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

Side by Side Diff: tools/PictureRenderer.cpp

Issue 15489004: New API for encoding bitmaps during serialization. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Remove dead code, keep original data in rerecord. Created 7 years, 7 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
« include/core/SkPicture.h ('K') | « tests/PictureTest.cpp ('k') | no next file » | 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 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
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(SkPicture::RecordPixelRefOffset* recordOffs et,
261 return SkImageEncoder::EncodeStream(wStream, bm, SkImageEncoder::kPNG_Type, 100); 262 const SkBitmap& bm) {
263 SkPixelRef* pr = bm.pixelRef();
264 if (pr != NULL) {
265 SkData* data = pr->refEncodedData();
266 if (data != NULL) {
267 *recordOffset = SkPicture::kYes_RecordPixelRefOffset;
268 return data;
269 }
270 }
271 *recordOffset = SkPicture::kNo_RecordPixelRefOffset;
272 return SkImageEncoder::EncodeData(bm, SkImageEncoder::kPNG_Type, 100);
262 } 273 }
263 274
264 bool RecordPictureRenderer::render(const SkString* path, SkBitmap** out) { 275 bool RecordPictureRenderer::render(const SkString* path, SkBitmap** out) {
265 SkAutoTUnref<SkPicture> replayer(this->createPicture()); 276 SkAutoTUnref<SkPicture> replayer(this->createPicture());
266 SkCanvas* recorder = replayer->beginRecording(this->getViewWidth(), this->ge tViewHeight(), 277 SkCanvas* recorder = replayer->beginRecording(this->getViewWidth(), this->ge tViewHeight(),
267 this->recordFlags()); 278 this->recordFlags());
268 this->scaleToScaleFactor(recorder); 279 this->scaleToScaleFactor(recorder);
269 fPicture->draw(recorder); 280 fPicture->draw(recorder);
270 replayer->endRecording(); 281 replayer->endRecording();
271 if (path != NULL) { 282 if (path != NULL) {
272 // Record the new picture as a new SKP with PNG encoded bitmaps. 283 // Record the new picture as a new SKP with PNG encoded bitmaps.
273 SkString skpPath(*path); 284 SkString skpPath(*path);
274 // ".skp" was removed from 'path' before being passed in here. 285 // ".skp" was removed from 'path' before being passed in here.
275 skpPath.append(".skp"); 286 skpPath.append(".skp");
276 SkFILEWStream stream(skpPath.c_str()); 287 SkFILEWStream stream(skpPath.c_str());
277 replayer->serialize(&stream, &PNGEncodeBitmapToStream); 288 replayer->serialize(&stream, &encode_bitmap_to_data);
278 return true; 289 return true;
279 } 290 }
280 return false; 291 return false;
281 } 292 }
282 293
283 SkString RecordPictureRenderer::getConfigNameInternal() { 294 SkString RecordPictureRenderer::getConfigNameInternal() {
284 return SkString("record"); 295 return SkString("record");
285 } 296 }
286 297
287 //////////////////////////////////////////////////////////////////////////////// /////////////// 298 //////////////////////////////////////////////////////////////////////////////// ///////////////
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 virtual SkString getConfigNameInternal() SK_OVERRIDE { 853 virtual SkString getConfigNameInternal() SK_OVERRIDE {
843 return SkString("picture_clone"); 854 return SkString("picture_clone");
844 } 855 }
845 }; 856 };
846 857
847 PictureRenderer* CreatePictureCloneRenderer() { 858 PictureRenderer* CreatePictureCloneRenderer() {
848 return SkNEW(PictureCloneRenderer); 859 return SkNEW(PictureCloneRenderer);
849 } 860 }
850 861
851 } // namespace sk_tools 862 } // namespace sk_tools
OLDNEW
« include/core/SkPicture.h ('K') | « tests/PictureTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698