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