Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: tests/SpecialImageTest.cpp

Issue 1861643003: Upgrade SkSpecialImage to have getTextureRef & getROPixels entry points (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Really fix no-GPU build Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 ==
65 !!TestingSpecialImageAccess::PeekTexture (img.get())); 65 !!TestingSpecialImageAccess::PeekTexture (img.get()));
66 66
67 #if SK_SUPPORT_GPU
67 //-------------- 68 //--------------
68 // Test that peekPixels reports the correct backing type 69 // Test getTextureAsRef - as long as there is a context this should succeed
69 SkPixmap pixmap; 70 if (context) {
70 REPORTER_ASSERT(reporter, peekPixelsSucceeds == 71 sk_sp<GrTexture> texture(img->asTextureRef(context));
71 !!TestingSpecialImageAccess::PeekPixels(img.get(), &pixmap)); 72 REPORTER_ASSERT(reporter, texture);
72 if (peekPixelsSucceeds) {
73 REPORTER_ASSERT(reporter, size == pixmap.width());
74 REPORTER_ASSERT(reporter, size == pixmap.height());
75 } 73 }
74 #endif
75
76 //--------------
77 // Test getROPixels - this should always succeed regardless of backing store
78 SkBitmap bitmap;
79 REPORTER_ASSERT(reporter, img->getROPixels(&bitmap));
80 REPORTER_ASSERT(reporter, size == bitmap.width());
81 REPORTER_ASSERT(reporter, size == bitmap.height());
76 82
77 //-------------- 83 //--------------
78 // Test that draw restricts itself to the subset 84 // Test that draw restricts itself to the subset
79 SkImageInfo info = SkImageInfo::MakeN32(kFullSize, kFullSize, kOpaque_SkAlph aType); 85 SkImageInfo info = SkImageInfo::MakeN32(kFullSize, kFullSize, kOpaque_SkAlph aType);
80 86
81 sk_sp<SkSpecialSurface> surf(img->makeSurface(info)); 87 sk_sp<SkSpecialSurface> surf(img->makeSurface(info));
82 88
83 SkCanvas* canvas = surf->getCanvas(); 89 SkCanvas* canvas = surf->getCanvas();
84 90
85 canvas->clear(SK_ColorBLUE); 91 canvas->clear(SK_ColorBLUE);
(...skipping 17 matching lines...) Expand all
103 // Test that makeTightSubset & makeTightSurface return appropriately sized o bjects 109 // Test that makeTightSubset & makeTightSurface return appropriately sized o bjects
104 // of the correct backing type 110 // of the correct backing type
105 SkIRect newSubset = SkIRect::MakeWH(subset.width(), subset.height()); 111 SkIRect newSubset = SkIRect::MakeWH(subset.width(), subset.height());
106 { 112 {
107 sk_sp<SkImage> tightImg(img->makeTightSubset(newSubset)); 113 sk_sp<SkImage> tightImg(img->makeTightSubset(newSubset));
108 114
109 REPORTER_ASSERT(reporter, tightImg->width() == subset.width()); 115 REPORTER_ASSERT(reporter, tightImg->width() == subset.width());
110 REPORTER_ASSERT(reporter, tightImg->height() == subset.height()); 116 REPORTER_ASSERT(reporter, tightImg->height() == subset.height());
111 REPORTER_ASSERT(reporter, peekTextureSucceeds == !!tightImg->getTexture( )); 117 REPORTER_ASSERT(reporter, peekTextureSucceeds == !!tightImg->getTexture( ));
112 SkPixmap tmpPixmap; 118 SkPixmap tmpPixmap;
113 REPORTER_ASSERT(reporter, peekPixelsSucceeds == !!tightImg->peekPixels(& tmpPixmap)); 119 REPORTER_ASSERT(reporter, peekTextureSucceeds != !!tightImg->peekPixels( &tmpPixmap));
114 } 120 }
115 { 121 {
116 SkImageInfo info = SkImageInfo::MakeN32(subset.width(), subset.height(), 122 SkImageInfo info = SkImageInfo::MakeN32(subset.width(), subset.height(),
117 kPremul_SkAlphaType); 123 kPremul_SkAlphaType);
118 sk_sp<SkSurface> tightSurf(img->makeTightSurface(info)); 124 sk_sp<SkSurface> tightSurf(img->makeTightSurface(info));
119 125
120 REPORTER_ASSERT(reporter, tightSurf->width() == subset.width()); 126 REPORTER_ASSERT(reporter, tightSurf->width() == subset.width());
121 REPORTER_ASSERT(reporter, tightSurf->height() == subset.height()); 127 REPORTER_ASSERT(reporter, tightSurf->height() == subset.height());
122 REPORTER_ASSERT(reporter, peekTextureSucceeds == 128 REPORTER_ASSERT(reporter, peekTextureSucceeds ==
123 !!tightSurf->getTextureHandle(SkSurface::kDiscardWrite_Back endHandleAccess)); 129 !!tightSurf->getTextureHandle(SkSurface::kDiscardWrite_Back endHandleAccess));
124 SkPixmap tmpPixmap; 130 SkPixmap tmpPixmap;
125 REPORTER_ASSERT(reporter, peekPixelsSucceeds == !!tightSurf->peekPixels( &tmpPixmap)); 131 REPORTER_ASSERT(reporter, peekTextureSucceeds != !!tightSurf->peekPixels (&tmpPixmap));
126 } 132 }
127 } 133 }
128 134
129 DEF_TEST(SpecialImage_Raster, reporter) { 135 DEF_TEST(SpecialImage_Raster, reporter) {
130 SkBitmap bm = create_bm(); 136 SkBitmap bm = create_bm();
131 137
132 sk_sp<SkSpecialImage> fullSImage(SkSpecialImage::MakeFromRaster( 138 sk_sp<SkSpecialImage> fullSImage(SkSpecialImage::MakeFromRaster(
133 nullptr, 139 nullptr,
134 SkIRect::MakeWH(kFul lSize, kFullSize), 140 SkIRect::MakeWH(kFul lSize, kFullSize),
135 bm)); 141 bm));
136 142
137 const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmaller Size); 143 const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmaller Size);
138 144
139 { 145 {
140 sk_sp<SkSpecialImage> subSImg1(SkSpecialImage::MakeFromRaster(nullptr, s ubset, bm)); 146 sk_sp<SkSpecialImage> subSImg1(SkSpecialImage::MakeFromRaster(nullptr, s ubset, bm));
141 test_image(subSImg1, reporter, true, false, kPad, kFullSize); 147 test_image(subSImg1, reporter, nullptr, false, kPad, kFullSize);
142 } 148 }
143 149
144 { 150 {
145 sk_sp<SkSpecialImage> subSImg2(fullSImage->makeSubset(subset)); 151 sk_sp<SkSpecialImage> subSImg2(fullSImage->makeSubset(subset));
146 test_image(subSImg2, reporter, true, false, 0, kSmallerSize); 152 test_image(subSImg2, reporter, nullptr, false, 0, kSmallerSize);
147 } 153 }
148 } 154 }
149 155
150 DEF_TEST(SpecialImage_Image, reporter) { 156 DEF_TEST(SpecialImage_Image, reporter) {
151 SkBitmap bm = create_bm(); 157 SkBitmap bm = create_bm();
152 158
153 sk_sp<SkImage> fullImage(SkImage::MakeFromBitmap(bm)); 159 sk_sp<SkImage> fullImage(SkImage::MakeFromBitmap(bm));
154 160
155 sk_sp<SkSpecialImage> fullSImage(SkSpecialImage::MakeFromImage( 161 sk_sp<SkSpecialImage> fullSImage(SkSpecialImage::MakeFromImage(
156 nullptr, 162 nullptr,
157 SkIRect::MakeWH(kFul lSize, kFullSize), 163 SkIRect::MakeWH(kFul lSize, kFullSize),
158 fullImage)); 164 fullImage));
159 165
160 const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmaller Size); 166 const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmaller Size);
161 167
162 { 168 {
163 sk_sp<SkSpecialImage> subSImg1(SkSpecialImage::MakeFromImage(nullptr, su bset, 169 sk_sp<SkSpecialImage> subSImg1(SkSpecialImage::MakeFromImage(nullptr, su bset,
164 fullImage)) ; 170 fullImage)) ;
165 test_image(subSImg1, reporter, true, false, kPad, kFullSize); 171 test_image(subSImg1, reporter, nullptr, false, kPad, kFullSize);
166 } 172 }
167 173
168 { 174 {
169 sk_sp<SkSpecialImage> subSImg2(fullSImage->makeSubset(subset)); 175 sk_sp<SkSpecialImage> subSImg2(fullSImage->makeSubset(subset));
170 test_image(subSImg2, reporter, true, false, 0, kSmallerSize); 176 test_image(subSImg2, reporter, nullptr, false, 0, kSmallerSize);
171 } 177 }
172 } 178 }
173 179
174 DEF_TEST(SpecialImage_Pixmap, reporter) { 180 DEF_TEST(SpecialImage_Pixmap, reporter) {
175 SkAutoPixmapStorage pixmap; 181 SkAutoPixmapStorage pixmap;
176 182
177 const SkImageInfo info = SkImageInfo::MakeN32(kFullSize, kFullSize, kOpaque_ SkAlphaType); 183 const SkImageInfo info = SkImageInfo::MakeN32(kFullSize, kFullSize, kOpaque_ SkAlphaType);
178 pixmap.alloc(info); 184 pixmap.alloc(info);
179 pixmap.erase(SK_ColorGREEN); 185 pixmap.erase(SK_ColorGREEN);
180 186
181 const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmaller Size); 187 const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmaller Size);
182 188
183 pixmap.erase(SK_ColorRED, subset); 189 pixmap.erase(SK_ColorRED, subset);
184 190
185 { 191 {
186 sk_sp<SkSpecialImage> img(SkSpecialImage::MakeFromPixmap(nullptr, subset , pixmap, 192 sk_sp<SkSpecialImage> img(SkSpecialImage::MakeFromPixmap(nullptr, subset , pixmap,
187 nullptr, nullpt r)); 193 nullptr, nullpt r));
188 test_image(img, reporter, true, false, kPad, kFullSize); 194 test_image(img, reporter, nullptr, false, kPad, kFullSize);
189 } 195 }
190 } 196 }
191 197
192 198
193 #if SK_SUPPORT_GPU 199 #if SK_SUPPORT_GPU
194 200
195 static void test_texture_backed(skiatest::Reporter* reporter, 201 static void test_texture_backed(skiatest::Reporter* reporter,
196 const sk_sp<SkSpecialImage>& orig, 202 const sk_sp<SkSpecialImage>& orig,
197 const sk_sp<SkSpecialImage>& gpuBacked) { 203 const sk_sp<SkSpecialImage>& gpuBacked) {
198 REPORTER_ASSERT(reporter, gpuBacked); 204 REPORTER_ASSERT(reporter, gpuBacked);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 kNeedNewImageUniqueI D_SpecialImage, 296 kNeedNewImageUniqueI D_SpecialImage,
291 texture)); 297 texture));
292 298
293 const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmaller Size); 299 const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmaller Size);
294 300
295 { 301 {
296 sk_sp<SkSpecialImage> subSImg1(SkSpecialImage::MakeFromGpu( 302 sk_sp<SkSpecialImage> subSImg1(SkSpecialImage::MakeFromGpu(
297 nullptr, subset, 303 nullptr, subset,
298 kNeedNewImageUniq ueID_SpecialImage, 304 kNeedNewImageUniq ueID_SpecialImage,
299 texture)); 305 texture));
300 test_image(subSImg1, reporter, false, true, kPad, kFullSize); 306 test_image(subSImg1, reporter, context, true, kPad, kFullSize);
301 } 307 }
302 308
303 { 309 {
304 sk_sp<SkSpecialImage> subSImg2(fullSImg->makeSubset(subset)); 310 sk_sp<SkSpecialImage> subSImg2(fullSImg->makeSubset(subset));
305 test_image(subSImg2, reporter, false, true, kPad, kFullSize); 311 test_image(subSImg2, reporter, context, true, kPad, kFullSize);
306 } 312 }
307 } 313 }
308 314
309 #endif 315 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698