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

Side by Side Diff: tests/SpecialImageTest.cpp

Issue 1787883002: Add SkSpecialImage::extractSubset & NewFromPixmap (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Update to ToT Created 4 years, 9 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
« no previous file with comments | « tests/ImageTest.cpp ('k') | tests/TestingSpecialImageAccess.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "SkBitmap.h" 9 #include "SkBitmap.h"
9 #include "SkCanvas.h" 10 #include "SkCanvas.h"
10 #include "SkImage.h" 11 #include "SkImage.h"
12 #include "SkPixmap.h"
11 #include "SkSpecialImage.h" 13 #include "SkSpecialImage.h"
12 #include "SkSpecialSurface.h" 14 #include "SkSpecialSurface.h"
13 #include "Test.h" 15 #include "Test.h"
14 #include "TestingSpecialImageAccess.h" 16 #include "TestingSpecialImageAccess.h"
15 17
16 #if SK_SUPPORT_GPU 18 #if SK_SUPPORT_GPU
17 #include "GrContext.h" 19 #include "GrContext.h"
18 #endif 20 #endif
19 21
20 22
(...skipping 20 matching lines...) Expand all
41 43
42 temp.drawRect(SkRect::MakeXYWH(SkIntToScalar(kPad), SkIntToScalar(kPad), 44 temp.drawRect(SkRect::MakeXYWH(SkIntToScalar(kPad), SkIntToScalar(kPad),
43 SkIntToScalar(kSmallerSize), SkIntToScalar(kS mallerSize)), 45 SkIntToScalar(kSmallerSize), SkIntToScalar(kS mallerSize)),
44 p); 46 p);
45 47
46 return bm; 48 return bm;
47 } 49 }
48 50
49 // Basic test of the SkSpecialImage public API (e.g., peekTexture, peekPixels & draw) 51 // Basic test of the SkSpecialImage public API (e.g., peekTexture, peekPixels & draw)
50 static void test_image(SkSpecialImage* img, skiatest::Reporter* reporter, 52 static void test_image(SkSpecialImage* img, skiatest::Reporter* reporter,
51 bool peekPixelsSucceeds, bool peekTextureSucceeds) { 53 bool peekPixelsSucceeds, bool peekTextureSucceeds,
54 int offset, int size) {
52 const SkIRect subset = TestingSpecialImageAccess::Subset(img); 55 const SkIRect subset = TestingSpecialImageAccess::Subset(img);
53 REPORTER_ASSERT(reporter, kPad == subset.left()); 56 REPORTER_ASSERT(reporter, offset == subset.left());
54 REPORTER_ASSERT(reporter, kPad == subset.top()); 57 REPORTER_ASSERT(reporter, offset == subset.top());
55 REPORTER_ASSERT(reporter, kSmallerSize == subset.width()); 58 REPORTER_ASSERT(reporter, kSmallerSize == subset.width());
56 REPORTER_ASSERT(reporter, kSmallerSize == subset.height()); 59 REPORTER_ASSERT(reporter, kSmallerSize == subset.height());
57 60
58 //-------------- 61 //--------------
59 REPORTER_ASSERT(reporter, peekTextureSucceeds == !!TestingSpecialImageAccess ::PeekTexture(img)); 62 REPORTER_ASSERT(reporter, peekTextureSucceeds == !!TestingSpecialImageAccess ::PeekTexture(img));
60 63
61 //-------------- 64 //--------------
62 SkPixmap pixmap; 65 SkPixmap pixmap;
63 REPORTER_ASSERT(reporter, peekPixelsSucceeds == 66 REPORTER_ASSERT(reporter, peekPixelsSucceeds ==
64 !!TestingSpecialImageAccess::PeekPixels(img, &pixm ap)); 67 !!TestingSpecialImageAccess::PeekPixels(img, &pixm ap));
65 if (peekPixelsSucceeds) { 68 if (peekPixelsSucceeds) {
66 REPORTER_ASSERT(reporter, kFullSize == pixmap.width()); 69 REPORTER_ASSERT(reporter, size == pixmap.width());
67 REPORTER_ASSERT(reporter, kFullSize == pixmap.height()); 70 REPORTER_ASSERT(reporter, size == pixmap.height());
68 } 71 }
69 72
70 //-------------- 73 //--------------
71 SkImageInfo info = SkImageInfo::MakeN32(kFullSize, kFullSize, kOpaque_SkAlph aType); 74 SkImageInfo info = SkImageInfo::MakeN32(kFullSize, kFullSize, kOpaque_SkAlph aType);
72 75
73 SkAutoTUnref<SkSpecialSurface> surf(img->newSurface(info)); 76 SkAutoTUnref<SkSpecialSurface> surf(img->newSurface(info));
74 77
75 SkCanvas* canvas = surf->getCanvas(); 78 SkCanvas* canvas = surf->getCanvas();
76 79
77 canvas->clear(SK_ColorBLUE); 80 canvas->clear(SK_ColorBLUE);
(...skipping 10 matching lines...) Expand all
88 REPORTER_ASSERT(reporter, SK_ColorRED == bm.getColor(kPad, kPad)); 91 REPORTER_ASSERT(reporter, SK_ColorRED == bm.getColor(kPad, kPad));
89 REPORTER_ASSERT(reporter, SK_ColorRED == bm.getColor(kSmallerSize+kPad-1, 92 REPORTER_ASSERT(reporter, SK_ColorRED == bm.getColor(kSmallerSize+kPad-1,
90 kSmallerSize+kPad-1)); 93 kSmallerSize+kPad-1));
91 REPORTER_ASSERT(reporter, SK_ColorBLUE == bm.getColor(kSmallerSize+kPad, 94 REPORTER_ASSERT(reporter, SK_ColorBLUE == bm.getColor(kSmallerSize+kPad,
92 kSmallerSize+kPad)); 95 kSmallerSize+kPad));
93 } 96 }
94 97
95 DEF_TEST(SpecialImage_Raster, reporter) { 98 DEF_TEST(SpecialImage_Raster, reporter) {
96 SkBitmap bm = create_bm(); 99 SkBitmap bm = create_bm();
97 100
101 SkAutoTUnref<SkSpecialImage> fullSImage(SkSpecialImage::NewFromRaster(
102 nullptr,
103 SkIRect::MakeWH(kFul lSize, kFullSize),
104 bm));
105
98 const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmaller Size); 106 const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmaller Size);
99 107
100 SkAutoTUnref<SkSpecialImage> img(SkSpecialImage::NewFromRaster(nullptr, subs et, bm)); 108 {
101 test_image(img, reporter, true, false); 109 SkAutoTUnref<SkSpecialImage> subSImg1(SkSpecialImage::NewFromRaster(null ptr, subset, bm));
110 test_image(subSImg1, reporter, true, false, kPad, kFullSize);
111 }
112
113 {
114 SkAutoTUnref<SkSpecialImage> subSImg2(fullSImage->extractSubset(subset)) ;
115 test_image(subSImg2, reporter, true, false, 0, kSmallerSize);
116 }
102 } 117 }
103 118
104 DEF_TEST(SpecialImage_Image, reporter) { 119 DEF_TEST(SpecialImage_Image, reporter) {
105 SkBitmap bm = create_bm(); 120 SkBitmap bm = create_bm();
106 121
107 SkAutoTUnref<SkImage> fullImage(SkImage::NewFromBitmap(bm)); 122 SkAutoTUnref<SkImage> fullImage(SkImage::NewFromBitmap(bm));
108 123
124 SkAutoTUnref<SkSpecialImage> fullSImage(SkSpecialImage::NewFromImage(
125 nullptr,
126 SkIRect::MakeWH(kFul lSize, kFullSize),
127 fullImage));
128
109 const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmaller Size); 129 const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmaller Size);
110 130
111 SkAutoTUnref<SkSpecialImage> img(SkSpecialImage::NewFromImage(nullptr, subse t, fullImage)); 131 {
112 test_image(img, reporter, true, false); 132 SkAutoTUnref<SkSpecialImage> subSImg1(SkSpecialImage::NewFromImage(nullp tr,
133 subse t,
134 fullI mage));
135 test_image(subSImg1, reporter, true, false, kPad, kFullSize);
136 }
137
138 {
139 SkAutoTUnref<SkSpecialImage> subSImg2(fullSImage->extractSubset(subset)) ;
140 test_image(subSImg2, reporter, true, false, 0, kSmallerSize);
141 }
113 } 142 }
114 143
144 DEF_TEST(SpecialImage_Pixmap, reporter) {
145 SkAutoPixmapStorage pixmap;
146
147 const SkImageInfo info = SkImageInfo::MakeN32(kFullSize, kFullSize, kOpaque_ SkAlphaType);
148 pixmap.alloc(info);
149 pixmap.erase(SK_ColorGREEN);
150
151 const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmaller Size);
152
153 pixmap.erase(SK_ColorRED, subset);
154
155 {
156 // The SkAutoPixmapStorage keeps hold of the memory
157 SkAutoTUnref<SkSpecialImage> img(SkSpecialImage::NewFromPixmap(nullptr, subset, pixmap,
158 nullptr, nullptr));
159 test_image(img, reporter, true, false, kPad, kFullSize);
160 }
161
162 {
163 // The image takes ownership of the memory
164 SkAutoTUnref<SkSpecialImage> img(SkSpecialImage::NewFromPixmap(
165 nullptr, subset, pixmap,
166 [] (void* addr, void*) -> void { sk_free(addr); },
167 nullptr));
168 pixmap.release();
169 test_image(img, reporter, true, false, kPad, kFullSize);
170 }
171 }
172
173
115 #if SK_SUPPORT_GPU 174 #if SK_SUPPORT_GPU
116 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialImage_Gpu, reporter, context) { 175 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialImage_Gpu, reporter, context) {
117 SkBitmap bm = create_bm(); 176 SkBitmap bm = create_bm();
118 177
119 GrSurfaceDesc desc; 178 GrSurfaceDesc desc;
120 desc.fConfig = kSkia8888_GrPixelConfig; 179 desc.fConfig = kSkia8888_GrPixelConfig;
121 desc.fFlags = kNone_GrSurfaceFlags; 180 desc.fFlags = kNone_GrSurfaceFlags;
122 desc.fWidth = kFullSize; 181 desc.fWidth = kFullSize;
123 desc.fHeight = kFullSize; 182 desc.fHeight = kFullSize;
124 183
125 SkAutoTUnref<GrTexture> texture(context->textureProvider()->createTexture(de sc, SkBudgeted::kNo, 184 SkAutoTUnref<GrTexture> texture(context->textureProvider()->createTexture(de sc, SkBudgeted::kNo,
126 bm .getPixels(), 0)); 185 bm .getPixels(), 0));
127 if (!texture) { 186 if (!texture) {
128 return; 187 return;
129 } 188 }
130 189
190 SkAutoTUnref<SkSpecialImage> fullSImg(SkSpecialImage::NewFromGpu(
191 nullptr,
192 SkIRect::MakeWH(kFul lSize, kFullSize),
193 kNeedNewImageUniqueI D_SpecialImage,
194 texture));
195
131 const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmaller Size); 196 const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmaller Size);
132 197
133 SkAutoTUnref<SkSpecialImage> img(SkSpecialImage::NewFromGpu(nullptr, subset, 198 {
134 kNeedNewImageUni queID_SpecialImage, 199 SkAutoTUnref<SkSpecialImage> subSImg1(SkSpecialImage::NewFromGpu(
135 texture)); 200 nullptr, subset,
136 test_image(img, reporter, false, true); 201 kNeedNewImageUniq ueID_SpecialImage,
202 texture));
203 test_image(subSImg1, reporter, false, true, kPad, kFullSize);
204 }
205
206 {
207 SkAutoTUnref<SkSpecialImage> subSImg2(fullSImg->extractSubset(subset));
208 test_image(subSImg2, reporter, false, true, kPad, kFullSize);
209 }
137 } 210 }
138 211
139 #endif 212 #endif
OLDNEW
« no previous file with comments | « tests/ImageTest.cpp ('k') | tests/TestingSpecialImageAccess.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698