| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 "SkAutoPixmapStorage.h" | 8 #include "SkAutoPixmapStorage.h" |
| 9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 if (context) { | 68 if (context) { |
| 69 sk_sp<GrTexture> texture(img->asTextureRef(context)); | 69 sk_sp<GrTexture> texture(img->asTextureRef(context)); |
| 70 REPORTER_ASSERT(reporter, texture); | 70 REPORTER_ASSERT(reporter, texture); |
| 71 } | 71 } |
| 72 #endif | 72 #endif |
| 73 | 73 |
| 74 //-------------- | 74 //-------------- |
| 75 // Test getROPixels - this should always succeed regardless of backing store | 75 // Test getROPixels - this should always succeed regardless of backing store |
| 76 SkBitmap bitmap; | 76 SkBitmap bitmap; |
| 77 REPORTER_ASSERT(reporter, img->getROPixels(&bitmap)); | 77 REPORTER_ASSERT(reporter, img->getROPixels(&bitmap)); |
| 78 REPORTER_ASSERT(reporter, size == bitmap.width()); | 78 if (context) { |
| 79 REPORTER_ASSERT(reporter, size == bitmap.height()); | 79 REPORTER_ASSERT(reporter, kSmallerSize == bitmap.width()); |
| 80 REPORTER_ASSERT(reporter, kSmallerSize == bitmap.height()); |
| 81 } else { |
| 82 REPORTER_ASSERT(reporter, size == bitmap.width()); |
| 83 REPORTER_ASSERT(reporter, size == bitmap.height()); |
| 84 } |
| 80 | 85 |
| 81 //-------------- | 86 //-------------- |
| 82 // Test that draw restricts itself to the subset | 87 // Test that draw restricts itself to the subset |
| 83 SkImageInfo info = SkImageInfo::MakeN32(kFullSize, kFullSize, kOpaque_SkAlph
aType); | 88 SkImageInfo info = SkImageInfo::MakeN32(kFullSize, kFullSize, kOpaque_SkAlph
aType); |
| 84 | 89 |
| 85 sk_sp<SkSpecialSurface> surf(img->makeSurface(info)); | 90 sk_sp<SkSpecialSurface> surf(img->makeSurface(info)); |
| 86 | 91 |
| 87 SkCanvas* canvas = surf->getCanvas(); | 92 SkCanvas* canvas = surf->getCanvas(); |
| 88 | 93 |
| 89 canvas->clear(SK_ColorBLUE); | 94 canvas->clear(SK_ColorBLUE); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 sk_sp<SkImage> fullImage(SkImage::MakeFromBitmap(bm)); | 161 sk_sp<SkImage> fullImage(SkImage::MakeFromBitmap(bm)); |
| 157 | 162 |
| 158 sk_sp<SkSpecialImage> fullSImage(SkSpecialImage::MakeFromImage( | 163 sk_sp<SkSpecialImage> fullSImage(SkSpecialImage::MakeFromImage( |
| 159 SkIRect::MakeWH(kFul
lSize, kFullSize), | 164 SkIRect::MakeWH(kFul
lSize, kFullSize), |
| 160 fullImage)); | 165 fullImage)); |
| 161 | 166 |
| 162 const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmaller
Size); | 167 const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmaller
Size); |
| 163 | 168 |
| 164 { | 169 { |
| 165 sk_sp<SkSpecialImage> subSImg1(SkSpecialImage::MakeFromImage(subset, ful
lImage)); | 170 sk_sp<SkSpecialImage> subSImg1(SkSpecialImage::MakeFromImage(subset, ful
lImage)); |
| 166 test_image(subSImg1, reporter, nullptr, false, kPad, kSmallerSize); | 171 test_image(subSImg1, reporter, nullptr, false, kPad, kFullSize); |
| 167 } | 172 } |
| 168 | 173 |
| 169 { | 174 { |
| 170 sk_sp<SkSpecialImage> subSImg2(fullSImage->makeSubset(subset)); | 175 sk_sp<SkSpecialImage> subSImg2(fullSImage->makeSubset(subset)); |
| 171 test_image(subSImg2, reporter, nullptr, false, kPad, kSmallerSize); | 176 test_image(subSImg2, reporter, nullptr, false, 0, kSmallerSize); |
| 172 } | 177 } |
| 173 } | 178 } |
| 174 | 179 |
| 175 DEF_TEST(SpecialImage_Pixmap, reporter) { | 180 DEF_TEST(SpecialImage_Pixmap, reporter) { |
| 176 SkAutoPixmapStorage pixmap; | 181 SkAutoPixmapStorage pixmap; |
| 177 | 182 |
| 178 const SkImageInfo info = SkImageInfo::MakeN32(kFullSize, kFullSize, kOpaque_
SkAlphaType); | 183 const SkImageInfo info = SkImageInfo::MakeN32(kFullSize, kFullSize, kOpaque_
SkAlphaType); |
| 179 pixmap.alloc(info); | 184 pixmap.alloc(info); |
| 180 pixmap.erase(SK_ColorGREEN); | 185 pixmap.erase(SK_ColorGREEN); |
| 181 | 186 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 kNeedNewImageUniqueI
D_SpecialImage, | 293 kNeedNewImageUniqueI
D_SpecialImage, |
| 289 texture)); | 294 texture)); |
| 290 | 295 |
| 291 const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmaller
Size); | 296 const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmaller
Size); |
| 292 | 297 |
| 293 { | 298 { |
| 294 sk_sp<SkSpecialImage> subSImg1(SkSpecialImage::MakeFromGpu( | 299 sk_sp<SkSpecialImage> subSImg1(SkSpecialImage::MakeFromGpu( |
| 295 subset, | 300 subset, |
| 296 kNeedNewImageUniq
ueID_SpecialImage, | 301 kNeedNewImageUniq
ueID_SpecialImage, |
| 297 texture)); | 302 texture)); |
| 298 test_image(subSImg1, reporter, context, true, kPad, kSmallerSize); | 303 test_image(subSImg1, reporter, context, true, kPad, kFullSize); |
| 299 } | 304 } |
| 300 | 305 |
| 301 { | 306 { |
| 302 sk_sp<SkSpecialImage> subSImg2(fullSImg->makeSubset(subset)); | 307 sk_sp<SkSpecialImage> subSImg2(fullSImg->makeSubset(subset)); |
| 303 test_image(subSImg2, reporter, context, true, kPad, kSmallerSize); | 308 test_image(subSImg2, reporter, context, true, kPad, kFullSize); |
| 304 } | 309 } |
| 305 } | 310 } |
| 306 | 311 |
| 307 #endif | 312 #endif |
| OLD | NEW |