Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkDrawable.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
8
12#include "include/core/SkPicture.h" // IWYU pragma: keep
14#include "include/core/SkRect.h"
17
18#include <atomic>
19#include <cstddef>
20#include <cstdint>
21
22static int32_t next_generation_id() {
23 static std::atomic<int32_t> nextID{1};
24
25 int32_t id;
26 do {
27 id = nextID.fetch_add(1, std::memory_order_relaxed);
28 } while (id == 0);
29 return id;
30}
31
32SkDrawable::SkDrawable() : fGenerationID(0) {}
33
34static void draw_bbox(SkCanvas* canvas, const SkRect& r) {
37 paint.setColor(0xFFFF7088);
38 canvas->drawRect(r, paint);
39 canvas->drawLine(r.left(), r.top(), r.right(), r.bottom(), paint);
40 canvas->drawLine(r.left(), r.bottom(), r.right(), r.top(), paint);
41}
42
43void SkDrawable::draw(SkCanvas* canvas, const SkMatrix* matrix) {
44 SkAutoCanvasRestore acr(canvas, true);
45 if (matrix) {
46 canvas->concat(*matrix);
47 }
48 this->onDraw(canvas);
49
50 if ((false)) {
51 draw_bbox(canvas, this->getBounds());
52 }
53}
54
57 this->draw(canvas, &matrix);
58}
59
63
65 if (0 == fGenerationID) {
66 fGenerationID = next_generation_id();
67 }
68 return fGenerationID;
69}
70
72 return this->onGetBounds();
73}
74
79 return 0;
80}
81
83 fGenerationID = 0;
84}
85
86/////////////////////////////////////////////////////////////////////////////////////////
87
89 SkPictureRecorder recorder;
90
91 const SkRect bounds = this->getBounds();
92 SkCanvas* canvas = recorder.beginRecording(bounds);
93 this->draw(canvas);
94 if ((false)) {
95 draw_bbox(canvas, bounds);
96 }
97 return recorder.finishRecordingAsPicture();
98}
static int32_t next_generation_id()
static void draw_bbox(SkCanvas *canvas, const SkRect &r)
void drawRect(const SkRect &rect, const SkPaint &paint)
void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const SkPaint &paint)
void concat(const SkMatrix &matrix)
void notifyDrawingChanged()
uint32_t getGenerationID()
size_t approximateBytesUsed()
virtual SkRect onGetBounds()=0
virtual sk_sp< SkPicture > onMakePictureSnapshot()
SkRect getBounds()
sk_sp< SkPicture > makePictureSnapshot()
virtual void onDraw(SkCanvas *)=0
virtual size_t onApproximateBytesUsed()
void draw(SkCanvas *, const SkMatrix *=nullptr)
static SkMatrix Translate(SkScalar dx, SkScalar dy)
Definition SkMatrix.h:91
@ kStroke_Style
set to stroke geometry
Definition SkPaint.h:194
SkCanvas * beginRecording(const SkRect &bounds, sk_sp< SkBBoxHierarchy > bbh)
sk_sp< SkPicture > finishRecordingAsPicture()
const Paint & paint
float SkScalar
Definition extension.cpp:12
double y
double x
constexpr float left() const
Definition SkRect.h:734
constexpr float top() const
Definition SkRect.h:741
constexpr float right() const
Definition SkRect.h:748
constexpr float bottom() const
Definition SkRect.h:755
const uintptr_t id