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" |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 const SkImageInfo dstInfo = SkImageInfo::MakeN32Premul(2, 2); | 123 const SkImageInfo dstInfo = SkImageInfo::MakeN32Premul(2, 2); |
124 const size_t dstRowBytes = 2 * sizeof(SkPMColor); | 124 const size_t dstRowBytes = 2 * sizeof(SkPMColor); |
125 SkPMColor pixels[4]; | 125 SkPMColor pixels[4]; |
126 memset(pixels, 0xFF, sizeof(pixels)); // init with values we don't expect | 126 memset(pixels, 0xFF, sizeof(pixels)); // init with values we don't expect |
127 image->readPixels(dstInfo, pixels, dstRowBytes, 0, 0); | 127 image->readPixels(dstInfo, pixels, dstRowBytes, 0, 0); |
128 REPORTER_ASSERT(reporter, red == pixels[0]); | 128 REPORTER_ASSERT(reporter, red == pixels[0]); |
129 REPORTER_ASSERT(reporter, green == pixels[1]); | 129 REPORTER_ASSERT(reporter, green == pixels[1]); |
130 REPORTER_ASSERT(reporter, blue == pixels[2]); | 130 REPORTER_ASSERT(reporter, blue == pixels[2]); |
131 REPORTER_ASSERT(reporter, 0 == pixels[3]); | 131 REPORTER_ASSERT(reporter, 0 == pixels[3]); |
132 } | 132 } |
133 | |
robertphillips
2015/07/22 12:34:23
// Test that a draw that only partially covers the
f(malita)
2015/07/22 12:49:58
Done.
| |
134 DEF_TEST(Image_RetainSnapshot, reporter) { | |
135 const SkPMColor red = SkPackARGB32(0xFF, 0xFF, 0, 0); | |
136 const SkPMColor green = SkPackARGB32(0xFF, 0, 0xFF, 0); | |
137 SkImageInfo info = SkImageInfo::MakeN32Premul(2, 2); | |
138 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); | |
139 surface->getCanvas()->clear(0xFF00FF00); | |
140 | |
141 SkPMColor pixels[4]; | |
142 memset(pixels, 0xFF, sizeof(pixels)); // init with values we don't expect | |
143 const SkImageInfo dstInfo = SkImageInfo::MakeN32Premul(2, 2); | |
144 const size_t dstRowBytes = 2 * sizeof(SkPMColor); | |
145 | |
146 SkAutoTUnref<SkImage> image1(surface->newImageSnapshot()); | |
147 REPORTER_ASSERT(reporter, image1->readPixels(dstInfo, pixels, dstRowBytes, 0 , 0)); | |
148 for (size_t i = 0; i < SK_ARRAY_COUNT(pixels); ++i) { | |
149 REPORTER_ASSERT(reporter, pixels[i] == green); | |
150 } | |
151 | |
152 SkPaint paint; | |
153 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | |
154 paint.setColor(SK_ColorRED); | |
155 | |
156 surface->getCanvas()->drawRect(SkRect::MakeXYWH(1, 1, 1, 1), paint); | |
157 | |
158 SkAutoTUnref<SkImage> image2(surface->newImageSnapshot()); | |
159 REPORTER_ASSERT(reporter, image2->readPixels(dstInfo, pixels, dstRowBytes, 0 , 0)); | |
160 REPORTER_ASSERT(reporter, pixels[0] == green); | |
161 REPORTER_ASSERT(reporter, pixels[1] == green); | |
162 REPORTER_ASSERT(reporter, pixels[2] == green); | |
163 REPORTER_ASSERT(reporter, pixels[3] == red); | |
164 } | |
OLD | NEW |