Chromium Code Reviews| Index: samplecode/SamplePictFile.cpp |
| diff --git a/samplecode/SamplePictFile.cpp b/samplecode/SamplePictFile.cpp |
| index b8298d4e19d2f34695adeab724a383147df01da7..f2919bd4c21f34b9534bdf34f08f7835f444b0f9 100644 |
| --- a/samplecode/SamplePictFile.cpp |
| +++ b/samplecode/SamplePictFile.cpp |
| @@ -19,6 +19,7 @@ |
| #include "SkRandom.h" |
| #include "SkRegion.h" |
| #include "SkShader.h" |
| +#include "SkTileGridPicture.h" |
| #include "SkUtils.h" |
| #include "SkColorPriv.h" |
| #include "SkColorFilter.h" |
| @@ -31,12 +32,81 @@ |
| #include "SkXMLParser.h" |
| class PictFileView : public SampleView { |
| +public: |
| + PictFileView(const char name[] = NULL) |
| + : fFilename(name) |
| + , fBBox(kNo_BBox) |
| + , fTileSize(SkSize::Make(0, 0)) { |
| + for (unsigned i = 0; i < kLast_BBox_enum; ++i) { |
| + fPictures[i] = NULL; |
| + } |
| + } |
| + |
| + virtual ~PictFileView() { |
| + for (unsigned i = 0; i < kLast_BBox_enum; ++i) { |
| + SkSafeUnref(fPictures[i]); |
| + } |
| + } |
| + |
|
robertphillips
2013/12/10 18:44:28
override?
fmalita_google_do_not_use
2013/12/10 19:48:17
Done.
|
| + virtual void onTileSizeChanged(const SkSize &tileSize) { |
| + if (tileSize != fTileSize) { |
| + fTileSize = tileSize; |
|
robertphillips
2013/12/10 18:44:28
SkSafeSetNull?
fmalita_google_do_not_use
2013/12/10 19:48:17
Done.
|
| + SkSafeUnref(fPictures[kTileGrid_BBox]); |
| + fPictures[kTileGrid_BBox] = NULL; |
| + } |
| + } |
| + |
| +protected: |
| + // overrides from SkEventSink |
|
robertphillips
2013/12/10 18:44:28
override keyword?
fmalita_google_do_not_use
2013/12/10 19:48:17
Done.
|
| + virtual bool onQuery(SkEvent* evt) { |
| + if (SampleCode::TitleQ(*evt)) { |
| + SkString name("P:"); |
| + const char* basename = strrchr(fFilename.c_str(), SkPATH_SEPARATOR); |
| + name.append(basename ? basename+1: fFilename.c_str()); |
| + if (fBBox != kNo_BBox) { |
| + name.append(fBBox == kRTree_BBox ? " <bbox: R>" : " <bbox: T>"); |
| + } |
| + SampleCode::TitleR(evt, name.c_str()); |
| + return true; |
| + } |
| + return this->INHERITED::onQuery(evt); |
| + } |
| + |
| + virtual bool onEvent(const SkEvent& evt) { |
| + if (evt.isType("PictFileView::toggleBBox")) { |
| + fBBox = (BBoxType)((fBBox + 1) % kLast_BBox_enum); |
| + return true; |
| + } |
| + return this->INHERITED::onEvent(evt); |
| + } |
| + |
| + virtual void onDrawContent(SkCanvas* canvas) { |
| + SkASSERT(fBBox < kLast_BBox_enum); |
| + SkPicture** picture = fPictures + fBBox; |
| + |
| + if (!*picture) { |
| + *picture = LoadPicture(fFilename.c_str(), fBBox); |
| + } |
| + if (*picture) { |
| + canvas->drawPicture(**picture); |
| + } |
| + } |
| + |
| +private: |
| + enum BBoxType { |
|
robertphillips
2013/12/10 18:44:28
kNo_BBoxType? same for others?
fmalita_google_do_not_use
2013/12/10 19:48:17
Done.
|
| + kNo_BBox, |
| + kRTree_BBox, |
| + kTileGrid_BBox, |
| + |
|
robertphillips
2013/12/10 18:44:28
kLast_BBoxType? (no _enum)?
Also shouldn't this be
fmalita_google_do_not_use
2013/12/10 19:48:17
Oh yeah, the style guide is quite specific about t
|
| + kLast_BBox_enum |
| + }; |
| + |
| SkString fFilename; |
| - SkPicture* fPicture; |
| - SkPicture* fBBoxPicture; |
| - bool fUseBBox; |
| + SkPicture* fPictures[kLast_BBox_enum]; |
| + BBoxType fBBox; |
| + SkSize fTileSize; |
| - static SkPicture* LoadPicture(const char path[], bool useBBox) { |
| + SkPicture* LoadPicture(const char path[], BBoxType bbox) { |
| SkPicture* pic = NULL; |
| SkBitmap bm; |
| @@ -71,8 +141,16 @@ class PictFileView : public SampleView { |
| } |
| } |
|
robertphillips
2013/12/10 18:44:28
put const on the left hand side (e.g., kNo_BBox !=
fmalita_google_do_not_use
2013/12/10 19:48:17
Done.
|
| - if (useBBox) { |
| - SkPicture* bboxPicture = SkNEW(SkPicture); |
| + if (bbox != kNo_BBox) { |
|
robertphillips
2013/12/10 18:44:28
Doesn't the next 5 lines only need to be done if w
fmalita_google_do_not_use
2013/12/10 19:48:17
That is correct, I was trading sloppiness for brev
|
| + SkASSERT(!fTileSize.isEmpty()); |
| + SkTileGridPicture::TileGridInfo gridInfo; |
| + gridInfo.fMargin = SkISize::Make(0, 0); |
| + gridInfo.fOffset = SkIPoint::Make(0, 0); |
| + gridInfo.fTileInterval = fTileSize.toRound(); |
| + |
| + SkPicture* bboxPicture = (bbox == kRTree_BBox) |
| + ? SkNEW(SkPicture) |
| + : SkNEW_ARGS(SkTileGridPicture, (pic->width(), pic->height(), gridInfo)); |
| pic->draw(bboxPicture->beginRecording(pic->width(), pic->height(), |
| SkPicture::kOptimizeForClippedPlayback_RecordingFlag)); |
| bboxPicture->endRecording(); |
| @@ -84,54 +162,6 @@ class PictFileView : public SampleView { |
| } |
| } |
| -public: |
| - PictFileView(const char name[] = NULL) : fFilename(name) { |
| - fPicture = NULL; |
| - fBBoxPicture = NULL; |
| - fUseBBox = false; |
| - } |
| - |
| - virtual ~PictFileView() { |
| - SkSafeUnref(fPicture); |
| - SkSafeUnref(fBBoxPicture); |
| - } |
| - |
| -protected: |
| - // overrides from SkEventSink |
| - virtual bool onQuery(SkEvent* evt) { |
| - if (SampleCode::TitleQ(*evt)) { |
| - SkString name("P:"); |
| - const char* basename = strrchr(fFilename.c_str(), SkPATH_SEPARATOR); |
| - name.append(basename ? basename+1: fFilename.c_str()); |
| - if (fUseBBox) { |
| - name.append(" <bbox>"); |
| - } |
| - SampleCode::TitleR(evt, name.c_str()); |
| - return true; |
| - } |
| - return this->INHERITED::onQuery(evt); |
| - } |
| - |
| - virtual bool onEvent(const SkEvent& evt) { |
| - if (evt.isType("PictFileView::toggleBBox")) { |
| - fUseBBox = !fUseBBox; |
| - return true; |
| - } |
| - return this->INHERITED::onEvent(evt); |
| - } |
| - |
| - virtual void onDrawContent(SkCanvas* canvas) { |
| - SkPicture** picture = fUseBBox ? &fBBoxPicture : &fPicture; |
| - |
| - if (!*picture) { |
| - *picture = LoadPicture(fFilename.c_str(), fUseBBox); |
| - } |
| - if (*picture) { |
| - canvas->drawPicture(**picture); |
| - } |
| - } |
| - |
| -private: |
| typedef SampleView INHERITED; |
| }; |