| 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" |
| 11 #include "SkCanvas.h" | 11 #include "SkCanvas.h" |
| 12 #include "SkData.h" |
| 12 #include "SkDevice.h" | 13 #include "SkDevice.h" |
| 13 #include "SkGPipe.h" | 14 #include "SkGPipe.h" |
| 14 #if SK_SUPPORT_GPU | 15 #if SK_SUPPORT_GPU |
| 15 #include "gl/GrGLDefines.h" | 16 #include "gl/GrGLDefines.h" |
| 16 #include "SkGpuDevice.h" | 17 #include "SkGpuDevice.h" |
| 17 #endif | 18 #endif |
| 18 #include "SkGraphics.h" | 19 #include "SkGraphics.h" |
| 19 #include "SkImageEncoder.h" | 20 #include "SkImageEncoder.h" |
| 20 #include "SkMaskFilter.h" | 21 #include "SkMaskFilter.h" |
| 21 #include "SkMatrix.h" | 22 #include "SkMatrix.h" |
| 22 #include "SkPicture.h" | 23 #include "SkPicture.h" |
| 24 #include "SkPictureUtils.h" |
| 25 #include "SkPixelRef.h" |
| 23 #include "SkRTree.h" | 26 #include "SkRTree.h" |
| 24 #include "SkScalar.h" | 27 #include "SkScalar.h" |
| 25 #include "SkStream.h" | 28 #include "SkStream.h" |
| 26 #include "SkString.h" | 29 #include "SkString.h" |
| 27 #include "SkTemplates.h" | 30 #include "SkTemplates.h" |
| 28 #include "SkTileGridPicture.h" | 31 #include "SkTileGridPicture.h" |
| 29 #include "SkTDArray.h" | 32 #include "SkTDArray.h" |
| 30 #include "SkThreadUtils.h" | 33 #include "SkThreadUtils.h" |
| 31 #include "SkTypes.h" | 34 #include "SkTypes.h" |
| 32 #include "SkData.h" | |
| 33 #include "SkPictureUtils.h" | |
| 34 | 35 |
| 35 namespace sk_tools { | 36 namespace sk_tools { |
| 36 | 37 |
| 37 enum { | 38 enum { |
| 38 kDefaultTileWidth = 256, | 39 kDefaultTileWidth = 256, |
| 39 kDefaultTileHeight = 256 | 40 kDefaultTileHeight = 256 |
| 40 }; | 41 }; |
| 41 | 42 |
| 42 void PictureRenderer::init(SkPicture* pict) { | 43 void PictureRenderer::init(SkPicture* pict) { |
| 43 SkASSERT(NULL == fPicture); | 44 SkASSERT(NULL == fPicture); |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 return write(canvas, pathWithNumber); | 251 return write(canvas, pathWithNumber); |
| 251 } | 252 } |
| 252 | 253 |
| 253 ////////////////////////////////////////////////////////////////////////////////
/////////////// | 254 ////////////////////////////////////////////////////////////////////////////////
/////////////// |
| 254 | 255 |
| 255 SkCanvas* RecordPictureRenderer::setupCanvas(int width, int height) { | 256 SkCanvas* RecordPictureRenderer::setupCanvas(int width, int height) { |
| 256 // defer the canvas setup until the render step | 257 // defer the canvas setup until the render step |
| 257 return NULL; | 258 return NULL; |
| 258 } | 259 } |
| 259 | 260 |
| 260 static bool PNGEncodeBitmapToStream(SkWStream* wStream, const SkBitmap& bm) { | 261 static SkData* encode_bitmap_to_data(size_t* offset, const SkBitmap& bm) { |
| 261 return SkImageEncoder::EncodeStream(wStream, bm, SkImageEncoder::kPNG_Type,
100); | 262 SkPixelRef* pr = bm.pixelRef(); |
| 263 if (pr != NULL) { |
| 264 SkData* data = pr->refEncodedData(); |
| 265 if (data != NULL) { |
| 266 *offset = bm.pixelRefOffset(); |
| 267 return data; |
| 268 } |
| 269 } |
| 270 *offset = 0; |
| 271 return SkImageEncoder::EncodeData(bm, SkImageEncoder::kPNG_Type, 100); |
| 262 } | 272 } |
| 263 | 273 |
| 264 bool RecordPictureRenderer::render(const SkString* path, SkBitmap** out) { | 274 bool RecordPictureRenderer::render(const SkString* path, SkBitmap** out) { |
| 265 SkAutoTUnref<SkPicture> replayer(this->createPicture()); | 275 SkAutoTUnref<SkPicture> replayer(this->createPicture()); |
| 266 SkCanvas* recorder = replayer->beginRecording(this->getViewWidth(), this->ge
tViewHeight(), | 276 SkCanvas* recorder = replayer->beginRecording(this->getViewWidth(), this->ge
tViewHeight(), |
| 267 this->recordFlags()); | 277 this->recordFlags()); |
| 268 this->scaleToScaleFactor(recorder); | 278 this->scaleToScaleFactor(recorder); |
| 269 fPicture->draw(recorder); | 279 fPicture->draw(recorder); |
| 270 replayer->endRecording(); | 280 replayer->endRecording(); |
| 271 if (path != NULL) { | 281 if (path != NULL) { |
| 272 // Record the new picture as a new SKP with PNG encoded bitmaps. | 282 // Record the new picture as a new SKP with PNG encoded bitmaps. |
| 273 SkString skpPath(*path); | 283 SkString skpPath(*path); |
| 274 // ".skp" was removed from 'path' before being passed in here. | 284 // ".skp" was removed from 'path' before being passed in here. |
| 275 skpPath.append(".skp"); | 285 skpPath.append(".skp"); |
| 276 SkFILEWStream stream(skpPath.c_str()); | 286 SkFILEWStream stream(skpPath.c_str()); |
| 277 replayer->serialize(&stream, &PNGEncodeBitmapToStream); | 287 replayer->serialize(&stream, &encode_bitmap_to_data); |
| 278 return true; | 288 return true; |
| 279 } | 289 } |
| 280 return false; | 290 return false; |
| 281 } | 291 } |
| 282 | 292 |
| 283 SkString RecordPictureRenderer::getConfigNameInternal() { | 293 SkString RecordPictureRenderer::getConfigNameInternal() { |
| 284 return SkString("record"); | 294 return SkString("record"); |
| 285 } | 295 } |
| 286 | 296 |
| 287 ////////////////////////////////////////////////////////////////////////////////
/////////////// | 297 ////////////////////////////////////////////////////////////////////////////////
/////////////// |
| (...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 842 virtual SkString getConfigNameInternal() SK_OVERRIDE { | 852 virtual SkString getConfigNameInternal() SK_OVERRIDE { |
| 843 return SkString("picture_clone"); | 853 return SkString("picture_clone"); |
| 844 } | 854 } |
| 845 }; | 855 }; |
| 846 | 856 |
| 847 PictureRenderer* CreatePictureCloneRenderer() { | 857 PictureRenderer* CreatePictureCloneRenderer() { |
| 848 return SkNEW(PictureCloneRenderer); | 858 return SkNEW(PictureCloneRenderer); |
| 849 } | 859 } |
| 850 | 860 |
| 851 } // namespace sk_tools | 861 } // namespace sk_tools |
| OLD | NEW |