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

Side by Side Diff: samplecode/SamplePictFile.cpp

Issue 214953003: split SkPictureRecorder out of SkPicture (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: update to ToT (again) Created 6 years, 8 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 | Annotate | Revision Log
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"
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 kLast_BBoxType = kTileGrid_BBoxType 115 kLast_BBoxType = kTileGrid_BBoxType
116 }; 116 };
117 static const int kBBoxTypeCount = kLast_BBoxType + 1; 117 static const int kBBoxTypeCount = kLast_BBoxType + 1;
118 118
119 SkString fFilename; 119 SkString fFilename;
120 SkPicture* fPictures[kBBoxTypeCount]; 120 SkPicture* fPictures[kBBoxTypeCount];
121 BBoxType fBBox; 121 BBoxType fBBox;
122 SkSize fTileSize; 122 SkSize fTileSize;
123 123
124 SkPicture* LoadPicture(const char path[], BBoxType bbox) { 124 SkPicture* LoadPicture(const char path[], BBoxType bbox) {
125 SkPicture* pic = NULL; 125 SkAutoTUnref<SkPicture> pic;
126 126
127 SkBitmap bm; 127 SkBitmap bm;
128 if (SkImageDecoder::DecodeFile(path, &bm)) { 128 if (SkImageDecoder::DecodeFile(path, &bm)) {
129 bm.setImmutable(); 129 bm.setImmutable();
130 pic = SkNEW(SkPicture); 130 SkPictureRecorder recorder;
131 SkCanvas* can = pic->beginRecording(bm.width(), bm.height()); 131 SkCanvas* can = recorder.beginRecording(bm.width(), bm.height());
132 can->drawBitmap(bm, 0, 0, NULL); 132 can->drawBitmap(bm, 0, 0, NULL);
133 pic->endRecording(); 133 pic.reset(recorder.endRecording());
134 } else { 134 } else {
135 SkFILEStream stream(path); 135 SkFILEStream stream(path);
136 if (stream.isValid()) { 136 if (stream.isValid()) {
137 pic = SkPicture::CreateFromStream(&stream); 137 pic.reset(SkPicture::CreateFromStream(&stream));
138 } else { 138 } else {
139 SkDebugf("coun't load picture at \"path\"\n", path); 139 SkDebugf("coun't load picture at \"path\"\n", path);
140 } 140 }
141 141
142 if (false) { 142 if (false) {
143 SkSurface* surf = SkSurface::NewRasterPMColor(pic->width(), pic- >height()); 143 SkSurface* surf = SkSurface::NewRasterPMColor(pic->width(), pic- >height());
144 surf->getCanvas()->drawPicture(*pic); 144 surf->getCanvas()->drawPicture(*pic);
145 surf->unref(); 145 surf->unref();
146 } 146 }
147 if (false) { // re-record 147 if (false) { // re-record
148 SkPicture p2; 148 SkPictureRecorder recorder;
149 pic->draw(p2.beginRecording(pic->width(), pic->height())); 149 pic->draw(recorder.beginRecording(pic->width(), pic->height()));
150 p2.endRecording(); 150 SkAutoTUnref<SkPicture> p2(recorder.endRecording());
151 151
152 SkString path2(path); 152 SkString path2(path);
153 path2.append(".new.skp"); 153 path2.append(".new.skp");
154 SkFILEWStream writer(path2.c_str()); 154 SkFILEWStream writer(path2.c_str());
155 p2.serialize(&writer); 155 p2->serialize(&writer);
156 } 156 }
157 } 157 }
158 158
159 if (!pic) { 159 if (NULL == pic) {
160 return NULL; 160 return NULL;
161 } 161 }
162 162
163 SkPicture* bboxPicture = NULL; 163 SkAutoTUnref<SkPictureFactory> factory;
164 switch (bbox) { 164 switch (bbox) {
165 case kNo_BBoxType: 165 case kNo_BBoxType:
166 // no bbox playback necessary 166 // no bbox playback necessary
167 break; 167 return pic.detach();
168 case kRTree_BBoxType: 168 case kRTree_BBoxType:
169 bboxPicture = SkNEW(SkPicture);
170 break; 169 break;
171 case kQuadTree_BBoxType: 170 case kQuadTree_BBoxType:
172 bboxPicture = SkNEW_ARGS(SkQuadTreePicture, 171 factory.reset(SkNEW(SkQuadTreePictureFactory));
173 (SkIRect::MakeWH(pic->width(), pic->height())));
174 break; 172 break;
175 case kTileGrid_BBoxType: { 173 case kTileGrid_BBoxType: {
176 SkASSERT(!fTileSize.isEmpty()); 174 SkASSERT(!fTileSize.isEmpty());
177 SkTileGridPicture::TileGridInfo gridInfo; 175 SkTileGridPicture::TileGridInfo gridInfo;
178 gridInfo.fMargin = SkISize::Make(0, 0); 176 gridInfo.fMargin = SkISize::Make(0, 0);
179 gridInfo.fOffset = SkIPoint::Make(0, 0); 177 gridInfo.fOffset = SkIPoint::Make(0, 0);
180 gridInfo.fTileInterval = fTileSize.toRound(); 178 gridInfo.fTileInterval = fTileSize.toRound();
181 bboxPicture = SkNEW_ARGS(SkTileGridPicture, (pic->width(), pic->heig ht(), gridInfo)); 179 factory.reset(SkNEW_ARGS(SkTileGridPictureFactory, (gridInfo)));
182 } break; 180 break;
181 }
183 default: 182 default:
184 SkASSERT(false); 183 SkASSERT(false);
185 } 184 }
186 185
187 if (bboxPicture) { 186 SkPictureRecorder recorder(factory);
188 pic->draw(bboxPicture->beginRecording(pic->width(), pic->height(), 187 pic->draw(recorder.beginRecording(pic->width(), pic->height(),
189 SkPicture::kOptimizeForClippedPlayback_RecordingFlag)); 188 SkPicture::kOptimizeForClippedPlayback _RecordingFlag));
190 bboxPicture->endRecording(); 189 return recorder.endRecording();
191 SkDELETE(pic);
192 return bboxPicture;
193 }
194
195 return pic;
196 } 190 }
197 191
198 typedef SampleView INHERITED; 192 typedef SampleView INHERITED;
199 }; 193 };
200 194
201 SampleView* CreateSamplePictFileView(const char filename[]); 195 SampleView* CreateSamplePictFileView(const char filename[]);
202 SampleView* CreateSamplePictFileView(const char filename[]) { 196 SampleView* CreateSamplePictFileView(const char filename[]) {
203 return new PictFileView(filename); 197 return new PictFileView(filename);
204 } 198 }
205 199
206 ////////////////////////////////////////////////////////////////////////////// 200 //////////////////////////////////////////////////////////////////////////////
207 201
208 #if 0 202 #if 0
209 static SkView* MyFactory() { return new PictFileView; } 203 static SkView* MyFactory() { return new PictFileView; }
210 static SkViewRegister reg(MyFactory); 204 static SkViewRegister reg(MyFactory);
211 #endif 205 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698