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 820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
831 #endif | 831 #endif |
832 | 832 |
833 // Encodes to PNG, unless there is already encoded data, in which case that gets | 833 // Encodes to PNG, unless there is already encoded data, in which case that gets |
834 // used. | 834 // used. |
835 // FIXME: Share with PictureRenderer.cpp? | 835 // FIXME: Share with PictureRenderer.cpp? |
836 class PngPixelSerializer : public SkPixelSerializer { | 836 class PngPixelSerializer : public SkPixelSerializer { |
837 public: | 837 public: |
838 bool onUseEncodedData(const void*, size_t) SK_OVERRIDE { return true; } | 838 bool onUseEncodedData(const void*, size_t) SK_OVERRIDE { return true; } |
839 SkData* onEncodePixels(const SkImageInfo& info, const void* pixels, | 839 SkData* onEncodePixels(const SkImageInfo& info, const void* pixels, |
840 size_t rowBytes) SK_OVERRIDE { | 840 size_t rowBytes) SK_OVERRIDE { |
841 return SkImageEncoder::EncodeData(info, pixels, rowBytes, SkImageEncoder
::kPNG_Type, 100); | 841 return SkImageEncoder::EncodeData(info, pixels, rowBytes, kPNG_SkEncoded
Format, 100); |
842 } | 842 } |
843 }; | 843 }; |
844 | 844 |
845 static SkData* serialized_picture_from_bitmap(const SkBitmap& bitmap) { | 845 static SkData* serialized_picture_from_bitmap(const SkBitmap& bitmap) { |
846 SkPictureRecorder recorder; | 846 SkPictureRecorder recorder; |
847 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(bitmap.width()), | 847 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(bitmap.width()), |
848 SkIntToScalar(bitmap.height())); | 848 SkIntToScalar(bitmap.height())); |
849 canvas->drawBitmap(bitmap, 0, 0); | 849 canvas->drawBitmap(bitmap, 0, 0); |
850 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 850 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); |
851 | 851 |
(...skipping 17 matching lines...) Expand all Loading... |
869 "This threw more errors than expected."); | 869 "This threw more errors than expected."); |
870 REPORTER_ASSERT_MESSAGE(errorContext->fReporter, kParseError_SkError == erro
r, | 870 REPORTER_ASSERT_MESSAGE(errorContext->fReporter, kParseError_SkError == erro
r, |
871 SkGetLastErrorString()); | 871 SkGetLastErrorString()); |
872 } | 872 } |
873 | 873 |
874 static void test_bitmap_with_encoded_data(skiatest::Reporter* reporter) { | 874 static void test_bitmap_with_encoded_data(skiatest::Reporter* reporter) { |
875 // Create a bitmap that will be encoded. | 875 // Create a bitmap that will be encoded. |
876 SkBitmap original; | 876 SkBitmap original; |
877 make_bm(&original, 100, 100, SK_ColorBLUE, true); | 877 make_bm(&original, 100, 100, SK_ColorBLUE, true); |
878 SkDynamicMemoryWStream wStream; | 878 SkDynamicMemoryWStream wStream; |
879 if (!SkImageEncoder::EncodeStream(&wStream, original, SkImageEncoder::kPNG_T
ype, 100)) { | 879 if (!SkImageEncoder::EncodeStream(&wStream, original, kPNG_SkEncodedFormat,
100)) { |
880 return; | 880 return; |
881 } | 881 } |
882 SkAutoDataUnref data(wStream.copyToData()); | 882 SkAutoDataUnref data(wStream.copyToData()); |
883 | 883 |
884 SkBitmap bm; | 884 SkBitmap bm; |
885 bool installSuccess = SkInstallDiscardablePixelRef(data, &bm); | 885 bool installSuccess = SkInstallDiscardablePixelRef(data, &bm); |
886 REPORTER_ASSERT(reporter, installSuccess); | 886 REPORTER_ASSERT(reporter, installSuccess); |
887 | 887 |
888 // Write both bitmaps to pictures, and ensure that the resulting data stream
s are the same. | 888 // Write both bitmaps to pictures, and ensure that the resulting data stream
s are the same. |
889 // Flattening original will follow the old path of performing an encode, whi
le flattening bm | 889 // Flattening original will follow the old path of performing an encode, whi
le flattening bm |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1315 | 1315 |
1316 // The picture shares the immutable pixels but copies the mutable ones. | 1316 // The picture shares the immutable pixels but copies the mutable ones. |
1317 REPORTER_ASSERT(r, mut.pixelRef()->unique()); | 1317 REPORTER_ASSERT(r, mut.pixelRef()->unique()); |
1318 REPORTER_ASSERT(r, !immut.pixelRef()->unique()); | 1318 REPORTER_ASSERT(r, !immut.pixelRef()->unique()); |
1319 | 1319 |
1320 // When the picture goes away, it's just our bitmaps holding the refs. | 1320 // When the picture goes away, it's just our bitmaps holding the refs. |
1321 pic.reset(NULL); | 1321 pic.reset(NULL); |
1322 REPORTER_ASSERT(r, mut.pixelRef()->unique()); | 1322 REPORTER_ASSERT(r, mut.pixelRef()->unique()); |
1323 REPORTER_ASSERT(r, immut.pixelRef()->unique()); | 1323 REPORTER_ASSERT(r, immut.pixelRef()->unique()); |
1324 } | 1324 } |
OLD | NEW |