OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "PictureRenderer.h" | 8 #include "PictureRenderer.h" |
9 #include "picture_utils.h" | 9 #include "picture_utils.h" |
10 #include "SamplePipeControllers.h" | 10 #include "SamplePipeControllers.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 const SkString* mismatchPath, | 58 const SkString* mismatchPath, |
59 const SkString* inputFilename, | 59 const SkString* inputFilename, |
60 bool useChecksumBasedFilenames, | 60 bool useChecksumBasedFilenames, |
61 bool useMultiPictureDraw) { | 61 bool useMultiPictureDraw) { |
62 this->CopyString(&fWritePath, writePath); | 62 this->CopyString(&fWritePath, writePath); |
63 this->CopyString(&fMismatchPath, mismatchPath); | 63 this->CopyString(&fMismatchPath, mismatchPath); |
64 this->CopyString(&fInputFilename, inputFilename); | 64 this->CopyString(&fInputFilename, inputFilename); |
65 fUseChecksumBasedFilenames = useChecksumBasedFilenames; | 65 fUseChecksumBasedFilenames = useChecksumBasedFilenames; |
66 fUseMultiPictureDraw = useMultiPictureDraw; | 66 fUseMultiPictureDraw = useMultiPictureDraw; |
67 | 67 |
68 SkASSERT(NULL == fPicture); | 68 SkASSERT(nullptr == fPicture); |
69 SkASSERT(NULL == fCanvas.get()); | 69 SkASSERT(nullptr == fCanvas.get()); |
70 if (fPicture || fCanvas.get()) { | 70 if (fPicture || fCanvas.get()) { |
71 return; | 71 return; |
72 } | 72 } |
73 | 73 |
74 SkASSERT(pict != NULL); | 74 SkASSERT(pict != nullptr); |
75 if (NULL == pict) { | 75 if (nullptr == pict) { |
76 return; | 76 return; |
77 } | 77 } |
78 | 78 |
79 fPicture.reset(pict)->ref(); | 79 fPicture.reset(pict)->ref(); |
80 fCanvas.reset(this->setupCanvas()); | 80 fCanvas.reset(this->setupCanvas()); |
81 } | 81 } |
82 | 82 |
83 void PictureRenderer::CopyString(SkString* dest, const SkString* src) { | 83 void PictureRenderer::CopyString(SkString* dest, const SkString* src) { |
84 if (src) { | 84 if (src) { |
85 dest->set(*src); | 85 dest->set(*src); |
86 } else { | 86 } else { |
87 dest->reset(); | 87 dest->reset(); |
88 } | 88 } |
89 } | 89 } |
90 | 90 |
91 class FlagsFilterCanvas : public SkPaintFilterCanvas { | 91 class FlagsFilterCanvas : public SkPaintFilterCanvas { |
92 public: | 92 public: |
93 FlagsFilterCanvas(SkCanvas* canvas, PictureRenderer::DrawFilterFlags* flags) | 93 FlagsFilterCanvas(SkCanvas* canvas, PictureRenderer::DrawFilterFlags* flags) |
94 : INHERITED(canvas->imageInfo().width(), canvas->imageInfo().height()) | 94 : INHERITED(canvas->imageInfo().width(), canvas->imageInfo().height()) |
95 , fFlags(flags) { | 95 , fFlags(flags) { |
96 this->addCanvas(canvas); | 96 this->addCanvas(canvas); |
97 } | 97 } |
98 | 98 |
99 protected: | 99 protected: |
100 void onFilterPaint(SkPaint* paint, Type t) const override { | 100 void onFilterPaint(SkPaint* paint, Type t) const override { |
101 paint->setFlags(paint->getFlags() & ~fFlags[t] & SkPaint::kAllFlags); | 101 paint->setFlags(paint->getFlags() & ~fFlags[t] & SkPaint::kAllFlags); |
102 if (PictureRenderer::kMaskFilter_DrawFilterFlag & fFlags[t]) { | 102 if (PictureRenderer::kMaskFilter_DrawFilterFlag & fFlags[t]) { |
103 SkMaskFilter* maskFilter = paint->getMaskFilter(); | 103 SkMaskFilter* maskFilter = paint->getMaskFilter(); |
104 if (maskFilter) { | 104 if (maskFilter) { |
105 paint->setMaskFilter(NULL); | 105 paint->setMaskFilter(nullptr); |
106 } | 106 } |
107 } | 107 } |
108 if (PictureRenderer::kHinting_DrawFilterFlag & fFlags[t]) { | 108 if (PictureRenderer::kHinting_DrawFilterFlag & fFlags[t]) { |
109 paint->setHinting(SkPaint::kNo_Hinting); | 109 paint->setHinting(SkPaint::kNo_Hinting); |
110 } else if (PictureRenderer::kSlightHinting_DrawFilterFlag & fFlags[t]) { | 110 } else if (PictureRenderer::kSlightHinting_DrawFilterFlag & fFlags[t]) { |
111 paint->setHinting(SkPaint::kSlight_Hinting); | 111 paint->setHinting(SkPaint::kSlight_Hinting); |
112 } | 112 } |
113 } | 113 } |
114 | 114 |
115 private: | 115 private: |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 case kNVPR_DeviceType: { | 147 case kNVPR_DeviceType: { |
148 SkAutoTUnref<GrSurface> target; | 148 SkAutoTUnref<GrSurface> target; |
149 if (fGrContext) { | 149 if (fGrContext) { |
150 // create a render target to back the device | 150 // create a render target to back the device |
151 GrSurfaceDesc desc; | 151 GrSurfaceDesc desc; |
152 desc.fConfig = kSkia8888_GrPixelConfig; | 152 desc.fConfig = kSkia8888_GrPixelConfig; |
153 desc.fFlags = kRenderTarget_GrSurfaceFlag; | 153 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
154 desc.fWidth = width; | 154 desc.fWidth = width; |
155 desc.fHeight = height; | 155 desc.fHeight = height; |
156 desc.fSampleCnt = fSampleCount; | 156 desc.fSampleCnt = fSampleCount; |
157 target.reset(fGrContext->textureProvider()->createTexture(desc,
false, NULL, 0)); | 157 target.reset(fGrContext->textureProvider()->createTexture(desc,
false, nullptr, 0)); |
158 } | 158 } |
159 | 159 |
160 uint32_t flags = fUseDFText ? SkSurfaceProps::kUseDistanceFieldFonts
_Flag : 0; | 160 uint32_t flags = fUseDFText ? SkSurfaceProps::kUseDistanceFieldFonts
_Flag : 0; |
161 SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType
); | 161 SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType
); |
162 SkAutoTUnref<SkGpuDevice> device( | 162 SkAutoTUnref<SkGpuDevice> device( |
163 SkGpuDevice::Create(target->asRenderTarget(), &props, | 163 SkGpuDevice::Create(target->asRenderTarget(), &props, |
164 SkGpuDevice::kUninit_InitContents)); | 164 SkGpuDevice::kUninit_InitContents)); |
165 if (!device) { | 165 if (!device) { |
166 return NULL; | 166 return nullptr; |
167 } | 167 } |
168 canvas.reset(new SkCanvas(device)); | 168 canvas.reset(new SkCanvas(device)); |
169 break; | 169 break; |
170 } | 170 } |
171 #endif | 171 #endif |
172 default: | 172 default: |
173 SkASSERT(0); | 173 SkASSERT(0); |
174 return NULL; | 174 return nullptr; |
175 } | 175 } |
176 | 176 |
177 if (fHasDrawFilters) { | 177 if (fHasDrawFilters) { |
178 if (fDrawFilters[0] & PictureRenderer::kAAClip_DrawFilterFlag) { | 178 if (fDrawFilters[0] & PictureRenderer::kAAClip_DrawFilterFlag) { |
179 canvas->setAllowSoftClip(false); | 179 canvas->setAllowSoftClip(false); |
180 } | 180 } |
181 | 181 |
182 canvas.reset(new FlagsFilterCanvas(canvas.get(), fDrawFilters)); | 182 canvas.reset(new FlagsFilterCanvas(canvas.get(), fDrawFilters)); |
183 } | 183 } |
184 | 184 |
185 this->scaleToScaleFactor(canvas); | 185 this->scaleToScaleFactor(canvas); |
186 | 186 |
187 // Pictures often lie about their extent (i.e., claim to be 100x100 but | 187 // Pictures often lie about their extent (i.e., claim to be 100x100 but |
188 // only ever draw to 90x100). Clear here so the undrawn portion will have | 188 // only ever draw to 90x100). Clear here so the undrawn portion will have |
189 // a consistent color | 189 // a consistent color |
190 canvas->clear(SK_ColorTRANSPARENT); | 190 canvas->clear(SK_ColorTRANSPARENT); |
191 return canvas.detach(); | 191 return canvas.detach(); |
192 } | 192 } |
193 | 193 |
194 void PictureRenderer::scaleToScaleFactor(SkCanvas* canvas) { | 194 void PictureRenderer::scaleToScaleFactor(SkCanvas* canvas) { |
195 SkASSERT(canvas != NULL); | 195 SkASSERT(canvas != nullptr); |
196 if (fScaleFactor != SK_Scalar1) { | 196 if (fScaleFactor != SK_Scalar1) { |
197 canvas->scale(fScaleFactor, fScaleFactor); | 197 canvas->scale(fScaleFactor, fScaleFactor); |
198 } | 198 } |
199 } | 199 } |
200 | 200 |
201 void PictureRenderer::end() { | 201 void PictureRenderer::end() { |
202 this->resetState(true); | 202 this->resetState(true); |
203 fPicture.reset(NULL); | 203 fPicture.reset(nullptr); |
204 fCanvas.reset(NULL); | 204 fCanvas.reset(nullptr); |
205 } | 205 } |
206 | 206 |
207 int PictureRenderer::getViewWidth() { | 207 int PictureRenderer::getViewWidth() { |
208 SkASSERT(fPicture != NULL); | 208 SkASSERT(fPicture != nullptr); |
209 int width = SkScalarCeilToInt(fPicture->cullRect().width() * fScaleFactor); | 209 int width = SkScalarCeilToInt(fPicture->cullRect().width() * fScaleFactor); |
210 if (fViewport.width() > 0) { | 210 if (fViewport.width() > 0) { |
211 width = SkMin32(width, fViewport.width()); | 211 width = SkMin32(width, fViewport.width()); |
212 } | 212 } |
213 return width; | 213 return width; |
214 } | 214 } |
215 | 215 |
216 int PictureRenderer::getViewHeight() { | 216 int PictureRenderer::getViewHeight() { |
217 SkASSERT(fPicture != NULL); | 217 SkASSERT(fPicture != nullptr); |
218 int height = SkScalarCeilToInt(fPicture->cullRect().height() * fScaleFactor)
; | 218 int height = SkScalarCeilToInt(fPicture->cullRect().height() * fScaleFactor)
; |
219 if (fViewport.height() > 0) { | 219 if (fViewport.height() > 0) { |
220 height = SkMin32(height, fViewport.height()); | 220 height = SkMin32(height, fViewport.height()); |
221 } | 221 } |
222 return height; | 222 return height; |
223 } | 223 } |
224 | 224 |
225 /** Converts fPicture to a picture that uses a BBoxHierarchy. | 225 /** Converts fPicture to a picture that uses a BBoxHierarchy. |
226 * PictureRenderer subclasses that are used to test picture playback | 226 * PictureRenderer subclasses that are used to test picture playback |
227 * should call this method during init. | 227 * should call this method during init. |
(...skipping 12 matching lines...) Expand all Loading... |
240 factory.get(), | 240 factory.get(), |
241 flags); | 241 flags); |
242 fPicture->playback(canvas); | 242 fPicture->playback(canvas); |
243 fPicture.reset(recorder.endRecording()); | 243 fPicture.reset(recorder.endRecording()); |
244 } | 244 } |
245 } | 245 } |
246 | 246 |
247 void PictureRenderer::resetState(bool callFinish) { | 247 void PictureRenderer::resetState(bool callFinish) { |
248 #if SK_SUPPORT_GPU | 248 #if SK_SUPPORT_GPU |
249 SkGLContext* glContext = this->getGLContext(); | 249 SkGLContext* glContext = this->getGLContext(); |
250 if (NULL == glContext) { | 250 if (nullptr == glContext) { |
251 SkASSERT(kBitmap_DeviceType == fDeviceType); | 251 SkASSERT(kBitmap_DeviceType == fDeviceType); |
252 return; | 252 return; |
253 } | 253 } |
254 | 254 |
255 fGrContext->flush(); | 255 fGrContext->flush(); |
256 glContext->swapBuffers(); | 256 glContext->swapBuffers(); |
257 if (callFinish) { | 257 if (callFinish) { |
258 SK_GL(*glContext, Finish()); | 258 SK_GL(*glContext, Finish()); |
259 } | 259 } |
260 #endif | 260 #endif |
261 } | 261 } |
262 | 262 |
263 void PictureRenderer::purgeTextures() { | 263 void PictureRenderer::purgeTextures() { |
264 SkDiscardableMemoryPool* pool = SkGetGlobalDiscardableMemoryPool(); | 264 SkDiscardableMemoryPool* pool = SkGetGlobalDiscardableMemoryPool(); |
265 | 265 |
266 pool->dumpPool(); | 266 pool->dumpPool(); |
267 | 267 |
268 #if SK_SUPPORT_GPU | 268 #if SK_SUPPORT_GPU |
269 SkGLContext* glContext = this->getGLContext(); | 269 SkGLContext* glContext = this->getGLContext(); |
270 if (NULL == glContext) { | 270 if (nullptr == glContext) { |
271 SkASSERT(kBitmap_DeviceType == fDeviceType); | 271 SkASSERT(kBitmap_DeviceType == fDeviceType); |
272 return; | 272 return; |
273 } | 273 } |
274 | 274 |
275 // resetState should've already done this | 275 // resetState should've already done this |
276 fGrContext->flush(); | 276 fGrContext->flush(); |
277 | 277 |
278 fGrContext->purgeAllUnlockedResources(); | 278 fGrContext->purgeAllUnlockedResources(); |
279 #endif | 279 #endif |
280 } | 280 } |
281 | 281 |
282 /** | 282 /** |
283 * Write the canvas to an image file and/or JSON summary. | 283 * Write the canvas to an image file and/or JSON summary. |
284 * | 284 * |
285 * @param canvas Must be non-null. Canvas to be written to a file. | 285 * @param canvas Must be non-null. Canvas to be written to a file. |
286 * @param writePath If nonempty, write the binary image to a file within this di
rectory. | 286 * @param writePath If nonempty, write the binary image to a file within this di
rectory. |
287 * @param mismatchPath If nonempty, write the binary image to a file within this
directory, | 287 * @param mismatchPath If nonempty, write the binary image to a file within this
directory, |
288 * but only if the image does not match expectations. | 288 * but only if the image does not match expectations. |
289 * @param inputFilename If we are writing out a binary image, use this to build
its filename. | 289 * @param inputFilename If we are writing out a binary image, use this to build
its filename. |
290 * @param jsonSummaryPtr If not null, add image results (checksum) to this summa
ry. | 290 * @param jsonSummaryPtr If not null, add image results (checksum) to this summa
ry. |
291 * @param useChecksumBasedFilenames If true, use checksum-based filenames when w
riting to disk. | 291 * @param useChecksumBasedFilenames If true, use checksum-based filenames when w
riting to disk. |
292 * @param tileNumberPtr If not null, which tile number this image contains. | 292 * @param tileNumberPtr If not null, which tile number this image contains. |
293 * | 293 * |
294 * @return bool True if the operation completed successfully. | 294 * @return bool True if the operation completed successfully. |
295 */ | 295 */ |
296 static bool write(SkCanvas* canvas, const SkString& writePath, const SkString& m
ismatchPath, | 296 static bool write(SkCanvas* canvas, const SkString& writePath, const SkString& m
ismatchPath, |
297 const SkString& inputFilename, ImageResultsAndExpectations *js
onSummaryPtr, | 297 const SkString& inputFilename, ImageResultsAndExpectations *js
onSummaryPtr, |
298 bool useChecksumBasedFilenames, const int* tileNumberPtr=NULL)
{ | 298 bool useChecksumBasedFilenames, const int* tileNumberPtr=nullp
tr) { |
299 SkASSERT(canvas != NULL); | 299 SkASSERT(canvas != nullptr); |
300 if (NULL == canvas) { | 300 if (nullptr == canvas) { |
301 return false; | 301 return false; |
302 } | 302 } |
303 | 303 |
304 SkBitmap bitmap; | 304 SkBitmap bitmap; |
305 SkISize size = canvas->getDeviceSize(); | 305 SkISize size = canvas->getDeviceSize(); |
306 setup_bitmap(&bitmap, size.width(), size.height()); | 306 setup_bitmap(&bitmap, size.width(), size.height()); |
307 | 307 |
308 canvas->readPixels(&bitmap, 0, 0); | 308 canvas->readPixels(&bitmap, 0, 0); |
309 force_all_opaque(bitmap); | 309 force_all_opaque(bitmap); |
310 BitmapAndDigest bitmapAndDigest(bitmap); | 310 BitmapAndDigest bitmapAndDigest(bitmap); |
311 | 311 |
312 SkString escapedInputFilename(inputFilename); | 312 SkString escapedInputFilename(inputFilename); |
313 replace_char(&escapedInputFilename, '.', '_'); | 313 replace_char(&escapedInputFilename, '.', '_'); |
314 | 314 |
315 // TODO(epoger): what about including the config type within outputFilename?
That way, | 315 // TODO(epoger): what about including the config type within outputFilename?
That way, |
316 // we could combine results of different config types without conflicting fi
lenames. | 316 // we could combine results of different config types without conflicting fi
lenames. |
317 SkString outputFilename; | 317 SkString outputFilename; |
318 const char *outputSubdirPtr = NULL; | 318 const char *outputSubdirPtr = nullptr; |
319 if (useChecksumBasedFilenames) { | 319 if (useChecksumBasedFilenames) { |
320 ImageDigest *imageDigestPtr = bitmapAndDigest.getImageDigestPtr(); | 320 ImageDigest *imageDigestPtr = bitmapAndDigest.getImageDigestPtr(); |
321 outputSubdirPtr = escapedInputFilename.c_str(); | 321 outputSubdirPtr = escapedInputFilename.c_str(); |
322 outputFilename.set(imageDigestPtr->getHashType()); | 322 outputFilename.set(imageDigestPtr->getHashType()); |
323 outputFilename.append("_"); | 323 outputFilename.append("_"); |
324 outputFilename.appendU64(imageDigestPtr->getHashValue()); | 324 outputFilename.appendU64(imageDigestPtr->getHashValue()); |
325 } else { | 325 } else { |
326 outputFilename.set(escapedInputFilename); | 326 outputFilename.set(escapedInputFilename); |
327 if (tileNumberPtr) { | 327 if (tileNumberPtr) { |
328 outputFilename.append("-tile"); | 328 outputFilename.append("-tile"); |
(...skipping 28 matching lines...) Expand all Loading... |
357 return true; | 357 return true; |
358 } else { | 358 } else { |
359 return write_bitmap_to_disk(bitmap, writePath, outputSubdirPtr, outputFi
lename); | 359 return write_bitmap_to_disk(bitmap, writePath, outputSubdirPtr, outputFi
lename); |
360 } | 360 } |
361 } | 361 } |
362 | 362 |
363 ////////////////////////////////////////////////////////////////////////////////
/////////////// | 363 ////////////////////////////////////////////////////////////////////////////////
/////////////// |
364 | 364 |
365 SkCanvas* RecordPictureRenderer::setupCanvas(int width, int height) { | 365 SkCanvas* RecordPictureRenderer::setupCanvas(int width, int height) { |
366 // defer the canvas setup until the render step | 366 // defer the canvas setup until the render step |
367 return NULL; | 367 return nullptr; |
368 } | 368 } |
369 | 369 |
370 bool RecordPictureRenderer::render(SkBitmap** out) { | 370 bool RecordPictureRenderer::render(SkBitmap** out) { |
371 SkAutoTDelete<SkBBHFactory> factory(this->getFactory()); | 371 SkAutoTDelete<SkBBHFactory> factory(this->getFactory()); |
372 SkPictureRecorder recorder; | 372 SkPictureRecorder recorder; |
373 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(this->getViewWidth(
)), | 373 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(this->getViewWidth(
)), |
374 SkIntToScalar(this->getViewHeight
()), | 374 SkIntToScalar(this->getViewHeight
()), |
375 factory.get(), | 375 factory.get(), |
376 this->recordFlags()); | 376 this->recordFlags()); |
377 this->scaleToScaleFactor(canvas); | 377 this->scaleToScaleFactor(canvas); |
(...skipping 10 matching lines...) Expand all Loading... |
388 return false; | 388 return false; |
389 } | 389 } |
390 | 390 |
391 SkString RecordPictureRenderer::getConfigNameInternal() { | 391 SkString RecordPictureRenderer::getConfigNameInternal() { |
392 return SkString("record"); | 392 return SkString("record"); |
393 } | 393 } |
394 | 394 |
395 ////////////////////////////////////////////////////////////////////////////////
/////////////// | 395 ////////////////////////////////////////////////////////////////////////////////
/////////////// |
396 | 396 |
397 bool PipePictureRenderer::render(SkBitmap** out) { | 397 bool PipePictureRenderer::render(SkBitmap** out) { |
398 SkASSERT(fCanvas.get() != NULL); | 398 SkASSERT(fCanvas.get() != nullptr); |
399 SkASSERT(fPicture != NULL); | 399 SkASSERT(fPicture != nullptr); |
400 if (NULL == fCanvas.get() || NULL == fPicture) { | 400 if (nullptr == fCanvas.get() || nullptr == fPicture) { |
401 return false; | 401 return false; |
402 } | 402 } |
403 | 403 |
404 PipeController pipeController(fCanvas.get()); | 404 PipeController pipeController(fCanvas.get()); |
405 SkGPipeWriter writer; | 405 SkGPipeWriter writer; |
406 SkCanvas* pipeCanvas = writer.startRecording(&pipeController); | 406 SkCanvas* pipeCanvas = writer.startRecording(&pipeController); |
407 pipeCanvas->drawPicture(fPicture); | 407 pipeCanvas->drawPicture(fPicture); |
408 writer.endRecording(); | 408 writer.endRecording(); |
409 fCanvas->flush(); | 409 fCanvas->flush(); |
410 if (out) { | 410 if (out) { |
(...skipping 18 matching lines...) Expand all Loading... |
429 | 429 |
430 void SimplePictureRenderer::init(const SkPicture* picture, const SkString* write
Path, | 430 void SimplePictureRenderer::init(const SkPicture* picture, const SkString* write
Path, |
431 const SkString* mismatchPath, const SkString* i
nputFilename, | 431 const SkString* mismatchPath, const SkString* i
nputFilename, |
432 bool useChecksumBasedFilenames, bool useMultiPi
ctureDraw) { | 432 bool useChecksumBasedFilenames, bool useMultiPi
ctureDraw) { |
433 INHERITED::init(picture, writePath, mismatchPath, inputFilename, | 433 INHERITED::init(picture, writePath, mismatchPath, inputFilename, |
434 useChecksumBasedFilenames, useMultiPictureDraw); | 434 useChecksumBasedFilenames, useMultiPictureDraw); |
435 this->buildBBoxHierarchy(); | 435 this->buildBBoxHierarchy(); |
436 } | 436 } |
437 | 437 |
438 bool SimplePictureRenderer::render(SkBitmap** out) { | 438 bool SimplePictureRenderer::render(SkBitmap** out) { |
439 SkASSERT(fCanvas.get() != NULL); | 439 SkASSERT(fCanvas.get() != nullptr); |
440 SkASSERT(fPicture); | 440 SkASSERT(fPicture); |
441 if (NULL == fCanvas.get() || NULL == fPicture) { | 441 if (nullptr == fCanvas.get() || nullptr == fPicture) { |
442 return false; | 442 return false; |
443 } | 443 } |
444 | 444 |
445 if (fUseMultiPictureDraw) { | 445 if (fUseMultiPictureDraw) { |
446 SkMultiPictureDraw mpd; | 446 SkMultiPictureDraw mpd; |
447 | 447 |
448 mpd.add(fCanvas, fPicture); | 448 mpd.add(fCanvas, fPicture); |
449 | 449 |
450 mpd.draw(); | 450 mpd.draw(); |
451 } else { | 451 } else { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 , fTileMinPowerOf2Width(0) | 486 , fTileMinPowerOf2Width(0) |
487 , fCurrentTileOffset(-1) | 487 , fCurrentTileOffset(-1) |
488 , fTilesX(0) | 488 , fTilesX(0) |
489 , fTilesY(0) { } | 489 , fTilesY(0) { } |
490 | 490 |
491 void TiledPictureRenderer::init(const SkPicture* pict, const SkString* writePath
, | 491 void TiledPictureRenderer::init(const SkPicture* pict, const SkString* writePath
, |
492 const SkString* mismatchPath, const SkString* in
putFilename, | 492 const SkString* mismatchPath, const SkString* in
putFilename, |
493 bool useChecksumBasedFilenames, bool useMultiPic
tureDraw) { | 493 bool useChecksumBasedFilenames, bool useMultiPic
tureDraw) { |
494 SkASSERT(pict); | 494 SkASSERT(pict); |
495 SkASSERT(0 == fTileRects.count()); | 495 SkASSERT(0 == fTileRects.count()); |
496 if (NULL == pict || fTileRects.count() != 0) { | 496 if (nullptr == pict || fTileRects.count() != 0) { |
497 return; | 497 return; |
498 } | 498 } |
499 | 499 |
500 // Do not call INHERITED::init(), which would create a (potentially large) c
anvas which is not | 500 // Do not call INHERITED::init(), which would create a (potentially large) c
anvas which is not |
501 // used by bench_pictures. | 501 // used by bench_pictures. |
502 fPicture.reset(pict)->ref(); | 502 fPicture.reset(pict)->ref(); |
503 this->CopyString(&fWritePath, writePath); | 503 this->CopyString(&fWritePath, writePath); |
504 this->CopyString(&fMismatchPath, mismatchPath); | 504 this->CopyString(&fMismatchPath, mismatchPath); |
505 this->CopyString(&fInputFilename, inputFilename); | 505 this->CopyString(&fInputFilename, inputFilename); |
506 fUseChecksumBasedFilenames = useChecksumBasedFilenames; | 506 fUseChecksumBasedFilenames = useChecksumBasedFilenames; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 // Only count tiles in the X direction on the first pass. | 543 // Only count tiles in the X direction on the first pass. |
544 fTilesX++; | 544 fTilesX++; |
545 } | 545 } |
546 *fTileRects.append() = SkIRect::MakeXYWH(tile_x_start, tile_y_start, | 546 *fTileRects.append() = SkIRect::MakeXYWH(tile_x_start, tile_y_start, |
547 fTileWidth, fTileHeight); | 547 fTileWidth, fTileHeight); |
548 } | 548 } |
549 } | 549 } |
550 } | 550 } |
551 | 551 |
552 bool TiledPictureRenderer::tileDimensions(int &x, int &y) { | 552 bool TiledPictureRenderer::tileDimensions(int &x, int &y) { |
553 if (fTileRects.count() == 0 || NULL == fPicture) { | 553 if (fTileRects.count() == 0 || nullptr == fPicture) { |
554 return false; | 554 return false; |
555 } | 555 } |
556 x = fTilesX; | 556 x = fTilesX; |
557 y = fTilesY; | 557 y = fTilesY; |
558 return true; | 558 return true; |
559 } | 559 } |
560 | 560 |
561 // The goal of the powers of two tiles is to minimize the amount of wasted tile | 561 // The goal of the powers of two tiles is to minimize the amount of wasted tile |
562 // space in the width-wise direction and then minimize the number of tiles. The | 562 // space in the width-wise direction and then minimize the number of tiles. The |
563 // constraints are that every tile must have a pixel width that is a power of | 563 // constraints are that every tile must have a pixel width that is a power of |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
680 bitmapCopyAtOffset(*tempBM, *out, tileRect.left(), tileRect.top()); | 680 bitmapCopyAtOffset(*tempBM, *out, tileRect.left(), tileRect.top()); |
681 } else { | 681 } else { |
682 success = false; | 682 success = false; |
683 } | 683 } |
684 } | 684 } |
685 | 685 |
686 return success; | 686 return success; |
687 } | 687 } |
688 | 688 |
689 bool TiledPictureRenderer::render(SkBitmap** out) { | 689 bool TiledPictureRenderer::render(SkBitmap** out) { |
690 SkASSERT(fPicture != NULL); | 690 SkASSERT(fPicture != nullptr); |
691 if (NULL == fPicture) { | 691 if (nullptr == fPicture) { |
692 return false; | 692 return false; |
693 } | 693 } |
694 | 694 |
695 SkBitmap bitmap; | 695 SkBitmap bitmap; |
696 if (out) { | 696 if (out) { |
697 *out = new SkBitmap; | 697 *out = new SkBitmap; |
698 setup_bitmap(*out, SkScalarCeilToInt(fPicture->cullRect().width()), | 698 setup_bitmap(*out, SkScalarCeilToInt(fPicture->cullRect().width()), |
699 SkScalarCeilToInt(fPicture->cullRect().height())); | 699 SkScalarCeilToInt(fPicture->cullRect().height())); |
700 setup_bitmap(&bitmap, fTileWidth, fTileHeight); | 700 setup_bitmap(&bitmap, fTileWidth, fTileHeight); |
701 } | 701 } |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
812 SkString PlaybackCreationRenderer::getConfigNameInternal() { | 812 SkString PlaybackCreationRenderer::getConfigNameInternal() { |
813 return SkString("playback_creation"); | 813 return SkString("playback_creation"); |
814 } | 814 } |
815 | 815 |
816 ////////////////////////////////////////////////////////////////////////////////
/////////////// | 816 ////////////////////////////////////////////////////////////////////////////////
/////////////// |
817 // SkPicture variants for each BBoxHierarchy type | 817 // SkPicture variants for each BBoxHierarchy type |
818 | 818 |
819 SkBBHFactory* PictureRenderer::getFactory() { | 819 SkBBHFactory* PictureRenderer::getFactory() { |
820 switch (fBBoxHierarchyType) { | 820 switch (fBBoxHierarchyType) { |
821 case kNone_BBoxHierarchyType: | 821 case kNone_BBoxHierarchyType: |
822 return NULL; | 822 return nullptr; |
823 case kRTree_BBoxHierarchyType: | 823 case kRTree_BBoxHierarchyType: |
824 return new SkRTreeFactory; | 824 return new SkRTreeFactory; |
825 } | 825 } |
826 SkASSERT(0); // invalid bbhType | 826 SkASSERT(0); // invalid bbhType |
827 return NULL; | 827 return nullptr; |
828 } | 828 } |
829 | 829 |
830 } // namespace sk_tools | 830 } // namespace sk_tools |
OLD | NEW |