| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 | 44 |
| 45 temp.drawRect(SkRect::MakeXYWH(SkIntToScalar(kPad), SkIntToScalar(kPad), | 45 temp.drawRect(SkRect::MakeXYWH(SkIntToScalar(kPad), SkIntToScalar(kPad), |
| 46 SkIntToScalar(kSmallerSize), SkIntToScalar(kS
mallerSize)), | 46 SkIntToScalar(kSmallerSize), SkIntToScalar(kS
mallerSize)), |
| 47 p); | 47 p); |
| 48 | 48 |
| 49 return bm; | 49 return bm; |
| 50 } | 50 } |
| 51 | 51 |
| 52 // Basic test of the SkSpecialImage public API (e.g., peekTexture, peekPixels &
draw) | 52 // Basic test of the SkSpecialImage public API (e.g., peekTexture, peekPixels &
draw) |
| 53 static void test_image(const sk_sp<SkSpecialImage>& img, skiatest::Reporter* rep
orter, | 53 static void test_image(const sk_sp<SkSpecialImage>& img, skiatest::Reporter* rep
orter, |
| 54 bool peekPixelsSucceeds, bool peekTextureSucceeds, | 54 GrContext* context, bool peekTextureSucceeds, |
| 55 int offset, int size) { | 55 int offset, int size) { |
| 56 const SkIRect subset = TestingSpecialImageAccess::Subset(img.get()); | 56 const SkIRect subset = TestingSpecialImageAccess::Subset(img.get()); |
| 57 REPORTER_ASSERT(reporter, offset == subset.left()); | 57 REPORTER_ASSERT(reporter, offset == subset.left()); |
| 58 REPORTER_ASSERT(reporter, offset == subset.top()); | 58 REPORTER_ASSERT(reporter, offset == subset.top()); |
| 59 REPORTER_ASSERT(reporter, kSmallerSize == subset.width()); | 59 REPORTER_ASSERT(reporter, kSmallerSize == subset.width()); |
| 60 REPORTER_ASSERT(reporter, kSmallerSize == subset.height()); | 60 REPORTER_ASSERT(reporter, kSmallerSize == subset.height()); |
| 61 | 61 |
| 62 //-------------- | 62 //-------------- |
| 63 // Test that peekTexture reports the correct backing type | 63 // Test that peekTexture reports the correct backing type |
| 64 REPORTER_ASSERT(reporter, peekTextureSucceeds == | 64 REPORTER_ASSERT(reporter, peekTextureSucceeds == img->isTextureBacked()); |
| 65 !!TestingSpecialImageAccess::PeekTexture
(img.get())); | 65 |
| 66 #if SK_SUPPORT_GPU |
| 67 //-------------- |
| 68 // Test getTextureAsRef - as long as there is a context this should succeed |
| 69 if (context) { |
| 70 sk_sp<GrTexture> texture(img->asTextureRef(context)); |
| 71 REPORTER_ASSERT(reporter, texture); |
| 72 } |
| 73 #endif |
| 66 | 74 |
| 67 //-------------- | 75 //-------------- |
| 68 // Test that peekPixels reports the correct backing type | 76 // Test getROPixels - this should always succeed regardless of backing store |
| 69 SkPixmap pixmap; | 77 SkBitmap bitmap; |
| 70 REPORTER_ASSERT(reporter, peekPixelsSucceeds == | 78 REPORTER_ASSERT(reporter, img->getROPixels(&bitmap)); |
| 71 !!TestingSpecialImageAccess::PeekPixels(img.get(),
&pixmap)); | 79 if (context) { |
| 72 if (peekPixelsSucceeds) { | 80 REPORTER_ASSERT(reporter, kSmallerSize == bitmap.width()); |
| 73 REPORTER_ASSERT(reporter, size == pixmap.width()); | 81 REPORTER_ASSERT(reporter, kSmallerSize == bitmap.height()); |
| 74 REPORTER_ASSERT(reporter, size == pixmap.height()); | 82 } else { |
| 83 REPORTER_ASSERT(reporter, size == bitmap.width()); |
| 84 REPORTER_ASSERT(reporter, size == bitmap.height()); |
| 75 } | 85 } |
| 76 | 86 |
| 77 //-------------- | 87 //-------------- |
| 78 // Test that draw restricts itself to the subset | 88 // Test that draw restricts itself to the subset |
| 79 SkImageInfo info = SkImageInfo::MakeN32(kFullSize, kFullSize, kOpaque_SkAlph
aType); | 89 SkImageInfo info = SkImageInfo::MakeN32(kFullSize, kFullSize, kOpaque_SkAlph
aType); |
| 80 | 90 |
| 81 sk_sp<SkSpecialSurface> surf(img->makeSurface(info)); | 91 sk_sp<SkSpecialSurface> surf(img->makeSurface(info)); |
| 82 | 92 |
| 83 SkCanvas* canvas = surf->getCanvas(); | 93 SkCanvas* canvas = surf->getCanvas(); |
| 84 | 94 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 103 // Test that makeTightSubset & makeTightSurface return appropriately sized o
bjects | 113 // Test that makeTightSubset & makeTightSurface return appropriately sized o
bjects |
| 104 // of the correct backing type | 114 // of the correct backing type |
| 105 SkIRect newSubset = SkIRect::MakeWH(subset.width(), subset.height()); | 115 SkIRect newSubset = SkIRect::MakeWH(subset.width(), subset.height()); |
| 106 { | 116 { |
| 107 sk_sp<SkImage> tightImg(img->makeTightSubset(newSubset)); | 117 sk_sp<SkImage> tightImg(img->makeTightSubset(newSubset)); |
| 108 | 118 |
| 109 REPORTER_ASSERT(reporter, tightImg->width() == subset.width()); | 119 REPORTER_ASSERT(reporter, tightImg->width() == subset.width()); |
| 110 REPORTER_ASSERT(reporter, tightImg->height() == subset.height()); | 120 REPORTER_ASSERT(reporter, tightImg->height() == subset.height()); |
| 111 REPORTER_ASSERT(reporter, peekTextureSucceeds == !!tightImg->getTexture(
)); | 121 REPORTER_ASSERT(reporter, peekTextureSucceeds == !!tightImg->getTexture(
)); |
| 112 SkPixmap tmpPixmap; | 122 SkPixmap tmpPixmap; |
| 113 REPORTER_ASSERT(reporter, peekPixelsSucceeds == !!tightImg->peekPixels(&
tmpPixmap)); | 123 REPORTER_ASSERT(reporter, peekTextureSucceeds != !!tightImg->peekPixels(
&tmpPixmap)); |
| 114 } | 124 } |
| 115 { | 125 { |
| 116 SkImageInfo info = SkImageInfo::MakeN32(subset.width(), subset.height(), | 126 SkImageInfo info = SkImageInfo::MakeN32(subset.width(), subset.height(), |
| 117 kPremul_SkAlphaType); | 127 kPremul_SkAlphaType); |
| 118 sk_sp<SkSurface> tightSurf(img->makeTightSurface(info)); | 128 sk_sp<SkSurface> tightSurf(img->makeTightSurface(info)); |
| 119 | 129 |
| 120 REPORTER_ASSERT(reporter, tightSurf->width() == subset.width()); | 130 REPORTER_ASSERT(reporter, tightSurf->width() == subset.width()); |
| 121 REPORTER_ASSERT(reporter, tightSurf->height() == subset.height()); | 131 REPORTER_ASSERT(reporter, tightSurf->height() == subset.height()); |
| 122 REPORTER_ASSERT(reporter, peekTextureSucceeds == | 132 REPORTER_ASSERT(reporter, peekTextureSucceeds == |
| 123 !!tightSurf->getTextureHandle(SkSurface::kDiscardWrite_Back
endHandleAccess)); | 133 !!tightSurf->getTextureHandle(SkSurface::kDiscardWrite_Back
endHandleAccess)); |
| 124 SkPixmap tmpPixmap; | 134 SkPixmap tmpPixmap; |
| 125 REPORTER_ASSERT(reporter, peekPixelsSucceeds == !!tightSurf->peekPixels(
&tmpPixmap)); | 135 REPORTER_ASSERT(reporter, peekTextureSucceeds != !!tightSurf->peekPixels
(&tmpPixmap)); |
| 126 } | 136 } |
| 127 } | 137 } |
| 128 | 138 |
| 129 DEF_TEST(SpecialImage_Raster, reporter) { | 139 DEF_TEST(SpecialImage_Raster, reporter) { |
| 130 SkBitmap bm = create_bm(); | 140 SkBitmap bm = create_bm(); |
| 131 | 141 |
| 132 sk_sp<SkSpecialImage> fullSImage(SkSpecialImage::MakeFromRaster( | 142 sk_sp<SkSpecialImage> fullSImage(SkSpecialImage::MakeFromRaster( |
| 133 nullptr, | 143 nullptr, |
| 134 SkIRect::MakeWH(kFul
lSize, kFullSize), | 144 SkIRect::MakeWH(kFul
lSize, kFullSize), |
| 135 bm)); | 145 bm)); |
| 136 | 146 |
| 137 const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmaller
Size); | 147 const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmaller
Size); |
| 138 | 148 |
| 139 { | 149 { |
| 140 sk_sp<SkSpecialImage> subSImg1(SkSpecialImage::MakeFromRaster(nullptr, s
ubset, bm)); | 150 sk_sp<SkSpecialImage> subSImg1(SkSpecialImage::MakeFromRaster(nullptr, s
ubset, bm)); |
| 141 test_image(subSImg1, reporter, true, false, kPad, kFullSize); | 151 test_image(subSImg1, reporter, nullptr, false, kPad, kFullSize); |
| 142 } | 152 } |
| 143 | 153 |
| 144 { | 154 { |
| 145 sk_sp<SkSpecialImage> subSImg2(fullSImage->makeSubset(subset)); | 155 sk_sp<SkSpecialImage> subSImg2(fullSImage->makeSubset(subset)); |
| 146 test_image(subSImg2, reporter, true, false, 0, kSmallerSize); | 156 test_image(subSImg2, reporter, nullptr, false, 0, kSmallerSize); |
| 147 } | 157 } |
| 148 } | 158 } |
| 149 | 159 |
| 150 DEF_TEST(SpecialImage_Image, reporter) { | 160 DEF_TEST(SpecialImage_Image, reporter) { |
| 151 SkBitmap bm = create_bm(); | 161 SkBitmap bm = create_bm(); |
| 152 | 162 |
| 153 sk_sp<SkImage> fullImage(SkImage::MakeFromBitmap(bm)); | 163 sk_sp<SkImage> fullImage(SkImage::MakeFromBitmap(bm)); |
| 154 | 164 |
| 155 sk_sp<SkSpecialImage> fullSImage(SkSpecialImage::MakeFromImage( | 165 sk_sp<SkSpecialImage> fullSImage(SkSpecialImage::MakeFromImage( |
| 156 nullptr, | 166 nullptr, |
| 157 SkIRect::MakeWH(kFul
lSize, kFullSize), | 167 SkIRect::MakeWH(kFul
lSize, kFullSize), |
| 158 fullImage)); | 168 fullImage)); |
| 159 | 169 |
| 160 const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmaller
Size); | 170 const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmaller
Size); |
| 161 | 171 |
| 162 { | 172 { |
| 163 sk_sp<SkSpecialImage> subSImg1(SkSpecialImage::MakeFromImage(nullptr, su
bset, | 173 sk_sp<SkSpecialImage> subSImg1(SkSpecialImage::MakeFromImage(nullptr, su
bset, |
| 164 fullImage))
; | 174 fullImage))
; |
| 165 test_image(subSImg1, reporter, true, false, kPad, kFullSize); | 175 test_image(subSImg1, reporter, nullptr, false, kPad, kFullSize); |
| 166 } | 176 } |
| 167 | 177 |
| 168 { | 178 { |
| 169 sk_sp<SkSpecialImage> subSImg2(fullSImage->makeSubset(subset)); | 179 sk_sp<SkSpecialImage> subSImg2(fullSImage->makeSubset(subset)); |
| 170 test_image(subSImg2, reporter, true, false, 0, kSmallerSize); | 180 test_image(subSImg2, reporter, nullptr, false, 0, kSmallerSize); |
| 171 } | 181 } |
| 172 } | 182 } |
| 173 | 183 |
| 174 DEF_TEST(SpecialImage_Pixmap, reporter) { | 184 DEF_TEST(SpecialImage_Pixmap, reporter) { |
| 175 SkAutoPixmapStorage pixmap; | 185 SkAutoPixmapStorage pixmap; |
| 176 | 186 |
| 177 const SkImageInfo info = SkImageInfo::MakeN32(kFullSize, kFullSize, kOpaque_
SkAlphaType); | 187 const SkImageInfo info = SkImageInfo::MakeN32(kFullSize, kFullSize, kOpaque_
SkAlphaType); |
| 178 pixmap.alloc(info); | 188 pixmap.alloc(info); |
| 179 pixmap.erase(SK_ColorGREEN); | 189 pixmap.erase(SK_ColorGREEN); |
| 180 | 190 |
| 181 const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmaller
Size); | 191 const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmaller
Size); |
| 182 | 192 |
| 183 pixmap.erase(SK_ColorRED, subset); | 193 pixmap.erase(SK_ColorRED, subset); |
| 184 | 194 |
| 185 { | 195 { |
| 186 sk_sp<SkSpecialImage> img(SkSpecialImage::MakeFromPixmap(nullptr, subset
, pixmap, | 196 sk_sp<SkSpecialImage> img(SkSpecialImage::MakeFromPixmap(nullptr, subset
, pixmap, |
| 187 nullptr, nullpt
r)); | 197 nullptr, nullpt
r)); |
| 188 test_image(img, reporter, true, false, kPad, kFullSize); | 198 test_image(img, reporter, nullptr, false, kPad, kFullSize); |
| 189 } | 199 } |
| 190 } | 200 } |
| 191 | 201 |
| 192 | 202 |
| 193 #if SK_SUPPORT_GPU | 203 #if SK_SUPPORT_GPU |
| 194 | 204 |
| 195 static void test_texture_backed(skiatest::Reporter* reporter, | 205 static void test_texture_backed(skiatest::Reporter* reporter, |
| 196 const sk_sp<SkSpecialImage>& orig, | 206 const sk_sp<SkSpecialImage>& orig, |
| 197 const sk_sp<SkSpecialImage>& gpuBacked) { | 207 const sk_sp<SkSpecialImage>& gpuBacked) { |
| 198 REPORTER_ASSERT(reporter, gpuBacked); | 208 REPORTER_ASSERT(reporter, gpuBacked); |
| 199 REPORTER_ASSERT(reporter, gpuBacked->peekTexture()); | 209 REPORTER_ASSERT(reporter, gpuBacked->isTextureBacked()); |
| 200 REPORTER_ASSERT(reporter, gpuBacked->uniqueID() == orig->uniqueID()); | 210 REPORTER_ASSERT(reporter, gpuBacked->uniqueID() == orig->uniqueID()); |
| 201 REPORTER_ASSERT(reporter, gpuBacked->subset().width() == orig->subset().widt
h() && | 211 REPORTER_ASSERT(reporter, gpuBacked->subset().width() == orig->subset().widt
h() && |
| 202 gpuBacked->subset().height() == orig->subset().hei
ght()); | 212 gpuBacked->subset().height() == orig->subset().hei
ght()); |
| 203 } | 213 } |
| 204 | 214 |
| 205 // Test out the SkSpecialImage::makeTextureImage entry point | 215 // Test out the SkSpecialImage::makeTextureImage entry point |
| 206 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SpecialImage_MakeTexture, reporter, ctxInf
o) { | 216 DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SpecialImage_MakeTexture, reporter, ctxInf
o) { |
| 207 GrContext* context = ctxInfo.fGrContext; | 217 GrContext* context = ctxInfo.fGrContext; |
| 208 SkBitmap bm = create_bm(); | 218 SkBitmap bm = create_bm(); |
| 209 | 219 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 kNeedNewImageUniqueI
D_SpecialImage, | 300 kNeedNewImageUniqueI
D_SpecialImage, |
| 291 texture)); | 301 texture)); |
| 292 | 302 |
| 293 const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmaller
Size); | 303 const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmaller
Size); |
| 294 | 304 |
| 295 { | 305 { |
| 296 sk_sp<SkSpecialImage> subSImg1(SkSpecialImage::MakeFromGpu( | 306 sk_sp<SkSpecialImage> subSImg1(SkSpecialImage::MakeFromGpu( |
| 297 nullptr, subset, | 307 nullptr, subset, |
| 298 kNeedNewImageUniq
ueID_SpecialImage, | 308 kNeedNewImageUniq
ueID_SpecialImage, |
| 299 texture)); | 309 texture)); |
| 300 test_image(subSImg1, reporter, false, true, kPad, kFullSize); | 310 test_image(subSImg1, reporter, context, true, kPad, kFullSize); |
| 301 } | 311 } |
| 302 | 312 |
| 303 { | 313 { |
| 304 sk_sp<SkSpecialImage> subSImg2(fullSImg->makeSubset(subset)); | 314 sk_sp<SkSpecialImage> subSImg2(fullSImg->makeSubset(subset)); |
| 305 test_image(subSImg2, reporter, false, true, kPad, kFullSize); | 315 test_image(subSImg2, reporter, context, true, kPad, kFullSize); |
| 306 } | 316 } |
| 307 } | 317 } |
| 308 | 318 |
| 309 #endif | 319 #endif |
| OLD | NEW |