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 19 matching lines...) Expand all Loading... |
30 #include "SkPixelRef.h" | 30 #include "SkPixelRef.h" |
31 #include "SkPixelSerializer.h" | 31 #include "SkPixelSerializer.h" |
32 #include "SkScalar.h" | 32 #include "SkScalar.h" |
33 #include "SkStream.h" | 33 #include "SkStream.h" |
34 #include "SkString.h" | 34 #include "SkString.h" |
35 #include "SkSurface.h" | 35 #include "SkSurface.h" |
36 #include "SkTemplates.h" | 36 #include "SkTemplates.h" |
37 #include "SkTDArray.h" | 37 #include "SkTDArray.h" |
38 #include "SkThreadUtils.h" | 38 #include "SkThreadUtils.h" |
39 #include "SkTypes.h" | 39 #include "SkTypes.h" |
| 40 #include "sk_tool_utils.h" |
40 | 41 |
41 static inline SkScalar scalar_log2(SkScalar x) { | 42 static inline SkScalar scalar_log2(SkScalar x) { |
42 static const SkScalar log2_conversion_factor = SkScalarDiv(1, SkScalarLog(2)
); | 43 static const SkScalar log2_conversion_factor = SkScalarDiv(1, SkScalarLog(2)
); |
43 | 44 |
44 return SkScalarLog(x) * log2_conversion_factor; | 45 return SkScalarLog(x) * log2_conversion_factor; |
45 } | 46 } |
46 | 47 |
47 namespace sk_tools { | 48 namespace sk_tools { |
48 | 49 |
49 enum { | 50 enum { |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 } | 352 } |
352 } | 353 } |
353 | 354 |
354 ////////////////////////////////////////////////////////////////////////////////
/////////////// | 355 ////////////////////////////////////////////////////////////////////////////////
/////////////// |
355 | 356 |
356 SkCanvas* RecordPictureRenderer::setupCanvas(int width, int height) { | 357 SkCanvas* RecordPictureRenderer::setupCanvas(int width, int height) { |
357 // defer the canvas setup until the render step | 358 // defer the canvas setup until the render step |
358 return NULL; | 359 return NULL; |
359 } | 360 } |
360 | 361 |
361 // Encodes to PNG, unless there is already encoded data, in which case that gets | |
362 // used. | |
363 // FIXME: Share with PictureTest.cpp? | |
364 | |
365 class PngPixelSerializer : public SkPixelSerializer { | |
366 public: | |
367 bool onUseEncodedData(const void*, size_t) SK_OVERRIDE { return true; } | |
368 SkData* onEncodePixels(const SkImageInfo& info, const void* pixels, | |
369 size_t rowBytes) SK_OVERRIDE { | |
370 return SkImageEncoder::EncodeData(info, pixels, rowBytes, SkImageEncoder
::kPNG_Type, 100); | |
371 } | |
372 }; | |
373 | |
374 bool RecordPictureRenderer::render(SkBitmap** out) { | 362 bool RecordPictureRenderer::render(SkBitmap** out) { |
375 SkAutoTDelete<SkBBHFactory> factory(this->getFactory()); | 363 SkAutoTDelete<SkBBHFactory> factory(this->getFactory()); |
376 SkPictureRecorder recorder; | 364 SkPictureRecorder recorder; |
377 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(this->getViewWidth(
)), | 365 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(this->getViewWidth(
)), |
378 SkIntToScalar(this->getViewHeight
()), | 366 SkIntToScalar(this->getViewHeight
()), |
379 factory.get(), | 367 factory.get(), |
380 this->recordFlags()); | 368 this->recordFlags()); |
381 this->scaleToScaleFactor(canvas); | 369 this->scaleToScaleFactor(canvas); |
382 fPicture->playback(canvas); | 370 fPicture->playback(canvas); |
383 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 371 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); |
384 if (!fWritePath.isEmpty()) { | 372 if (!fWritePath.isEmpty()) { |
385 // Record the new picture as a new SKP with PNG encoded bitmaps. | 373 // Record the new picture as a new SKP with PNG encoded bitmaps. |
386 SkString skpPath = SkOSPath::Join(fWritePath.c_str(), fInputFilename.c_s
tr()); | 374 SkString skpPath = SkOSPath::Join(fWritePath.c_str(), fInputFilename.c_s
tr()); |
387 SkFILEWStream stream(skpPath.c_str()); | 375 SkFILEWStream stream(skpPath.c_str()); |
388 PngPixelSerializer serializer; | 376 sk_tool_utils::PngPixelSerializer serializer; |
389 picture->serialize(&stream, &serializer); | 377 picture->serialize(&stream, &serializer); |
390 return true; | 378 return true; |
391 } | 379 } |
392 return false; | 380 return false; |
393 } | 381 } |
394 | 382 |
395 SkString RecordPictureRenderer::getConfigNameInternal() { | 383 SkString RecordPictureRenderer::getConfigNameInternal() { |
396 return SkString("record"); | 384 return SkString("record"); |
397 } | 385 } |
398 | 386 |
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
825 case kNone_BBoxHierarchyType: | 813 case kNone_BBoxHierarchyType: |
826 return NULL; | 814 return NULL; |
827 case kRTree_BBoxHierarchyType: | 815 case kRTree_BBoxHierarchyType: |
828 return SkNEW(SkRTreeFactory); | 816 return SkNEW(SkRTreeFactory); |
829 } | 817 } |
830 SkASSERT(0); // invalid bbhType | 818 SkASSERT(0); // invalid bbhType |
831 return NULL; | 819 return NULL; |
832 } | 820 } |
833 | 821 |
834 } // namespace sk_tools | 822 } // namespace sk_tools |
OLD | NEW |