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

Side by Side Diff: samplecode/SamplePictFile.cpp

Issue 238273012: Staged removal of SkPicture-derived classes (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: have SkPicture only friend SkPictureRecorder once 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
« no previous file with comments | « samplecode/SampleApp.cpp ('k') | samplecode/SamplePicture.cpp » ('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"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 BBoxType fBBox; 122 BBoxType fBBox;
123 SkSize fTileSize; 123 SkSize fTileSize;
124 124
125 SkPicture* LoadPicture(const char path[], BBoxType bbox) { 125 SkPicture* LoadPicture(const char path[], BBoxType bbox) {
126 SkAutoTUnref<SkPicture> pic; 126 SkAutoTUnref<SkPicture> pic;
127 127
128 SkBitmap bm; 128 SkBitmap bm;
129 if (SkImageDecoder::DecodeFile(path, &bm)) { 129 if (SkImageDecoder::DecodeFile(path, &bm)) {
130 bm.setImmutable(); 130 bm.setImmutable();
131 SkPictureRecorder recorder; 131 SkPictureRecorder recorder;
132 SkCanvas* can = recorder.beginRecording(bm.width(), bm.height()); 132 SkCanvas* can = recorder.beginRecording(bm.width(), bm.height(), NUL L, 0);
133 can->drawBitmap(bm, 0, 0, NULL); 133 can->drawBitmap(bm, 0, 0, NULL);
134 pic.reset(recorder.endRecording()); 134 pic.reset(recorder.endRecording());
135 } else { 135 } else {
136 SkFILEStream stream(path); 136 SkFILEStream stream(path);
137 if (stream.isValid()) { 137 if (stream.isValid()) {
138 pic.reset(SkPicture::CreateFromStream(&stream)); 138 pic.reset(SkPicture::CreateFromStream(&stream));
139 } else { 139 } else {
140 SkDebugf("coun't load picture at \"path\"\n", path); 140 SkDebugf("coun't load picture at \"path\"\n", path);
141 } 141 }
142 142
143 if (false) { 143 if (false) {
144 SkSurface* surf = SkSurface::NewRasterPMColor(pic->width(), pic- >height()); 144 SkSurface* surf = SkSurface::NewRasterPMColor(pic->width(), pic- >height());
145 surf->getCanvas()->drawPicture(*pic); 145 surf->getCanvas()->drawPicture(*pic);
146 surf->unref(); 146 surf->unref();
147 } 147 }
148 if (false) { // re-record 148 if (false) { // re-record
149 SkPictureRecorder recorder; 149 SkPictureRecorder recorder;
150 pic->draw(recorder.beginRecording(pic->width(), pic->height())); 150 pic->draw(recorder.beginRecording(pic->width(), pic->height(), N ULL, 0));
151 SkAutoTUnref<SkPicture> p2(recorder.endRecording()); 151 SkAutoTUnref<SkPicture> p2(recorder.endRecording());
152 152
153 SkString path2(path); 153 SkString path2(path);
154 path2.append(".new.skp"); 154 path2.append(".new.skp");
155 SkFILEWStream writer(path2.c_str()); 155 SkFILEWStream writer(path2.c_str());
156 p2->serialize(&writer); 156 p2->serialize(&writer);
157 } 157 }
158 } 158 }
159 159
160 if (NULL == pic) { 160 if (NULL == pic) {
161 return NULL; 161 return NULL;
162 } 162 }
163 163
164 SkAutoTUnref<SkPictureFactory> factory; 164 SkAutoTDelete<SkBBHFactory> factory;
165 switch (bbox) { 165 switch (bbox) {
166 case kNo_BBoxType: 166 case kNo_BBoxType:
167 // no bbox playback necessary 167 // no bbox playback necessary
168 return pic.detach(); 168 return pic.detach();
169 case kRTree_BBoxType: 169 case kRTree_BBoxType:
170 factory.reset(SkNEW(SkRTreePictureFactory)); 170 factory.reset(SkNEW(SkRTreeFactory));
171 break; 171 break;
172 case kQuadTree_BBoxType: 172 case kQuadTree_BBoxType:
173 factory.reset(SkNEW(SkQuadTreePictureFactory)); 173 factory.reset(SkNEW(SkQuadTreeFactory));
174 break; 174 break;
175 case kTileGrid_BBoxType: { 175 case kTileGrid_BBoxType: {
176 SkASSERT(!fTileSize.isEmpty()); 176 SkASSERT(!fTileSize.isEmpty());
177 SkTileGridPicture::TileGridInfo gridInfo; 177 SkTileGridFactory::TileGridInfo gridInfo;
178 gridInfo.fMargin = SkISize::Make(0, 0); 178 gridInfo.fMargin = SkISize::Make(0, 0);
179 gridInfo.fOffset = SkIPoint::Make(0, 0); 179 gridInfo.fOffset = SkIPoint::Make(0, 0);
180 gridInfo.fTileInterval = fTileSize.toRound(); 180 gridInfo.fTileInterval = fTileSize.toRound();
181 factory.reset(SkNEW_ARGS(SkTileGridPictureFactory, (gridInfo))); 181 factory.reset(SkNEW_ARGS(SkTileGridFactory, (gridInfo)));
182 break; 182 break;
183 } 183 }
184 default: 184 default:
185 SkASSERT(false); 185 SkASSERT(false);
186 } 186 }
187 187
188 SkPictureRecorder recorder(factory); 188 SkPictureRecorder recorder;
189 pic->draw(recorder.beginRecording(pic->width(), pic->height())); 189 pic->draw(recorder.beginRecording(pic->width(), pic->height(), factory.g et(), 0));
190 return recorder.endRecording(); 190 return recorder.endRecording();
191 } 191 }
192 192
193 typedef SampleView INHERITED; 193 typedef SampleView INHERITED;
194 }; 194 };
195 195
196 SampleView* CreateSamplePictFileView(const char filename[]); 196 SampleView* CreateSamplePictFileView(const char filename[]);
197 SampleView* CreateSamplePictFileView(const char filename[]) { 197 SampleView* CreateSamplePictFileView(const char filename[]) {
198 return new PictFileView(filename); 198 return new PictFileView(filename);
199 } 199 }
200 200
201 ////////////////////////////////////////////////////////////////////////////// 201 //////////////////////////////////////////////////////////////////////////////
202 202
203 #if 0 203 #if 0
204 static SkView* MyFactory() { return new PictFileView; } 204 static SkView* MyFactory() { return new PictFileView; }
205 static SkViewRegister reg(MyFactory); 205 static SkViewRegister reg(MyFactory);
206 #endif 206 #endif
OLDNEW
« no previous file with comments | « samplecode/SampleApp.cpp ('k') | samplecode/SamplePicture.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698