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 |
| 134 // Test that a draw that only partially covers the drawing surface isn't |
| 135 // interpreted as covering the entire drawing surface (i.e., exercise one of the |
| 136 // conditions of SkCanvas::wouldOverwriteEntireSurface()). |
| 137 DEF_TEST(Image_RetainSnapshot, reporter) { |
| 138 const SkPMColor red = SkPackARGB32(0xFF, 0xFF, 0, 0); |
| 139 const SkPMColor green = SkPackARGB32(0xFF, 0, 0xFF, 0); |
| 140 SkImageInfo info = SkImageInfo::MakeN32Premul(2, 2); |
| 141 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); |
| 142 surface->getCanvas()->clear(0xFF00FF00); |
| 143 |
| 144 SkPMColor pixels[4]; |
| 145 memset(pixels, 0xFF, sizeof(pixels)); // init with values we don't expect |
| 146 const SkImageInfo dstInfo = SkImageInfo::MakeN32Premul(2, 2); |
| 147 const size_t dstRowBytes = 2 * sizeof(SkPMColor); |
| 148 |
| 149 SkAutoTUnref<SkImage> image1(surface->newImageSnapshot()); |
| 150 REPORTER_ASSERT(reporter, image1->readPixels(dstInfo, pixels, dstRowBytes, 0
, 0)); |
| 151 for (size_t i = 0; i < SK_ARRAY_COUNT(pixels); ++i) { |
| 152 REPORTER_ASSERT(reporter, pixels[i] == green); |
| 153 } |
| 154 |
| 155 SkPaint paint; |
| 156 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
| 157 paint.setColor(SK_ColorRED); |
| 158 |
| 159 surface->getCanvas()->drawRect(SkRect::MakeXYWH(1, 1, 1, 1), paint); |
| 160 |
| 161 SkAutoTUnref<SkImage> image2(surface->newImageSnapshot()); |
| 162 REPORTER_ASSERT(reporter, image2->readPixels(dstInfo, pixels, dstRowBytes, 0
, 0)); |
| 163 REPORTER_ASSERT(reporter, pixels[0] == green); |
| 164 REPORTER_ASSERT(reporter, pixels[1] == green); |
| 165 REPORTER_ASSERT(reporter, pixels[2] == green); |
| 166 REPORTER_ASSERT(reporter, pixels[3] == red); |
| 167 } |
OLD | NEW |