Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(208)

Side by Side Diff: samplecode/SamplePictFile.cpp

Issue 131343011: Initial QuadTree implementation (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fixed SkScalar conversion issue Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gyp/tests.gyp ('k') | src/core/SkBBoxHierarchy.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SampleCode.h" 8 #include "SampleCode.h"
9 #include "SkDumpCanvas.h" 9 #include "SkDumpCanvas.h"
10 #include "SkView.h" 10 #include "SkView.h"
11 #include "SkCanvas.h" 11 #include "SkCanvas.h"
12 #include "SkGradientShader.h" 12 #include "SkGradientShader.h"
13 #include "SkGraphics.h" 13 #include "SkGraphics.h"
14 #include "SkImageDecoder.h" 14 #include "SkImageDecoder.h"
15 #include "SkOSFile.h" 15 #include "SkOSFile.h"
16 #include "SkPath.h" 16 #include "SkPath.h"
17 #include "SkPicture.h" 17 #include "SkPicture.h"
18 #include "SkQuadTreePicture.h"
18 #include "SkRandom.h" 19 #include "SkRandom.h"
19 #include "SkRegion.h" 20 #include "SkRegion.h"
20 #include "SkShader.h" 21 #include "SkShader.h"
21 #include "SkTileGridPicture.h" 22 #include "SkTileGridPicture.h"
22 #include "SkUtils.h" 23 #include "SkUtils.h"
23 #include "SkColorPriv.h" 24 #include "SkColorPriv.h"
24 #include "SkColorFilter.h" 25 #include "SkColorFilter.h"
25 #include "SkTime.h" 26 #include "SkTime.h"
26 #include "SkTypeface.h" 27 #include "SkTypeface.h"
27 #include "SkXfermode.h" 28 #include "SkXfermode.h"
(...skipping 26 matching lines...) Expand all
54 } 55 }
55 } 56 }
56 57
57 protected: 58 protected:
58 // overrides from SkEventSink 59 // overrides from SkEventSink
59 virtual bool onQuery(SkEvent* evt) SK_OVERRIDE { 60 virtual bool onQuery(SkEvent* evt) SK_OVERRIDE {
60 if (SampleCode::TitleQ(*evt)) { 61 if (SampleCode::TitleQ(*evt)) {
61 SkString name("P:"); 62 SkString name("P:");
62 const char* basename = strrchr(fFilename.c_str(), SkPATH_SEPARATOR); 63 const char* basename = strrchr(fFilename.c_str(), SkPATH_SEPARATOR);
63 name.append(basename ? basename+1: fFilename.c_str()); 64 name.append(basename ? basename+1: fFilename.c_str());
64 if (fBBox != kNo_BBoxType) { 65 switch (fBBox) {
65 name.append(fBBox == kRTree_BBoxType ? " <bbox: R>" : " <bbox: T >"); 66 case kNo_BBoxType:
67 // No name appended
68 break;
69 case kRTree_BBoxType:
70 name.append(" <bbox: R>");
71 break;
72 case kQuadTree_BBoxType:
73 name.append(" <bbox: Q>");
74 break;
75 case kTileGrid_BBoxType:
76 name.append(" <bbox: T>");
77 break;
78 default:
79 SkASSERT(false);
80 break;
66 } 81 }
67 SampleCode::TitleR(evt, name.c_str()); 82 SampleCode::TitleR(evt, name.c_str());
68 return true; 83 return true;
69 } 84 }
70 return this->INHERITED::onQuery(evt); 85 return this->INHERITED::onQuery(evt);
71 } 86 }
72 87
73 virtual bool onEvent(const SkEvent& evt) SK_OVERRIDE { 88 virtual bool onEvent(const SkEvent& evt) SK_OVERRIDE {
74 if (evt.isType("PictFileView::toggleBBox")) { 89 if (evt.isType("PictFileView::toggleBBox")) {
75 fBBox = (BBoxType)((fBBox + 1) % kBBoxTypeCount); 90 fBBox = (BBoxType)((fBBox + 1) % kBBoxTypeCount);
(...skipping 10 matching lines...) Expand all
86 *picture = LoadPicture(fFilename.c_str(), fBBox); 101 *picture = LoadPicture(fFilename.c_str(), fBBox);
87 } 102 }
88 if (*picture) { 103 if (*picture) {
89 canvas->drawPicture(**picture); 104 canvas->drawPicture(**picture);
90 } 105 }
91 } 106 }
92 107
93 private: 108 private:
94 enum BBoxType { 109 enum BBoxType {
95 kNo_BBoxType, 110 kNo_BBoxType,
111 kQuadTree_BBoxType,
96 kRTree_BBoxType, 112 kRTree_BBoxType,
97 kTileGrid_BBoxType, 113 kTileGrid_BBoxType,
98 114
99 kLast_BBoxType = kTileGrid_BBoxType 115 kLast_BBoxType = kTileGrid_BBoxType
100 }; 116 };
101 static const int kBBoxTypeCount = kLast_BBoxType + 1; 117 static const int kBBoxTypeCount = kLast_BBoxType + 1;
102 118
103 SkString fFilename; 119 SkString fFilename;
104 SkPicture* fPictures[kBBoxTypeCount]; 120 SkPicture* fPictures[kBBoxTypeCount];
105 BBoxType fBBox; 121 BBoxType fBBox;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 } 161 }
146 162
147 SkPicture* bboxPicture = NULL; 163 SkPicture* bboxPicture = NULL;
148 switch (bbox) { 164 switch (bbox) {
149 case kNo_BBoxType: 165 case kNo_BBoxType:
150 // no bbox playback necessary 166 // no bbox playback necessary
151 break; 167 break;
152 case kRTree_BBoxType: 168 case kRTree_BBoxType:
153 bboxPicture = SkNEW(SkPicture); 169 bboxPicture = SkNEW(SkPicture);
154 break; 170 break;
171 case kQuadTree_BBoxType:
172 bboxPicture = SkNEW_ARGS(SkQuadTreePicture,
173 (SkIRect::MakeWH(pic->width(), pic->height())));
174 break;
155 case kTileGrid_BBoxType: { 175 case kTileGrid_BBoxType: {
156 SkASSERT(!fTileSize.isEmpty()); 176 SkASSERT(!fTileSize.isEmpty());
157 SkTileGridPicture::TileGridInfo gridInfo; 177 SkTileGridPicture::TileGridInfo gridInfo;
158 gridInfo.fMargin = SkISize::Make(0, 0); 178 gridInfo.fMargin = SkISize::Make(0, 0);
159 gridInfo.fOffset = SkIPoint::Make(0, 0); 179 gridInfo.fOffset = SkIPoint::Make(0, 0);
160 gridInfo.fTileInterval = fTileSize.toRound(); 180 gridInfo.fTileInterval = fTileSize.toRound();
161 bboxPicture = SkNEW_ARGS(SkTileGridPicture, (pic->width(), pic->heig ht(), gridInfo)); 181 bboxPicture = SkNEW_ARGS(SkTileGridPicture, (pic->width(), pic->heig ht(), gridInfo));
162 } break; 182 } break;
163 default: 183 default:
164 SkASSERT(false); 184 SkASSERT(false);
(...skipping 17 matching lines...) Expand all
182 SampleView* CreateSamplePictFileView(const char filename[]) { 202 SampleView* CreateSamplePictFileView(const char filename[]) {
183 return new PictFileView(filename); 203 return new PictFileView(filename);
184 } 204 }
185 205
186 ////////////////////////////////////////////////////////////////////////////// 206 //////////////////////////////////////////////////////////////////////////////
187 207
188 #if 0 208 #if 0
189 static SkView* MyFactory() { return new PictFileView; } 209 static SkView* MyFactory() { return new PictFileView; }
190 static SkViewRegister reg(MyFactory); 210 static SkViewRegister reg(MyFactory);
191 #endif 211 #endif
OLDNEW
« no previous file with comments | « gyp/tests.gyp ('k') | src/core/SkBBoxHierarchy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698