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 |
| 133 static void test_image_readpixels(skiatest::Reporter* reporter, SkImage* image, |
| 134 SkPMColor expected) { |
| 135 const SkPMColor notExpected = ~expected; |
| 136 |
| 137 const int w = 2, h = 2; |
| 138 const size_t rowBytes = w * sizeof(SkPMColor); |
| 139 SkPMColor pixels[w*h]; |
| 140 |
| 141 SkImageInfo info; |
| 142 |
| 143 info = SkImageInfo::MakeUnknown(w, h); |
| 144 REPORTER_ASSERT(reporter, !image->readPixels(info, pixels, rowBytes, 0, 0)); |
| 145 |
| 146 // out-of-bounds should fail |
| 147 info = SkImageInfo::MakeN32Premul(w, h); |
| 148 REPORTER_ASSERT(reporter, !image->readPixels(info, pixels, rowBytes, -w, 0))
; |
| 149 REPORTER_ASSERT(reporter, !image->readPixels(info, pixels, rowBytes, 0, -h))
; |
| 150 REPORTER_ASSERT(reporter, !image->readPixels(info, pixels, rowBytes, image->
width(), 0)); |
| 151 REPORTER_ASSERT(reporter, !image->readPixels(info, pixels, rowBytes, 0, imag
e->height())); |
| 152 |
| 153 // top-left should succeed |
| 154 set_pixels(pixels, w*h, notExpected); |
| 155 REPORTER_ASSERT(reporter, image->readPixels(info, pixels, rowBytes, 0, 0)); |
| 156 REPORTER_ASSERT(reporter, has_pixels(pixels, w*h, expected)); |
| 157 |
| 158 // bottom-right should succeed |
| 159 set_pixels(pixels, w*h, notExpected); |
| 160 REPORTER_ASSERT(reporter, image->readPixels(info, pixels, rowBytes, |
| 161 image->width() - w, image->heigh
t() - h)); |
| 162 REPORTER_ASSERT(reporter, has_pixels(pixels, w*h, expected)); |
| 163 |
| 164 // partial top-left should succeed |
| 165 set_pixels(pixels, w*h, notExpected); |
| 166 REPORTER_ASSERT(reporter, image->readPixels(info, pixels, rowBytes, -1, -1))
; |
| 167 REPORTER_ASSERT(reporter, pixels[3] == expected); |
| 168 REPORTER_ASSERT(reporter, has_pixels(pixels, w*h - 1, notExpected)); |
| 169 |
| 170 // partial bottom-right should succeed |
| 171 set_pixels(pixels, w*h, notExpected); |
| 172 REPORTER_ASSERT(reporter, image->readPixels(info, pixels, rowBytes, |
| 173 image->width() - 1, image->heigh
t() - 1)); |
| 174 REPORTER_ASSERT(reporter, pixels[0] == expected); |
| 175 REPORTER_ASSERT(reporter, has_pixels(&pixels[1], w*h - 1, notExpected)); |
| 176 } |
| 177 |
121 static void test_imagepeek(skiatest::Reporter* reporter, GrContextFactory* facto
ry) { | 178 static void test_imagepeek(skiatest::Reporter* reporter, GrContextFactory* facto
ry) { |
122 static const struct { | 179 static const struct { |
123 ImageType fType; | 180 ImageType fType; |
124 bool fPeekShouldSucceed; | 181 bool fPeekShouldSucceed; |
125 const char* fName; | 182 const char* fName; |
126 } gRec[] = { | 183 } gRec[] = { |
127 { kRasterCopy_ImageType, true, "RasterCopy" }, | 184 { kRasterCopy_ImageType, true, "RasterCopy" }, |
128 { kRasterData_ImageType, true, "RasterData" }, | 185 { kRasterData_ImageType, true, "RasterData" }, |
129 { kGpu_ImageType, false, "Gpu" }, | 186 { kGpu_ImageType, false, "Gpu" }, |
130 { kCodec_ImageType, false, "Codec" }, | 187 { kCodec_ImageType, false, "Codec" }, |
(...skipping 21 matching lines...) Expand all Loading... |
152 REPORTER_ASSERT(reporter, gRec[i].fPeekShouldSucceed == success); | 209 REPORTER_ASSERT(reporter, gRec[i].fPeekShouldSucceed == success); |
153 if (success) { | 210 if (success) { |
154 REPORTER_ASSERT(reporter, 10 == info.width()); | 211 REPORTER_ASSERT(reporter, 10 == info.width()); |
155 REPORTER_ASSERT(reporter, 10 == info.height()); | 212 REPORTER_ASSERT(reporter, 10 == info.height()); |
156 REPORTER_ASSERT(reporter, kN32_SkColorType == info.colorType()); | 213 REPORTER_ASSERT(reporter, kN32_SkColorType == info.colorType()); |
157 REPORTER_ASSERT(reporter, kPremul_SkAlphaType == info.alphaType() || | 214 REPORTER_ASSERT(reporter, kPremul_SkAlphaType == info.alphaType() || |
158 kOpaque_SkAlphaType == info.alphaType()); | 215 kOpaque_SkAlphaType == info.alphaType()); |
159 REPORTER_ASSERT(reporter, info.minRowBytes() <= rowBytes); | 216 REPORTER_ASSERT(reporter, info.minRowBytes() <= rowBytes); |
160 REPORTER_ASSERT(reporter, pmcolor == *(const SkPMColor*)addr); | 217 REPORTER_ASSERT(reporter, pmcolor == *(const SkPMColor*)addr); |
161 } | 218 } |
| 219 |
| 220 test_image_readpixels(reporter, image, pmcolor); |
162 } | 221 } |
163 } | 222 } |
164 | 223 |
165 static void test_canvaspeek(skiatest::Reporter* reporter, | 224 static void test_canvaspeek(skiatest::Reporter* reporter, |
166 GrContextFactory* factory) { | 225 GrContextFactory* factory) { |
167 static const struct { | 226 static const struct { |
168 SurfaceType fType; | 227 SurfaceType fType; |
169 bool fPeekShouldSucceed; | 228 bool fPeekShouldSucceed; |
170 } gRec[] = { | 229 } gRec[] = { |
171 { kRaster_SurfaceType, true }, | 230 { 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); | 503 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context,
SkSurface::kDiscard_ContentChangeMode); |
445 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurfa
ce::kRetain_ContentChangeMode); | 504 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurfa
ce::kRetain_ContentChangeMode); |
446 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context,
SkSurface::kRetain_ContentChangeMode); | 505 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context,
SkSurface::kRetain_ContentChangeMode); |
447 TestGetTexture(reporter, kGpu_SurfaceType, context); | 506 TestGetTexture(reporter, kGpu_SurfaceType, context); |
448 TestGetTexture(reporter, kGpuScratch_SurfaceType, context); | 507 TestGetTexture(reporter, kGpuScratch_SurfaceType, context); |
449 } | 508 } |
450 } | 509 } |
451 } | 510 } |
452 #endif | 511 #endif |
453 } | 512 } |
OLD | NEW |