From 4d5161135efb96dd6a63fc58567c495e73a17f7d Mon Sep 17 00:00:00 2001 From: Ben Wagner Date: Thu, 7 Jun 2018 13:11:37 -0400 Subject: 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 Commit-Queue: Ben Wagner --- samplecode/SampleAtlas.cpp | 19 +++++++++---------- samplecode/SampleBitmapRect.cpp | 22 ++++++++++++---------- 2 files changed, 21 insertions(+), 20 deletions(-) (limited to 'samplecode') 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 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(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); -- cgit v1.2.3