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 10 matching lines...) Expand all Loading... |
21 #include "SkGraphics.h" | 21 #include "SkGraphics.h" |
22 #include "SkImageEncoder.h" | 22 #include "SkImageEncoder.h" |
23 #include "SkMaskFilter.h" | 23 #include "SkMaskFilter.h" |
24 #include "SkMatrix.h" | 24 #include "SkMatrix.h" |
25 #include "SkMultiPictureDraw.h" | 25 #include "SkMultiPictureDraw.h" |
26 #include "SkOSFile.h" | 26 #include "SkOSFile.h" |
27 #include "SkPicture.h" | 27 #include "SkPicture.h" |
28 #include "SkPictureRecorder.h" | 28 #include "SkPictureRecorder.h" |
29 #include "SkPictureUtils.h" | 29 #include "SkPictureUtils.h" |
30 #include "SkPixelRef.h" | 30 #include "SkPixelRef.h" |
31 #include "SkPixelSerializer.h" | |
32 #include "SkScalar.h" | 31 #include "SkScalar.h" |
33 #include "SkStream.h" | 32 #include "SkStream.h" |
34 #include "SkString.h" | 33 #include "SkString.h" |
35 #include "SkSurface.h" | 34 #include "SkSurface.h" |
36 #include "SkTemplates.h" | 35 #include "SkTemplates.h" |
37 #include "SkTDArray.h" | 36 #include "SkTDArray.h" |
38 #include "SkThreadUtils.h" | 37 #include "SkThreadUtils.h" |
39 #include "SkTypes.h" | 38 #include "SkTypes.h" |
40 | 39 |
41 static inline SkScalar scalar_log2(SkScalar x) { | 40 static inline SkScalar scalar_log2(SkScalar x) { |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 } | 352 } |
354 } | 353 } |
355 | 354 |
356 ////////////////////////////////////////////////////////////////////////////////
/////////////// | 355 ////////////////////////////////////////////////////////////////////////////////
/////////////// |
357 | 356 |
358 SkCanvas* RecordPictureRenderer::setupCanvas(int width, int height) { | 357 SkCanvas* RecordPictureRenderer::setupCanvas(int width, int height) { |
359 // defer the canvas setup until the render step | 358 // defer the canvas setup until the render step |
360 return NULL; | 359 return NULL; |
361 } | 360 } |
362 | 361 |
363 // Encodes to PNG, unless there is already encoded data, in which case that gets | 362 // the size_t* parameter is deprecated, so we ignore it |
364 // used. | 363 static SkData* encode_bitmap_to_data(size_t*, const SkBitmap& bm) { |
365 // FIXME: Share with PictureTest.cpp? | 364 return SkImageEncoder::EncodeData(bm, SkImageEncoder::kPNG_Type, 100); |
366 | 365 } |
367 class PngPixelSerializer : public SkPixelSerializer { | |
368 public: | |
369 virtual bool onUseEncodedData(const void*, size_t) SK_OVERRIDE { return true
; } | |
370 virtual SkData* onEncodePixels(const SkImageInfo& info, void* pixels, | |
371 size_t rowBytes) SK_OVERRIDE { | |
372 SkBitmap bm; | |
373 if (!bm.installPixels(info, pixels, rowBytes)) { | |
374 return NULL; | |
375 } | |
376 return SkImageEncoder::EncodeData(bm, SkImageEncoder::kPNG_Type, 100); | |
377 } | |
378 }; | |
379 | 366 |
380 bool RecordPictureRenderer::render(SkBitmap** out) { | 367 bool RecordPictureRenderer::render(SkBitmap** out) { |
381 SkAutoTDelete<SkBBHFactory> factory(this->getFactory()); | 368 SkAutoTDelete<SkBBHFactory> factory(this->getFactory()); |
382 SkPictureRecorder recorder; | 369 SkPictureRecorder recorder; |
383 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(this->getViewWidth(
)), | 370 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(this->getViewWidth(
)), |
384 SkIntToScalar(this->getViewHeight
()), | 371 SkIntToScalar(this->getViewHeight
()), |
385 factory.get(), | 372 factory.get(), |
386 this->recordFlags()); | 373 this->recordFlags()); |
387 this->scaleToScaleFactor(canvas); | 374 this->scaleToScaleFactor(canvas); |
388 fPicture->playback(canvas); | 375 fPicture->playback(canvas); |
389 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 376 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); |
390 if (!fWritePath.isEmpty()) { | 377 if (!fWritePath.isEmpty()) { |
391 // Record the new picture as a new SKP with PNG encoded bitmaps. | 378 // Record the new picture as a new SKP with PNG encoded bitmaps. |
392 SkString skpPath = SkOSPath::Join(fWritePath.c_str(), fInputFilename.c_s
tr()); | 379 SkString skpPath = SkOSPath::Join(fWritePath.c_str(), fInputFilename.c_s
tr()); |
393 SkFILEWStream stream(skpPath.c_str()); | 380 SkFILEWStream stream(skpPath.c_str()); |
394 PngPixelSerializer serializer; | 381 picture->serialize(&stream, &encode_bitmap_to_data); |
395 picture->serialize(&stream, &serializer); | |
396 return true; | 382 return true; |
397 } | 383 } |
398 return false; | 384 return false; |
399 } | 385 } |
400 | 386 |
401 SkString RecordPictureRenderer::getConfigNameInternal() { | 387 SkString RecordPictureRenderer::getConfigNameInternal() { |
402 return SkString("record"); | 388 return SkString("record"); |
403 } | 389 } |
404 | 390 |
405 ////////////////////////////////////////////////////////////////////////////////
/////////////// | 391 ////////////////////////////////////////////////////////////////////////////////
/////////////// |
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
868 PictureRenderer* CreateGatherPixelRefsRenderer(const GrContext::Options& opts) { | 854 PictureRenderer* CreateGatherPixelRefsRenderer(const GrContext::Options& opts) { |
869 return SkNEW_ARGS(GatherRenderer, (opts)); | 855 return SkNEW_ARGS(GatherRenderer, (opts)); |
870 } | 856 } |
871 #else | 857 #else |
872 PictureRenderer* CreateGatherPixelRefsRenderer() { | 858 PictureRenderer* CreateGatherPixelRefsRenderer() { |
873 return SkNEW(GatherRenderer); | 859 return SkNEW(GatherRenderer); |
874 } | 860 } |
875 #endif | 861 #endif |
876 | 862 |
877 } // namespace sk_tools | 863 } // namespace sk_tools |
OLD | NEW |