aboutsummaryrefslogtreecommitdiffhomepage
path: root/samplecode
diff options
context:
space:
mode:
authorGravatar Ben Wagner <bungeman@google.com>2018-06-07 13:11:37 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-06-07 20:37:06 +0000
commit4d5161135efb96dd6a63fc58567c495e73a17f7d (patch)
treeb4811fdbd3c9df8bcd9cd62d3352000260405139 /samplecode
parent0c78238e2991c95b6fb3c945d4ad2b5d941ae21b (diff)
Defer Sample setup to onOnceBeforeDraw.
The Atlas and BitmapRect samples do a great deal of work in their constructors. In particular this makes setting breakpoints deep in the glyph handling code more problematic that it needs to be, since these will call into the glyph code when they are created which can happen quite early. A great deal of this code does not need to run in the constructor in any event, the work only needs to be done once before the sample is drawn. As a result, defer this work into onOnceBeforeDraw. Change-Id: I212d3909170bf1cb56769a45e1714f24a496472f Reviewed-on: https://skia-review.googlesource.com/132927 Reviewed-by: Brian Osman <brianosman@google.com> Commit-Queue: Ben Wagner <bungeman@google.com>
Diffstat (limited to 'samplecode')
-rw-r--r--samplecode/SampleAtlas.cpp19
-rw-r--r--samplecode/SampleBitmapRect.cpp22
2 files changed, 21 insertions, 20 deletions
diff --git a/samplecode/SampleAtlas.cpp b/samplecode/SampleAtlas.cpp
index bb42fc182b..fac8327210 100644
--- a/samplecode/SampleAtlas.cpp
+++ b/samplecode/SampleAtlas.cpp
@@ -202,17 +202,12 @@ private:
};
class DrawAtlasView : public SampleView {
- const char* fName;
- DrawAtlasDrawable* fDrawable;
+ const char* fName;
+ DrawAtlasProc fProc;
+ sk_sp<DrawAtlasDrawable> fDrawable;
public:
- DrawAtlasView(const char name[], DrawAtlasProc proc) : fName(name) {
- fDrawable = new DrawAtlasDrawable(proc, SkRect::MakeWH(640, 480));
- }
-
- ~DrawAtlasView() override {
- fDrawable->unref();
- }
+ DrawAtlasView(const char name[], DrawAtlasProc proc) : fName(name), fProc(proc) { }
protected:
bool onQuery(SkEvent* evt) override {
@@ -230,8 +225,12 @@ protected:
return this->INHERITED::onQuery(evt);
}
+ void onOnceBeforeDraw() override {
+ fDrawable = sk_make_sp<DrawAtlasDrawable>(fProc, SkRect::MakeWH(640, 480));
+ }
+
void onDrawContent(SkCanvas* canvas) override {
- canvas->drawDrawable(fDrawable);
+ canvas->drawDrawable(fDrawable.get());
}
bool onAnimate(const SkAnimTimer&) override {
diff --git a/samplecode/SampleBitmapRect.cpp b/samplecode/SampleBitmapRect.cpp
index 90275b1cde..0e3ae5bf4e 100644
--- a/samplecode/SampleBitmapRect.cpp
+++ b/samplecode/SampleBitmapRect.cpp
@@ -195,7 +195,18 @@ class BitmapRectView2 : public SampleView {
}
public:
- BitmapRectView2() {
+ BitmapRectView2() { }
+
+protected:
+ bool onQuery(SkEvent* evt) override {
+ if (SampleCode::TitleQ(*evt)) {
+ SampleCode::TitleR(evt, "BigBitmapRect");
+ return true;
+ }
+ return this->INHERITED::onQuery(evt);
+ }
+
+ void onOnceBeforeDraw() override {
make_big_bitmap(&fBitmap);
this->setBGColor(SK_ColorGRAY);
@@ -209,15 +220,6 @@ public:
fDstR[1].offset(0, fDstR[0].height() * 5/4);
}
-protected:
- bool onQuery(SkEvent* evt) override {
- if (SampleCode::TitleQ(*evt)) {
- SampleCode::TitleR(evt, "BigBitmapRect");
- return true;
- }
- return this->INHERITED::onQuery(evt);
- }
-
void onDrawContent(SkCanvas* canvas) override {
SkPaint paint;
paint.setStyle(SkPaint::kStroke_Style);