| 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 "SkBBoxHierarchy.h" | 8 #include "SkBBoxHierarchy.h" |
| 9 #include "SkBlurImageFilter.h" | 9 #include "SkBlurImageFilter.h" |
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
| (...skipping 1430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1441 SkCanvas canvas; | 1441 SkCanvas canvas; |
| 1442 canvas.drawPicture(picture); | 1442 canvas.drawPicture(picture); |
| 1443 } | 1443 } |
| 1444 #endif | 1444 #endif |
| 1445 | 1445 |
| 1446 // Encodes to PNG, unless there is already encoded data, in which case that gets | 1446 // Encodes to PNG, unless there is already encoded data, in which case that gets |
| 1447 // used. | 1447 // used. |
| 1448 // FIXME: Share with PictureRenderer.cpp? | 1448 // FIXME: Share with PictureRenderer.cpp? |
| 1449 class PngPixelSerializer : public SkPixelSerializer { | 1449 class PngPixelSerializer : public SkPixelSerializer { |
| 1450 public: | 1450 public: |
| 1451 virtual bool onUseEncodedData(const void*, size_t) SK_OVERRIDE { return true
; } | 1451 bool onUseEncodedData(const void*, size_t) SK_OVERRIDE { return true; } |
| 1452 virtual SkData* onEncodePixels(const SkImageInfo& info, void* pixels, | 1452 SkData* onEncodePixels(const SkImageInfo& info, const void* pixels, |
| 1453 size_t rowBytes) SK_OVERRIDE { | 1453 size_t rowBytes) SK_OVERRIDE { |
| 1454 SkBitmap bm; | 1454 return SkImageEncoder::EncodeData(info, pixels, rowBytes, SkImageEncoder
::kPNG_Type, 100); |
| 1455 if (!bm.installPixels(info, pixels, rowBytes)) { | |
| 1456 return NULL; | |
| 1457 } | |
| 1458 return SkImageEncoder::EncodeData(bm, SkImageEncoder::kPNG_Type, 100); | |
| 1459 } | 1455 } |
| 1460 }; | 1456 }; |
| 1461 | 1457 |
| 1462 static SkData* serialized_picture_from_bitmap(const SkBitmap& bitmap) { | 1458 static SkData* serialized_picture_from_bitmap(const SkBitmap& bitmap) { |
| 1463 SkPictureRecorder recorder; | 1459 SkPictureRecorder recorder; |
| 1464 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(bitmap.width()), | 1460 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(bitmap.width()), |
| 1465 SkIntToScalar(bitmap.height())); | 1461 SkIntToScalar(bitmap.height())); |
| 1466 canvas->drawBitmap(bitmap, 0, 0); | 1462 canvas->drawBitmap(bitmap, 0, 0); |
| 1467 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 1463 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); |
| 1468 | 1464 |
| (...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1932 | 1928 |
| 1933 // The picture shares the immutable pixels but copies the mutable ones. | 1929 // The picture shares the immutable pixels but copies the mutable ones. |
| 1934 REPORTER_ASSERT(r, mut.pixelRef()->unique()); | 1930 REPORTER_ASSERT(r, mut.pixelRef()->unique()); |
| 1935 REPORTER_ASSERT(r, !immut.pixelRef()->unique()); | 1931 REPORTER_ASSERT(r, !immut.pixelRef()->unique()); |
| 1936 | 1932 |
| 1937 // When the picture goes away, it's just our bitmaps holding the refs. | 1933 // When the picture goes away, it's just our bitmaps holding the refs. |
| 1938 pic.reset(NULL); | 1934 pic.reset(NULL); |
| 1939 REPORTER_ASSERT(r, mut.pixelRef()->unique()); | 1935 REPORTER_ASSERT(r, mut.pixelRef()->unique()); |
| 1940 REPORTER_ASSERT(r, immut.pixelRef()->unique()); | 1936 REPORTER_ASSERT(r, immut.pixelRef()->unique()); |
| 1941 } | 1937 } |
| OLD | NEW |