OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "SkDecodingImageGenerator.h" | 10 #include "SkDecodingImageGenerator.h" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
111 SkAutoTUnref<SkData> src( | 111 SkAutoTUnref<SkData> src( |
112 SkImageEncoder::EncodeData(bitmap, SkImageEncoder::kPNG_Type, 1 00)); | 112 SkImageEncoder::EncodeData(bitmap, SkImageEncoder::kPNG_Type, 1 00)); |
113 return SkImage::NewFromGenerator( | 113 return SkImage::NewFromGenerator( |
114 SkDecodingImageGenerator::Create(src, SkDecodingImageGenerator:: Options())); | 114 SkDecodingImageGenerator::Create(src, SkDecodingImageGenerator:: Options())); |
115 } | 115 } |
116 } | 116 } |
117 SkASSERT(false); | 117 SkASSERT(false); |
118 return NULL; | 118 return NULL; |
119 } | 119 } |
120 | 120 |
121 static void set_pixels(SkPMColor pixels[], int count, SkPMColor color) { | |
122 sk_memset32(pixels, color, count); | |
123 } | |
124 static bool has_pixels(const SkPMColor pixels[], int count, SkPMColor expected) { | |
125 for (int i = 0; i < count; ++i) { | |
126 if (pixels[i] != expected) { | |
127 return false; | |
128 } | |
129 } | |
130 return true; | |
131 } | |
132 | |
robertphillips
2014/12/10 17:03:43
// test SkImage's readPixels entry point
?
| |
133 static void test_readpixels(skiatest::Reporter* reporter, SkImage* image, SkPMCo lor expected) { | |
134 const SkPMColor notExpected = ~expected; | |
135 | |
136 const int w = 2, h = 2; | |
137 const size_t rowBytes = w * sizeof(SkPMColor); | |
138 SkPMColor pixels[w*h]; | |
139 | |
140 SkImageInfo info; | |
141 | |
142 info = SkImageInfo::MakeUnknown(w, h); | |
143 REPORTER_ASSERT(reporter, !image->readPixels(info, pixels, rowBytes, 0, 0)); | |
144 | |
145 // out-of-bounds should fail | |
146 info = SkImageInfo::MakeN32Premul(w, h); | |
147 REPORTER_ASSERT(reporter, !image->readPixels(info, pixels, rowBytes, -w, 0)) ; | |
148 REPORTER_ASSERT(reporter, !image->readPixels(info, pixels, rowBytes, 0, -h)) ; | |
149 REPORTER_ASSERT(reporter, !image->readPixels(info, pixels, rowBytes, image-> width(), 0)); | |
150 REPORTER_ASSERT(reporter, !image->readPixels(info, pixels, rowBytes, 0, imag e->height())); | |
151 | |
152 // top-left should succeed | |
153 set_pixels(pixels, w*h, notExpected); | |
154 REPORTER_ASSERT(reporter, image->readPixels(info, pixels, rowBytes, 0, 0)); | |
155 REPORTER_ASSERT(reporter, has_pixels(pixels, w*h, expected)); | |
156 | |
157 // bottom-right should succeed | |
158 set_pixels(pixels, w*h, notExpected); | |
159 REPORTER_ASSERT(reporter, image->readPixels(info, pixels, rowBytes, | |
160 image->width() - w, image->heigh t() - h)); | |
161 REPORTER_ASSERT(reporter, has_pixels(pixels, w*h, expected)); | |
162 | |
163 // partial top-left should succeed | |
164 set_pixels(pixels, w*h, notExpected); | |
165 REPORTER_ASSERT(reporter, image->readPixels(info, pixels, rowBytes, -1, -1)) ; | |
166 REPORTER_ASSERT(reporter, pixels[3] == expected); | |
167 REPORTER_ASSERT(reporter, has_pixels(pixels, w*h - 1, notExpected)); | |
168 | |
169 // partial bottom-right should succeed | |
170 set_pixels(pixels, w*h, notExpected); | |
171 REPORTER_ASSERT(reporter, image->readPixels(info, pixels, rowBytes, | |
172 image->width() - 1, image->heigh t() - 1)); | |
173 REPORTER_ASSERT(reporter, pixels[0] == expected); | |
174 REPORTER_ASSERT(reporter, has_pixels(&pixels[1], w*h - 1, notExpected)); | |
175 } | |
176 | |
121 static void test_imagepeek(skiatest::Reporter* reporter, GrContextFactory* facto ry) { | 177 static void test_imagepeek(skiatest::Reporter* reporter, GrContextFactory* facto ry) { |
122 static const struct { | 178 static const struct { |
123 ImageType fType; | 179 ImageType fType; |
124 bool fPeekShouldSucceed; | 180 bool fPeekShouldSucceed; |
125 const char* fName; | 181 const char* fName; |
126 } gRec[] = { | 182 } gRec[] = { |
127 { kRasterCopy_ImageType, true, "RasterCopy" }, | 183 { kRasterCopy_ImageType, true, "RasterCopy" }, |
128 { kRasterData_ImageType, true, "RasterData" }, | 184 { kRasterData_ImageType, true, "RasterData" }, |
129 { kGpu_ImageType, false, "Gpu" }, | 185 { kGpu_ImageType, false, "Gpu" }, |
130 { kCodec_ImageType, false, "Codec" }, | 186 { kCodec_ImageType, false, "Codec" }, |
(...skipping 21 matching lines...) Expand all Loading... | |
152 REPORTER_ASSERT(reporter, gRec[i].fPeekShouldSucceed == success); | 208 REPORTER_ASSERT(reporter, gRec[i].fPeekShouldSucceed == success); |
153 if (success) { | 209 if (success) { |
154 REPORTER_ASSERT(reporter, 10 == info.width()); | 210 REPORTER_ASSERT(reporter, 10 == info.width()); |
155 REPORTER_ASSERT(reporter, 10 == info.height()); | 211 REPORTER_ASSERT(reporter, 10 == info.height()); |
156 REPORTER_ASSERT(reporter, kN32_SkColorType == info.colorType()); | 212 REPORTER_ASSERT(reporter, kN32_SkColorType == info.colorType()); |
157 REPORTER_ASSERT(reporter, kPremul_SkAlphaType == info.alphaType() || | 213 REPORTER_ASSERT(reporter, kPremul_SkAlphaType == info.alphaType() || |
158 kOpaque_SkAlphaType == info.alphaType()); | 214 kOpaque_SkAlphaType == info.alphaType()); |
159 REPORTER_ASSERT(reporter, info.minRowBytes() <= rowBytes); | 215 REPORTER_ASSERT(reporter, info.minRowBytes() <= rowBytes); |
160 REPORTER_ASSERT(reporter, pmcolor == *(const SkPMColor*)addr); | 216 REPORTER_ASSERT(reporter, pmcolor == *(const SkPMColor*)addr); |
161 } | 217 } |
218 | |
219 test_readpixels(reporter, image, pmcolor); | |
162 } | 220 } |
163 } | 221 } |
164 | 222 |
165 static void test_canvaspeek(skiatest::Reporter* reporter, | 223 static void test_canvaspeek(skiatest::Reporter* reporter, |
166 GrContextFactory* factory) { | 224 GrContextFactory* factory) { |
167 static const struct { | 225 static const struct { |
168 SurfaceType fType; | 226 SurfaceType fType; |
169 bool fPeekShouldSucceed; | 227 bool fPeekShouldSucceed; |
170 } gRec[] = { | 228 } gRec[] = { |
171 { kRaster_SurfaceType, true }, | 229 { kRaster_SurfaceType, true }, |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
444 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context, SkSurface::kDiscard_ContentChangeMode); | 502 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context, SkSurface::kDiscard_ContentChangeMode); |
445 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurfa ce::kRetain_ContentChangeMode); | 503 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurfa ce::kRetain_ContentChangeMode); |
446 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context, SkSurface::kRetain_ContentChangeMode); | 504 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context, SkSurface::kRetain_ContentChangeMode); |
447 TestGetTexture(reporter, kGpu_SurfaceType, context); | 505 TestGetTexture(reporter, kGpu_SurfaceType, context); |
448 TestGetTexture(reporter, kGpuScratch_SurfaceType, context); | 506 TestGetTexture(reporter, kGpuScratch_SurfaceType, context); |
449 } | 507 } |
450 } | 508 } |
451 } | 509 } |
452 #endif | 510 #endif |
453 } | 511 } |
OLD | NEW |