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

Side by Side Diff: tests/SurfaceTest.cpp

Issue 1860593002: One signature for creating unit tests that run on premade GrContexts (Closed) Base URL: https://skia.googlesource.com/skia.git@try_no_native
Patch Set: another guess to fix windows 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
« no previous file with comments | « tests/SpecialSurfaceTest.cpp ('k') | tests/TessellatingPathRendererTests.cpp » ('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 2013 Google Inc. 2 * Copyright 2013 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 <functional> 8 #include <functional>
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkData.h" 10 #include "SkData.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 } 67 }
68 #endif 68 #endif
69 69
70 DEF_TEST(SurfaceEmpty, reporter) { 70 DEF_TEST(SurfaceEmpty, reporter) {
71 const SkImageInfo info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_S kAlphaType); 71 const SkImageInfo info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_S kAlphaType);
72 REPORTER_ASSERT(reporter, nullptr == SkSurface::MakeRaster(info)); 72 REPORTER_ASSERT(reporter, nullptr == SkSurface::MakeRaster(info));
73 REPORTER_ASSERT(reporter, nullptr == SkSurface::MakeRasterDirect(info, nullp tr, 0)); 73 REPORTER_ASSERT(reporter, nullptr == SkSurface::MakeRasterDirect(info, nullp tr, 0));
74 74
75 } 75 }
76 #if SK_SUPPORT_GPU 76 #if SK_SUPPORT_GPU
77 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceEmpty_Gpu, reporter, context) { 77 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceEmpty_Gpu, reporter, ctxInfo) {
78 const SkImageInfo info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_S kAlphaType); 78 const SkImageInfo info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_S kAlphaType);
79 REPORTER_ASSERT(reporter, nullptr == 79 REPORTER_ASSERT(reporter, nullptr ==
80 SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info, 0, nullptr)); 80 SkSurface::MakeRenderTarget(ctxInfo.fGrContext, SkBudgeted:: kNo, info, 0,
81 nullptr));
81 } 82 }
82 #endif 83 #endif
83 84
84 #if SK_SUPPORT_GPU 85 #if SK_SUPPORT_GPU
85 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceWrappedTexture, reporter, context) { 86 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceWrappedTexture, reporter, ctxInfo) {
86 GrGpu* gpu = context->getGpu(); 87 GrGpu* gpu = ctxInfo.fGrContext->getGpu();
87 if (!gpu) { 88 if (!gpu) {
88 return; 89 return;
89 } 90 }
90 91
91 // Test the wrapped factory for SkSurface by creating a backend texture and then wrap it in 92 // Test the wrapped factory for SkSurface by creating a backend texture and then wrap it in
92 // a SkSurface. 93 // a SkSurface.
93 static const int kW = 100; 94 static const int kW = 100;
94 static const int kH = 100; 95 static const int kH = 100;
95 static const uint32_t kOrigColor = 0xFFAABBCC; 96 static const uint32_t kOrigColor = 0xFFAABBCC;
96 SkAutoTArray<uint32_t> pixels(kW * kH); 97 SkAutoTArray<uint32_t> pixels(kW * kH);
97 sk_memset32(pixels.get(), kOrigColor, kW * kH); 98 sk_memset32(pixels.get(), kOrigColor, kW * kH);
98 GrBackendObject texHandle = gpu->createTestingOnlyBackendTexture(pixels.get( ), kW, kH, 99 GrBackendObject texHandle = gpu->createTestingOnlyBackendTexture(pixels.get( ), kW, kH,
99 kRGBA_8888_ GrPixelConfig); 100 kRGBA_8888_ GrPixelConfig);
100 101
101 GrBackendTextureDesc wrappedDesc; 102 GrBackendTextureDesc wrappedDesc;
102 wrappedDesc.fConfig = kRGBA_8888_GrPixelConfig; 103 wrappedDesc.fConfig = kRGBA_8888_GrPixelConfig;
103 wrappedDesc.fWidth = kW; 104 wrappedDesc.fWidth = kW;
104 wrappedDesc.fHeight = kH; 105 wrappedDesc.fHeight = kH;
105 wrappedDesc.fOrigin = kBottomLeft_GrSurfaceOrigin; 106 wrappedDesc.fOrigin = kBottomLeft_GrSurfaceOrigin;
106 wrappedDesc.fSampleCnt = 0; 107 wrappedDesc.fSampleCnt = 0;
107 wrappedDesc.fFlags = kRenderTarget_GrBackendTextureFlag; 108 wrappedDesc.fFlags = kRenderTarget_GrBackendTextureFlag;
108 wrappedDesc.fTextureHandle = texHandle; 109 wrappedDesc.fTextureHandle = texHandle;
109 110
110 auto surface(SkSurface::MakeFromBackendTexture(context, wrappedDesc, nullptr )); 111 auto surface(SkSurface::MakeFromBackendTexture(ctxInfo.fGrContext, wrappedDe sc, nullptr));
111 REPORTER_ASSERT(reporter, surface); 112 REPORTER_ASSERT(reporter, surface);
112 if (surface) { 113 if (surface) {
113 // Validate that we can draw to the canvas and that the original texture color is preserved 114 // Validate that we can draw to the canvas and that the original texture color is preserved
114 // in pixels that aren't rendered to via the surface. 115 // in pixels that aren't rendered to via the surface.
115 SkPaint paint; 116 SkPaint paint;
116 static const SkColor kRectColor = ~kOrigColor | 0xFF000000; 117 static const SkColor kRectColor = ~kOrigColor | 0xFF000000;
117 paint.setColor(kRectColor); 118 paint.setColor(kRectColor);
118 surface->getCanvas()->drawRect(SkRect::MakeWH(SkIntToScalar(kW), SkIntTo Scalar(kH)/2), 119 surface->getCanvas()->drawRect(SkRect::MakeWH(SkIntToScalar(kW), SkIntTo Scalar(kH)/2),
119 paint); 120 paint);
120 SkImageInfo readInfo = SkImageInfo::MakeN32Premul(kW, kH); 121 SkImageInfo readInfo = SkImageInfo::MakeN32Premul(kW, kH);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 } 179 }
179 } 180 }
180 DEF_TEST(SurfaceCanvasPeek, reporter) { 181 DEF_TEST(SurfaceCanvasPeek, reporter) {
181 for (auto& surface_func : { &create_surface, &create_direct_surface }) { 182 for (auto& surface_func : { &create_surface, &create_direct_surface }) {
182 SkImageInfo requestInfo; 183 SkImageInfo requestInfo;
183 auto surface(surface_func(kPremul_SkAlphaType, &requestInfo)); 184 auto surface(surface_func(kPremul_SkAlphaType, &requestInfo));
184 test_canvas_peek(reporter, surface, requestInfo, true); 185 test_canvas_peek(reporter, surface, requestInfo, true);
185 } 186 }
186 } 187 }
187 #if SK_SUPPORT_GPU 188 #if SK_SUPPORT_GPU
188 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCanvasPeek_Gpu, reporter, context) { 189 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCanvasPeek_Gpu, reporter, ctxInfo) {
189 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) { 190 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
190 SkImageInfo requestInfo; 191 SkImageInfo requestInfo;
191 auto surface(surface_func(context, kPremul_SkAlphaType, &requestInfo)); 192 auto surface(surface_func(ctxInfo.fGrContext, kPremul_SkAlphaType, &requ estInfo));
192 test_canvas_peek(reporter, surface, requestInfo, false); 193 test_canvas_peek(reporter, surface, requestInfo, false);
193 } 194 }
194 } 195 }
195 #endif 196 #endif
196 197
197 // For compatibility with clients that still call accessBitmap(), we need to ens ure that we bump 198 // For compatibility with clients that still call accessBitmap(), we need to ens ure that we bump
198 // the bitmap's genID when we draw to it, else they won't know it has new values . When they are 199 // the bitmap's genID when we draw to it, else they won't know it has new values . When they are
199 // exclusively using surface/image, and we can hide accessBitmap from device, we can remove this 200 // exclusively using surface/image, and we can hide accessBitmap from device, we can remove this
200 // test. 201 // test.
201 void test_access_pixels(skiatest::Reporter* reporter, const sk_sp<SkSurface>& su rface) { 202 void test_access_pixels(skiatest::Reporter* reporter, const sk_sp<SkSurface>& su rface) {
202 SkCanvas* canvas = surface->getCanvas(); 203 SkCanvas* canvas = surface->getCanvas();
203 canvas->clear(0); 204 canvas->clear(0);
204 205
205 SkBaseDevice* device = canvas->getDevice_just_for_deprecated_compatibility_t esting(); 206 SkBaseDevice* device = canvas->getDevice_just_for_deprecated_compatibility_t esting();
206 SkBitmap bm = device->accessBitmap(false); 207 SkBitmap bm = device->accessBitmap(false);
207 uint32_t genID0 = bm.getGenerationID(); 208 uint32_t genID0 = bm.getGenerationID();
208 // Now we draw something, which needs to "dirty" the genID (sorta like copy- on-write) 209 // Now we draw something, which needs to "dirty" the genID (sorta like copy- on-write)
209 canvas->drawColor(SK_ColorBLUE); 210 canvas->drawColor(SK_ColorBLUE);
210 // Now check that we get a different genID 211 // Now check that we get a different genID
211 uint32_t genID1 = bm.getGenerationID(); 212 uint32_t genID1 = bm.getGenerationID();
212 REPORTER_ASSERT(reporter, genID0 != genID1); 213 REPORTER_ASSERT(reporter, genID0 != genID1);
213 } 214 }
214 DEF_TEST(SurfaceAccessPixels, reporter) { 215 DEF_TEST(SurfaceAccessPixels, reporter) {
215 for (auto& surface_func : { &create_surface, &create_direct_surface }) { 216 for (auto& surface_func : { &create_surface, &create_direct_surface }) {
216 auto surface(surface_func(kPremul_SkAlphaType, nullptr)); 217 auto surface(surface_func(kPremul_SkAlphaType, nullptr));
217 test_access_pixels(reporter, surface); 218 test_access_pixels(reporter, surface);
218 } 219 }
219 } 220 }
220 #if SK_SUPPORT_GPU 221 #if SK_SUPPORT_GPU
221 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceAccessPixels_Gpu, reporter, context) { 222 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceAccessPixels_Gpu, reporter, ctxInfo) {
222 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) { 223 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
223 auto surface(surface_func(context, kPremul_SkAlphaType, nullptr)); 224 auto surface(surface_func(ctxInfo.fGrContext, kPremul_SkAlphaType, nullp tr));
224 test_access_pixels(reporter, surface); 225 test_access_pixels(reporter, surface);
225 } 226 }
226 } 227 }
227 #endif 228 #endif
228 229
229 static void test_snapshot_alphatype(skiatest::Reporter* reporter, const sk_sp<Sk Surface>& surface, 230 static void test_snapshot_alphatype(skiatest::Reporter* reporter, const sk_sp<Sk Surface>& surface,
230 bool expectOpaque) { 231 bool expectOpaque) {
231 REPORTER_ASSERT(reporter, surface); 232 REPORTER_ASSERT(reporter, surface);
232 if (surface) { 233 if (surface) {
233 sk_sp<SkImage> image(surface->makeImageSnapshot()); 234 sk_sp<SkImage> image(surface->makeImageSnapshot());
234 REPORTER_ASSERT(reporter, image); 235 REPORTER_ASSERT(reporter, image);
235 if (image) { 236 if (image) {
236 REPORTER_ASSERT(reporter, image->isOpaque() == SkToBool(expectOpaque )); 237 REPORTER_ASSERT(reporter, image->isOpaque() == SkToBool(expectOpaque ));
237 } 238 }
238 } 239 }
239 } 240 }
240 DEF_TEST(SurfaceSnapshotAlphaType, reporter) { 241 DEF_TEST(SurfaceSnapshotAlphaType, reporter) {
241 for (auto& surface_func : { &create_surface, &create_direct_surface }) { 242 for (auto& surface_func : { &create_surface, &create_direct_surface }) {
242 for (auto& isOpaque : { true, false }) { 243 for (auto& isOpaque : { true, false }) {
243 SkAlphaType alphaType = isOpaque ? kOpaque_SkAlphaType : kPremul_SkA lphaType; 244 SkAlphaType alphaType = isOpaque ? kOpaque_SkAlphaType : kPremul_SkA lphaType;
244 auto surface(surface_func(alphaType, nullptr)); 245 auto surface(surface_func(alphaType, nullptr));
245 test_snapshot_alphatype(reporter, surface, isOpaque); 246 test_snapshot_alphatype(reporter, surface, isOpaque);
246 } 247 }
247 } 248 }
248 } 249 }
249 #if SK_SUPPORT_GPU 250 #if SK_SUPPORT_GPU
250 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceSnapshotAlphaType_Gpu, reporter, conte xt) { 251 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceSnapshotAlphaType_Gpu, reporter, ctxIn fo) {
251 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) { 252 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
252 for (auto& isOpaque : { true, false }) { 253 for (auto& isOpaque : { true, false }) {
253 SkAlphaType alphaType = isOpaque ? kOpaque_SkAlphaType : kPremul_SkA lphaType; 254 SkAlphaType alphaType = isOpaque ? kOpaque_SkAlphaType : kPremul_SkA lphaType;
254 auto surface(surface_func(context, alphaType, nullptr)); 255 auto surface(surface_func(ctxInfo.fGrContext, alphaType, nullptr));
255 test_snapshot_alphatype(reporter, surface, isOpaque); 256 test_snapshot_alphatype(reporter, surface, isOpaque);
256 } 257 }
257 } 258 }
258 } 259 }
259 #endif 260 #endif
260 261
261 static GrBackendObject get_surface_backend_texture_handle( 262 static GrBackendObject get_surface_backend_texture_handle(
262 SkSurface* s, SkSurface::BackendHandleAccess a) { 263 SkSurface* s, SkSurface::BackendHandleAccess a) {
263 return s->getTextureHandle(a); 264 return s->getTextureHandle(a);
264 } 265 }
(...skipping 27 matching lines...) Expand all
292 for (auto& handle_access_func : 293 for (auto& handle_access_func :
293 { &get_surface_backend_texture_handle, &get_surface_backend_render_t arget_handle }) { 294 { &get_surface_backend_texture_handle, &get_surface_backend_render_t arget_handle }) {
294 for (auto& accessMode : accessModes) { 295 for (auto& accessMode : accessModes) {
295 auto surface(create_surface()); 296 auto surface(create_surface());
296 test_backend_handle_access_copy_on_write(reporter, surface.get(), ac cessMode, 297 test_backend_handle_access_copy_on_write(reporter, surface.get(), ac cessMode,
297 handle_access_func); 298 handle_access_func);
298 } 299 }
299 } 300 }
300 } 301 }
301 #if SK_SUPPORT_GPU 302 #if SK_SUPPORT_GPU
302 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceBackendHandleAccessCopyOnWrite_Gpu, re porter, context) { 303 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceBackendHandleAccessCopyOnWrite_Gpu, re porter, ctxInfo) {
303 const SkSurface::BackendHandleAccess accessModes[] = { 304 const SkSurface::BackendHandleAccess accessModes[] = {
304 SkSurface::kFlushRead_BackendHandleAccess, 305 SkSurface::kFlushRead_BackendHandleAccess,
305 SkSurface::kFlushWrite_BackendHandleAccess, 306 SkSurface::kFlushWrite_BackendHandleAccess,
306 SkSurface::kDiscardWrite_BackendHandleAccess, 307 SkSurface::kDiscardWrite_BackendHandleAccess,
307 }; 308 };
308 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) { 309 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
309 for (auto& handle_access_func : 310 for (auto& handle_access_func :
310 { &get_surface_backend_texture_handle, &get_surface_backend_rend er_target_handle }) { 311 { &get_surface_backend_texture_handle, &get_surface_backend_rend er_target_handle }) {
311 for (auto& accessMode : accessModes) { 312 for (auto& accessMode : accessModes) {
312 auto surface(surface_func(context, kPremul_SkAlphaType, nullptr) ); 313 auto surface(surface_func(ctxInfo.fGrContext, kPremul_SkAlphaTyp e, nullptr));
313 test_backend_handle_access_copy_on_write(reporter, surface.get() , accessMode, 314 test_backend_handle_access_copy_on_write(reporter, surface.get() , accessMode,
314 handle_access_func); 315 handle_access_func);
315 } 316 }
316 } 317 }
317 } 318 }
318 } 319 }
319 #endif 320 #endif
320 321
321 static bool same_image(SkImage* a, SkImage* b, 322 static bool same_image(SkImage* a, SkImage* b,
322 std::function<intptr_t(SkImage*)> getImageBackingStore) { 323 std::function<intptr_t(SkImage*)> getImageBackingStore) {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 391
391 auto surface(create_surface()); 392 auto surface(create_surface());
392 test_unique_image_snap(reporter, surface.get(), false, getImageBackingStore, 393 test_unique_image_snap(reporter, surface.get(), false, getImageBackingStore,
393 getSufaceBackingStore); 394 getSufaceBackingStore);
394 surface = create_direct_surface(); 395 surface = create_direct_surface();
395 test_unique_image_snap(reporter, surface.get(), true, getImageBackingStore, 396 test_unique_image_snap(reporter, surface.get(), true, getImageBackingStore,
396 getSufaceBackingStore); 397 getSufaceBackingStore);
397 } 398 }
398 399
399 #if SK_SUPPORT_GPU 400 #if SK_SUPPORT_GPU
400 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(UniqueImageSnapshot_Gpu, reporter, context) { 401 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(UniqueImageSnapshot_Gpu, reporter, ctxInfo) {
402 GrContext* context = ctxInfo.fGrContext;
401 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) { 403 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
402 auto surface(surface_func(context, kOpaque_SkAlphaType, nullptr)); 404 auto surface(surface_func(context, kOpaque_SkAlphaType, nullptr));
403 405
404 auto imageBackingStore = [reporter](SkImage* image) { 406 auto imageBackingStore = [reporter](SkImage* image) {
405 GrTexture* texture = as_IB(image)->peekTexture(); 407 GrTexture* texture = as_IB(image)->peekTexture();
406 if (!texture) { 408 if (!texture) {
407 ERRORF(reporter, "Not texture backed."); 409 ERRORF(reporter, "Not texture backed.");
408 return static_cast<intptr_t>(0); 410 return static_cast<intptr_t>(0);
409 } 411 }
410 return static_cast<intptr_t>(texture->getUniqueID()); 412 return static_cast<intptr_t>(texture->getUniqueID());
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 REPORTER_ASSERT(reporter, image0->uniqueID() != image2->uniqueID()); 494 REPORTER_ASSERT(reporter, image0->uniqueID() != image2->uniqueID());
493 495
494 obj = func(surface, SkSurface::kDiscardWrite_BackendHandleAccess); 496 obj = func(surface, SkSurface::kDiscardWrite_BackendHandleAccess);
495 REPORTER_ASSERT(reporter, obj != 0); 497 REPORTER_ASSERT(reporter, obj != 0);
496 sk_sp<SkImage> image3(surface->makeImageSnapshot()); 498 sk_sp<SkImage> image3(surface->makeImageSnapshot());
497 // expect a new(er) image, since we claimed we would write 499 // expect a new(er) image, since we claimed we would write
498 REPORTER_ASSERT(reporter, image0->uniqueID() != image3->uniqueID()); 500 REPORTER_ASSERT(reporter, image0->uniqueID() != image3->uniqueID());
499 REPORTER_ASSERT(reporter, image2->uniqueID() != image3->uniqueID()); 501 REPORTER_ASSERT(reporter, image2->uniqueID() != image3->uniqueID());
500 } 502 }
501 // No CPU test. 503 // No CPU test.
502 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceBackendHandleAccessIDs_Gpu, reporter, context) { 504 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceBackendHandleAccessIDs_Gpu, reporter, ctxInfo) {
503 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) { 505 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
504 for (auto& test_func : { &test_backend_handle_unique_id, &test_backend_h andle_gen_id }) { 506 for (auto& test_func : { &test_backend_handle_unique_id, &test_backend_h andle_gen_id }) {
505 for (auto& handle_access_func : 507 for (auto& handle_access_func :
506 { &get_surface_backend_texture_handle, &get_surface_backend_rend er_target_handle}) { 508 { &get_surface_backend_texture_handle, &get_surface_backend_rend er_target_handle}) {
507 auto surface(surface_func(context, kPremul_SkAlphaType, nullptr) ); 509 auto surface(surface_func(ctxInfo.fGrContext, kPremul_SkAlphaTyp e, nullptr));
508 test_func(reporter, surface.get(), handle_access_func); 510 test_func(reporter, surface.get(), handle_access_func);
509 } 511 }
510 } 512 }
511 } 513 }
512 } 514 }
513 #endif 515 #endif
514 516
515 // Verify that the right canvas commands trigger a copy on write. 517 // Verify that the right canvas commands trigger a copy on write.
516 static void test_copy_on_write(skiatest::Reporter* reporter, SkSurface* surface) { 518 static void test_copy_on_write(skiatest::Reporter* reporter, SkSurface* surface) {
517 SkCanvas* canvas = surface->getCanvas(); 519 SkCanvas* canvas = surface->getCanvas();
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 EXPECT_COPY_ON_WRITE(drawText(testText.c_str(), testText.size(), 0, 1, testP aint)) 586 EXPECT_COPY_ON_WRITE(drawText(testText.c_str(), testText.size(), 0, 1, testP aint))
585 EXPECT_COPY_ON_WRITE(drawPosText(testText.c_str(), testText.size(), testPoin ts2, \ 587 EXPECT_COPY_ON_WRITE(drawPosText(testText.c_str(), testText.size(), testPoin ts2, \
586 testPaint)) 588 testPaint))
587 EXPECT_COPY_ON_WRITE(drawTextOnPath(testText.c_str(), testText.size(), testP ath, nullptr, \ 589 EXPECT_COPY_ON_WRITE(drawTextOnPath(testText.c_str(), testText.size(), testP ath, nullptr, \
588 testPaint)) 590 testPaint))
589 } 591 }
590 DEF_TEST(SurfaceCopyOnWrite, reporter) { 592 DEF_TEST(SurfaceCopyOnWrite, reporter) {
591 test_copy_on_write(reporter, create_surface().get()); 593 test_copy_on_write(reporter, create_surface().get());
592 } 594 }
593 #if SK_SUPPORT_GPU 595 #if SK_SUPPORT_GPU
594 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCopyOnWrite_Gpu, reporter, context) { 596 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCopyOnWrite_Gpu, reporter, ctxInfo) {
595 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) { 597 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
596 auto surface(surface_func(context, kPremul_SkAlphaType, nullptr)); 598 auto surface(surface_func(ctxInfo.fGrContext, kPremul_SkAlphaType, nullp tr));
597 test_copy_on_write(reporter, surface.get()); 599 test_copy_on_write(reporter, surface.get());
598 } 600 }
599 } 601 }
600 #endif 602 #endif
601 603
602 static void test_writable_after_snapshot_release(skiatest::Reporter* reporter, 604 static void test_writable_after_snapshot_release(skiatest::Reporter* reporter,
603 SkSurface* surface) { 605 SkSurface* surface) {
604 // This test succeeds by not triggering an assertion. 606 // This test succeeds by not triggering an assertion.
605 // The test verifies that the surface remains writable (usable) after 607 // The test verifies that the surface remains writable (usable) after
606 // acquiring and releasing a snapshot without triggering a copy on write. 608 // acquiring and releasing a snapshot without triggering a copy on write.
607 SkCanvas* canvas = surface->getCanvas(); 609 SkCanvas* canvas = surface->getCanvas();
608 canvas->clear(1); 610 canvas->clear(1);
609 surface->makeImageSnapshot(); // Create and destroy SkImage 611 surface->makeImageSnapshot(); // Create and destroy SkImage
610 canvas->clear(2); // Must not assert internally 612 canvas->clear(2); // Must not assert internally
611 } 613 }
612 DEF_TEST(SurfaceWriteableAfterSnapshotRelease, reporter) { 614 DEF_TEST(SurfaceWriteableAfterSnapshotRelease, reporter) {
613 test_writable_after_snapshot_release(reporter, create_surface().get()); 615 test_writable_after_snapshot_release(reporter, create_surface().get());
614 } 616 }
615 #if SK_SUPPORT_GPU 617 #if SK_SUPPORT_GPU
616 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceWriteableAfterSnapshotRelease_Gpu, rep orter, context) { 618 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceWriteableAfterSnapshotRelease_Gpu, rep orter, ctxInfo) {
617 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) { 619 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
618 auto surface(surface_func(context, kPremul_SkAlphaType, nullptr)); 620 auto surface(surface_func(ctxInfo.fGrContext, kPremul_SkAlphaType, nullp tr));
619 test_writable_after_snapshot_release(reporter, surface.get()); 621 test_writable_after_snapshot_release(reporter, surface.get());
620 } 622 }
621 } 623 }
622 #endif 624 #endif
623 625
624 #if SK_SUPPORT_GPU 626 #if SK_SUPPORT_GPU
625 static void test_crbug263329(skiatest::Reporter* reporter, 627 static void test_crbug263329(skiatest::Reporter* reporter,
626 SkSurface* surface1, 628 SkSurface* surface1,
627 SkSurface* surface2) { 629 SkSurface* surface2) {
628 // This is a regression test for crbug.com/263329 630 // This is a regression test for crbug.com/263329
(...skipping 18 matching lines...) Expand all
647 canvas2->clear(5); 649 canvas2->clear(5);
648 sk_sp<SkImage> image4(surface2->makeImageSnapshot()); 650 sk_sp<SkImage> image4(surface2->makeImageSnapshot());
649 REPORTER_ASSERT(reporter, as_IB(image4)->peekTexture() != as_IB(image3)->pee kTexture()); 651 REPORTER_ASSERT(reporter, as_IB(image4)->peekTexture() != as_IB(image3)->pee kTexture());
650 // The following assertion checks crbug.com/263329 652 // The following assertion checks crbug.com/263329
651 REPORTER_ASSERT(reporter, as_IB(image4)->peekTexture() != as_IB(image2)->pee kTexture()); 653 REPORTER_ASSERT(reporter, as_IB(image4)->peekTexture() != as_IB(image2)->pee kTexture());
652 REPORTER_ASSERT(reporter, as_IB(image4)->peekTexture() != as_IB(image1)->pee kTexture()); 654 REPORTER_ASSERT(reporter, as_IB(image4)->peekTexture() != as_IB(image1)->pee kTexture());
653 REPORTER_ASSERT(reporter, as_IB(image3)->peekTexture() != as_IB(image2)->pee kTexture()); 655 REPORTER_ASSERT(reporter, as_IB(image3)->peekTexture() != as_IB(image2)->pee kTexture());
654 REPORTER_ASSERT(reporter, as_IB(image3)->peekTexture() != as_IB(image1)->pee kTexture()); 656 REPORTER_ASSERT(reporter, as_IB(image3)->peekTexture() != as_IB(image1)->pee kTexture());
655 REPORTER_ASSERT(reporter, as_IB(image2)->peekTexture() != as_IB(image1)->pee kTexture()); 657 REPORTER_ASSERT(reporter, as_IB(image2)->peekTexture() != as_IB(image1)->pee kTexture());
656 } 658 }
657 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCRBug263329_Gpu, reporter, context) { 659 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCRBug263329_Gpu, reporter, ctxInfo) {
658 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) { 660 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
659 auto surface1(surface_func(context, kPremul_SkAlphaType, nullptr)); 661 auto surface1(surface_func(ctxInfo.fGrContext, kPremul_SkAlphaType, null ptr));
660 auto surface2(surface_func(context, kPremul_SkAlphaType, nullptr)); 662 auto surface2(surface_func(ctxInfo.fGrContext, kPremul_SkAlphaType, null ptr));
661 test_crbug263329(reporter, surface1.get(), surface2.get()); 663 test_crbug263329(reporter, surface1.get(), surface2.get());
662 } 664 }
663 } 665 }
664 #endif 666 #endif
665 667
666 DEF_TEST(SurfaceGetTexture, reporter) { 668 DEF_TEST(SurfaceGetTexture, reporter) {
667 auto surface(create_surface()); 669 auto surface(create_surface());
668 sk_sp<SkImage> image(surface->makeImageSnapshot()); 670 sk_sp<SkImage> image(surface->makeImageSnapshot());
669 REPORTER_ASSERT(reporter, as_IB(image)->peekTexture() == nullptr); 671 REPORTER_ASSERT(reporter, as_IB(image)->peekTexture() == nullptr);
670 surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode); 672 surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode);
671 REPORTER_ASSERT(reporter, as_IB(image)->peekTexture() == nullptr); 673 REPORTER_ASSERT(reporter, as_IB(image)->peekTexture() == nullptr);
672 } 674 }
673 #if SK_SUPPORT_GPU 675 #if SK_SUPPORT_GPU
674 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfacepeekTexture_Gpu, reporter, context) { 676 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfacepeekTexture_Gpu, reporter, ctxInfo) {
675 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) { 677 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
676 auto surface(surface_func(context, kPremul_SkAlphaType, nullptr)); 678 auto surface(surface_func(ctxInfo.fGrContext, kPremul_SkAlphaType, nullp tr));
677 sk_sp<SkImage> image(surface->makeImageSnapshot()); 679 sk_sp<SkImage> image(surface->makeImageSnapshot());
678 GrTexture* texture = as_IB(image)->peekTexture(); 680 GrTexture* texture = as_IB(image)->peekTexture();
679 REPORTER_ASSERT(reporter, texture); 681 REPORTER_ASSERT(reporter, texture);
680 REPORTER_ASSERT(reporter, 0 != texture->getTextureHandle()); 682 REPORTER_ASSERT(reporter, 0 != texture->getTextureHandle());
681 surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode); 683 surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode);
682 REPORTER_ASSERT(reporter, as_IB(image)->peekTexture() == texture); 684 REPORTER_ASSERT(reporter, as_IB(image)->peekTexture() == texture);
683 } 685 }
684 } 686 }
685 #endif 687 #endif
686 688
687 #if SK_SUPPORT_GPU 689 #if SK_SUPPORT_GPU
688 #include "GrGpuResourcePriv.h" 690 #include "GrGpuResourcePriv.h"
689 #include "SkGpuDevice.h" 691 #include "SkGpuDevice.h"
690 #include "SkImage_Gpu.h" 692 #include "SkImage_Gpu.h"
691 #include "SkSurface_Gpu.h" 693 #include "SkSurface_Gpu.h"
692 694
693 static SkBudgeted is_budgeted(const sk_sp<SkSurface>& surf) { 695 static SkBudgeted is_budgeted(const sk_sp<SkSurface>& surf) {
694 SkSurface_Gpu* gsurf = (SkSurface_Gpu*)surf.get(); 696 SkSurface_Gpu* gsurf = (SkSurface_Gpu*)surf.get();
695 return gsurf->getDevice()->accessRenderTarget()->resourcePriv().isBudgeted() ; 697 return gsurf->getDevice()->accessRenderTarget()->resourcePriv().isBudgeted() ;
696 } 698 }
697 699
698 static SkBudgeted is_budgeted(SkImage* image) { 700 static SkBudgeted is_budgeted(SkImage* image) {
699 return ((SkImage_Gpu*)image)->peekTexture()->resourcePriv().isBudgeted(); 701 return ((SkImage_Gpu*)image)->peekTexture()->resourcePriv().isBudgeted();
700 } 702 }
701 703
702 static SkBudgeted is_budgeted(const sk_sp<SkImage> image) { 704 static SkBudgeted is_budgeted(const sk_sp<SkImage> image) {
703 return is_budgeted(image.get()); 705 return is_budgeted(image.get());
704 } 706 }
705 707
706 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceBudget, reporter, context) { 708 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceBudget, reporter, ctxInfo) {
707 SkImageInfo info = SkImageInfo::MakeN32Premul(8,8); 709 SkImageInfo info = SkImageInfo::MakeN32Premul(8,8);
708 for (auto sbudgeted : { SkBudgeted::kNo, SkBudgeted::kYes }) { 710 for (auto sbudgeted : { SkBudgeted::kNo, SkBudgeted::kYes }) {
709 for (auto ibudgeted : { SkBudgeted::kNo, SkBudgeted::kYes }) { 711 for (auto ibudgeted : { SkBudgeted::kNo, SkBudgeted::kYes }) {
710 auto surface(SkSurface::MakeRenderTarget(context, sbudgeted, info)); 712 auto surface(SkSurface::MakeRenderTarget(ctxInfo.fGrContext, sbudget ed, info));
711 SkASSERT(surface); 713 SkASSERT(surface);
712 REPORTER_ASSERT(reporter, sbudgeted == is_budgeted(surface)); 714 REPORTER_ASSERT(reporter, sbudgeted == is_budgeted(surface));
713 715
714 sk_sp<SkImage> image(surface->makeImageSnapshot(ibudgeted)); 716 sk_sp<SkImage> image(surface->makeImageSnapshot(ibudgeted));
715 717
716 // Initially the image shares a texture with the surface, and the su rface decides 718 // Initially the image shares a texture with the surface, and the su rface decides
717 // whether it is budgeted or not. 719 // whether it is budgeted or not.
718 REPORTER_ASSERT(reporter, sbudgeted == is_budgeted(surface)); 720 REPORTER_ASSERT(reporter, sbudgeted == is_budgeted(surface));
719 REPORTER_ASSERT(reporter, sbudgeted == is_budgeted(image)); 721 REPORTER_ASSERT(reporter, sbudgeted == is_budgeted(image));
720 722
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 DEF_TEST(SurfaceNoCanvas, reporter) { 760 DEF_TEST(SurfaceNoCanvas, reporter) {
759 SkSurface::ContentChangeMode modes[] = 761 SkSurface::ContentChangeMode modes[] =
760 { SkSurface::kDiscard_ContentChangeMode, SkSurface::kRetain_ContentC hangeMode}; 762 { SkSurface::kDiscard_ContentChangeMode, SkSurface::kRetain_ContentC hangeMode};
761 for (auto& test_func : { &test_no_canvas1, &test_no_canvas2 }) { 763 for (auto& test_func : { &test_no_canvas1, &test_no_canvas2 }) {
762 for (auto& mode : modes) { 764 for (auto& mode : modes) {
763 test_func(reporter, create_surface().get(), mode); 765 test_func(reporter, create_surface().get(), mode);
764 } 766 }
765 } 767 }
766 } 768 }
767 #if SK_SUPPORT_GPU 769 #if SK_SUPPORT_GPU
768 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceNoCanvas_Gpu, reporter, context) { 770 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceNoCanvas_Gpu, reporter, ctxInfo) {
769 SkSurface::ContentChangeMode modes[] = 771 SkSurface::ContentChangeMode modes[] =
770 { SkSurface::kDiscard_ContentChangeMode, SkSurface::kRetain_ContentC hangeMode}; 772 { SkSurface::kDiscard_ContentChangeMode, SkSurface::kRetain_ContentC hangeMode};
771 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) { 773 for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
772 for (auto& test_func : { &test_no_canvas1, &test_no_canvas2 }) { 774 for (auto& test_func : { &test_no_canvas1, &test_no_canvas2 }) {
773 for (auto& mode : modes) { 775 for (auto& mode : modes) {
774 auto surface(surface_func(context, kPremul_SkAlphaType, nullptr) ); 776 auto surface(surface_func(ctxInfo.fGrContext, kPremul_SkAlphaTyp e, nullptr));
775 test_func(reporter, surface.get(), mode); 777 test_func(reporter, surface.get(), mode);
776 } 778 }
777 } 779 }
778 } 780 }
779 } 781 }
780 #endif 782 #endif
781 783
782 static void check_rowbytes_remain_consistent(SkSurface* surface, skiatest::Repor ter* reporter) { 784 static void check_rowbytes_remain_consistent(SkSurface* surface, skiatest::Repor ter* reporter) {
783 SkPixmap surfacePM; 785 SkPixmap surfacePM;
784 REPORTER_ASSERT(reporter, surface->peekPixels(&surfacePM)); 786 REPORTER_ASSERT(reporter, surface->peekPixels(&surfacePM));
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 } 851 }
850 ERRORF(reporter, 852 ERRORF(reporter,
851 "%s but read 0x%08x (instead of 0x%08x) at %x,%d", msg.c_ str(), pixel, 853 "%s but read 0x%08x (instead of 0x%08x) at %x,%d", msg.c_ str(), pixel,
852 expectedValue, x, y); 854 expectedValue, x, y);
853 return; 855 return;
854 } 856 }
855 } 857 }
856 } 858 }
857 } 859 }
858 860
859 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceClear_Gpu, reporter, context) { 861 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceClear_Gpu, reporter, ctxInfo) {
862 GrContext* context = ctxInfo.fGrContext;
860 std::function<GrSurface*(SkSurface*)> grSurfaceGetters[] = { 863 std::function<GrSurface*(SkSurface*)> grSurfaceGetters[] = {
861 [] (SkSurface* s){ return s->getCanvas()->internal_private_accessTopLaye rRenderTarget(); }, 864 [] (SkSurface* s){ return s->getCanvas()->internal_private_accessTopLaye rRenderTarget(); },
862 [] (SkSurface* s){ 865 [] (SkSurface* s){
863 SkBaseDevice* d = 866 SkBaseDevice* d =
864 s->getCanvas()->getDevice_just_for_deprecated_compatibility_test ing(); 867 s->getCanvas()->getDevice_just_for_deprecated_compatibility_test ing();
865 return d->accessRenderTarget(); }, 868 return d->accessRenderTarget(); },
866 [] (SkSurface* s){ sk_sp<SkImage> i(s->makeImageSnapshot()); 869 [] (SkSurface* s){ sk_sp<SkImage> i(s->makeImageSnapshot());
867 return as_IB(i)->peekTexture(); }, 870 return as_IB(i)->peekTexture(); },
868 }; 871 };
869 for (auto grSurfaceGetter : grSurfaceGetters) { 872 for (auto grSurfaceGetter : grSurfaceGetters) {
(...skipping 17 matching lines...) Expand all
887 desc.fHeight = kHeight; 890 desc.fHeight = kHeight;
888 desc.fFlags = kRenderTarget_GrBackendTextureFlag; 891 desc.fFlags = kRenderTarget_GrBackendTextureFlag;
889 desc.fTextureHandle = textureObject; 892 desc.fTextureHandle = textureObject;
890 893
891 auto surface = SkSurface::MakeFromBackendTexture(context, desc, nullptr) ; 894 auto surface = SkSurface::MakeFromBackendTexture(context, desc, nullptr) ;
892 test_surface_clear(reporter, surface, grSurfaceGetter, 0xABABABAB); 895 test_surface_clear(reporter, surface, grSurfaceGetter, 0xABABABAB);
893 context->getGpu()->deleteTestingOnlyBackendTexture(textureObject); 896 context->getGpu()->deleteTestingOnlyBackendTexture(textureObject);
894 } 897 }
895 } 898 }
896 #endif 899 #endif
OLDNEW
« no previous file with comments | « tests/SpecialSurfaceTest.cpp ('k') | tests/TessellatingPathRendererTests.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698