OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "SkCanvas.h" | 8 #include "SkCanvas.h" |
9 #include "SkData.h" | 9 #include "SkData.h" |
10 #include "SkDevice.h" | 10 #include "SkDevice.h" |
11 #include "SkImageEncoder.h" | 11 #include "SkImageEncoder.h" |
12 #include "SkImage_Base.h" | 12 #include "SkImage_Base.h" |
| 13 #include "SkPixelSerializer.h" |
13 #include "SkRRect.h" | 14 #include "SkRRect.h" |
14 #include "SkSurface.h" | 15 #include "SkSurface.h" |
15 #include "SkUtils.h" | 16 #include "SkUtils.h" |
16 #include "Test.h" | 17 #include "Test.h" |
17 | 18 |
18 #if SK_SUPPORT_GPU | 19 #if SK_SUPPORT_GPU |
19 #include "GrContextFactory.h" | 20 #include "GrContextFactory.h" |
20 #include "GrTest.h" | 21 #include "GrTest.h" |
21 #include "gl/GrGLInterface.h" | 22 #include "gl/GrGLInterface.h" |
22 #include "gl/GrGLUtil.h" | 23 #include "gl/GrGLUtil.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 DEF_GPUTEST(Image_Encode_Gpu, reporter, factory) { | 98 DEF_GPUTEST(Image_Encode_Gpu, reporter, factory) { |
98 GrContext* ctx = factory->get(GrContextFactory::kNative_GLContextType); | 99 GrContext* ctx = factory->get(GrContextFactory::kNative_GLContextType); |
99 if (!ctx) { | 100 if (!ctx) { |
100 REPORTER_ASSERT(reporter, false); | 101 REPORTER_ASSERT(reporter, false); |
101 return; | 102 return; |
102 } | 103 } |
103 test_encode(reporter, ctx); | 104 test_encode(reporter, ctx); |
104 } | 105 } |
105 #endif | 106 #endif |
106 | 107 |
| 108 namespace { |
| 109 |
| 110 const char* kSerializedData = "serialized"; |
| 111 |
| 112 class MockSerializer : public SkPixelSerializer { |
| 113 protected: |
| 114 bool onUseEncodedData(const void*, size_t) override { |
| 115 return false; |
| 116 } |
| 117 |
| 118 SkData* onEncodePixels(const SkImageInfo&, const void*, size_t) override { |
| 119 return SkData::NewWithCString(kSerializedData); |
| 120 } |
| 121 }; |
| 122 |
| 123 } // anonymous namespace |
| 124 |
| 125 // Test that SkImage encoding observes custom pixel serializers. |
| 126 DEF_TEST(Image_Encode_Serializer, reporter) { |
| 127 MockSerializer serializer; |
| 128 const SkIRect ir = SkIRect::MakeXYWH(5, 5, 10, 10); |
| 129 SkAutoTUnref<SkImage> image(make_image(nullptr, 20, 20, ir)); |
| 130 SkAutoTUnref<SkData> encoded(image->encode(&serializer)); |
| 131 SkAutoTUnref<SkData> reference(SkData::NewWithCString(kSerializedData)); |
| 132 |
| 133 REPORTER_ASSERT(reporter, encoded); |
| 134 REPORTER_ASSERT(reporter, encoded->size() > 0); |
| 135 REPORTER_ASSERT(reporter, encoded->equals(reference)); |
| 136 } |
| 137 |
107 DEF_TEST(Image_NewRasterCopy, reporter) { | 138 DEF_TEST(Image_NewRasterCopy, reporter) { |
108 const SkPMColor red = SkPackARGB32(0xFF, 0xFF, 0, 0); | 139 const SkPMColor red = SkPackARGB32(0xFF, 0xFF, 0, 0); |
109 const SkPMColor green = SkPackARGB32(0xFF, 0, 0xFF, 0); | 140 const SkPMColor green = SkPackARGB32(0xFF, 0, 0xFF, 0); |
110 const SkPMColor blue = SkPackARGB32(0xFF, 0, 0, 0xFF); | 141 const SkPMColor blue = SkPackARGB32(0xFF, 0, 0, 0xFF); |
111 SkPMColor colors[] = { red, green, blue, 0 }; | 142 SkPMColor colors[] = { red, green, blue, 0 }; |
112 SkAutoTUnref<SkColorTable> ctable(new SkColorTable(colors, SK_ARRAY_COUNT(co
lors))); | 143 SkAutoTUnref<SkColorTable> ctable(new SkColorTable(colors, SK_ARRAY_COUNT(co
lors))); |
113 // The colortable made a copy, so we can trash the original colors | 144 // The colortable made a copy, so we can trash the original colors |
114 memset(colors, 0xFF, sizeof(colors)); | 145 memset(colors, 0xFF, sizeof(colors)); |
115 | 146 |
116 const SkImageInfo srcInfo = SkImageInfo::Make(2, 2, kIndex_8_SkColorType, kP
remul_SkAlphaType); | 147 const SkImageInfo srcInfo = SkImageInfo::Make(2, 2, kIndex_8_SkColorType, kP
remul_SkAlphaType); |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 } | 339 } |
309 } | 340 } |
310 | 341 |
311 image.reset(nullptr); | 342 image.reset(nullptr); |
312 { | 343 { |
313 SkBitmap cachedBitmap; | 344 SkBitmap cachedBitmap; |
314 REPORTER_ASSERT(reporter, !SkBitmapCache::Find(uniqueID, &cachedBitmap))
; | 345 REPORTER_ASSERT(reporter, !SkBitmapCache::Find(uniqueID, &cachedBitmap))
; |
315 } | 346 } |
316 } | 347 } |
317 #endif | 348 #endif |
OLD | NEW |