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

Side by Side Diff: tests/SurfaceTest.cpp

Issue 1208993008: explicitly bump legacy genID on gpu surface (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add dox Created 5 years, 5 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 | « src/image/SkSurface_Gpu.cpp ('k') | no next file » | 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 "SkCanvas.h" 8 #include "SkCanvas.h"
9 #include "SkData.h" 9 #include "SkData.h"
10 #include "SkDevice.h" 10 #include "SkDevice.h"
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 } 253 }
254 }; 254 };
255 255
256 // May we (soon) eliminate the need to keep testing this, by hiding the bloody d evice! 256 // May we (soon) eliminate the need to keep testing this, by hiding the bloody d evice!
257 #include "SkDevice.h" 257 #include "SkDevice.h"
258 static uint32_t get_legacy_gen_id(SkSurface* surf) { 258 static uint32_t get_legacy_gen_id(SkSurface* surf) {
259 SkBaseDevice* device = surf->getCanvas()->getDevice_just_for_deprecated_comp atibility_testing(); 259 SkBaseDevice* device = surf->getCanvas()->getDevice_just_for_deprecated_comp atibility_testing();
260 return device->accessBitmap(false).getGenerationID(); 260 return device->accessBitmap(false).getGenerationID();
261 } 261 }
262 262
263 /*
264 * Test legacy behavor of bumping the surface's device's bitmap's genID when we access its
265 * texture handle for writing.
266 *
267 * Note: this needs to be tested separately from checking newImageSnapshot, as calling that
268 * can also incidentally bump the genID (when a new backing surface is created) .
269 */
270 static void test_texture_handle_genID(skiatest::Reporter* reporter, SkSurface* s urf) {
271 const uint32_t gen0 = get_legacy_gen_id(surf);
272 surf->getTextureHandle(SkSurface::kFlushRead_TextureHandleAccess);
273 const uint32_t gen1 = get_legacy_gen_id(surf);
274 REPORTER_ASSERT(reporter, gen0 == gen1);
275
276 surf->getTextureHandle(SkSurface::kFlushWrite_TextureHandleAccess);
277 const uint32_t gen2 = get_legacy_gen_id(surf);
278 REPORTER_ASSERT(reporter, gen0 != gen2);
279
280 surf->getTextureHandle(SkSurface::kDiscardWrite_TextureHandleAccess);
281 const uint32_t gen3 = get_legacy_gen_id(surf);
282 REPORTER_ASSERT(reporter, gen0 != gen3);
283 REPORTER_ASSERT(reporter, gen2 != gen3);
284 }
285
263 static void test_texture_handle(skiatest::Reporter* reporter, SkSurface* surf) { 286 static void test_texture_handle(skiatest::Reporter* reporter, SkSurface* surf) {
264 SkAutoTUnref<SkImage> image0(surf->newImageSnapshot()); 287 SkAutoTUnref<SkImage> image0(surf->newImageSnapshot());
265 const uint32_t genID0 = get_legacy_gen_id(surf);
266 GrBackendObject obj = surf->getTextureHandle(SkSurface::kFlushRead_TextureHa ndleAccess); 288 GrBackendObject obj = surf->getTextureHandle(SkSurface::kFlushRead_TextureHa ndleAccess);
267 REPORTER_ASSERT(reporter, obj != 0); 289 REPORTER_ASSERT(reporter, obj != 0);
268 SkAutoTUnref<SkImage> image1(surf->newImageSnapshot()); 290 SkAutoTUnref<SkImage> image1(surf->newImageSnapshot());
269 const uint32_t genID1 = get_legacy_gen_id(surf);
270 // just read access should not affect the snapshot 291 // just read access should not affect the snapshot
271 REPORTER_ASSERT(reporter, image0->uniqueID() == image1->uniqueID()); 292 REPORTER_ASSERT(reporter, image0->uniqueID() == image1->uniqueID());
272 REPORTER_ASSERT(reporter, genID0 == genID1);
273 293
274 obj = surf->getTextureHandle(SkSurface::kFlushWrite_TextureHandleAccess); 294 obj = surf->getTextureHandle(SkSurface::kFlushWrite_TextureHandleAccess);
275 REPORTER_ASSERT(reporter, obj != 0); 295 REPORTER_ASSERT(reporter, obj != 0);
276 SkAutoTUnref<SkImage> image2(surf->newImageSnapshot()); 296 SkAutoTUnref<SkImage> image2(surf->newImageSnapshot());
277 const uint32_t genID2 = get_legacy_gen_id(surf);
278 // expect a new image, since we claimed we would write 297 // expect a new image, since we claimed we would write
279 REPORTER_ASSERT(reporter, image0->uniqueID() != image2->uniqueID()); 298 REPORTER_ASSERT(reporter, image0->uniqueID() != image2->uniqueID());
280 REPORTER_ASSERT(reporter, genID0 != genID2);
281 299
282 obj = surf->getTextureHandle(SkSurface::kDiscardWrite_TextureHandleAccess); 300 obj = surf->getTextureHandle(SkSurface::kDiscardWrite_TextureHandleAccess);
283 REPORTER_ASSERT(reporter, obj != 0); 301 REPORTER_ASSERT(reporter, obj != 0);
284 SkAutoTUnref<SkImage> image3(surf->newImageSnapshot()); 302 SkAutoTUnref<SkImage> image3(surf->newImageSnapshot());
285 const uint32_t genID3 = get_legacy_gen_id(surf);
286 // expect a new(er) image, since we claimed we would write 303 // expect a new(er) image, since we claimed we would write
287 REPORTER_ASSERT(reporter, image0->uniqueID() != image3->uniqueID()); 304 REPORTER_ASSERT(reporter, image0->uniqueID() != image3->uniqueID());
288 REPORTER_ASSERT(reporter, image2->uniqueID() != image3->uniqueID()); 305 REPORTER_ASSERT(reporter, image2->uniqueID() != image3->uniqueID());
289 REPORTER_ASSERT(reporter, genID0 != genID3);
290 REPORTER_ASSERT(reporter, genID2 != genID3);
291 } 306 }
292 307
293 static SkImage* create_image(skiatest::Reporter* reporter, 308 static SkImage* create_image(skiatest::Reporter* reporter,
294 ImageType imageType, GrContext* context, SkColor co lor, 309 ImageType imageType, GrContext* context, SkColor co lor,
295 ReleaseDataContext* releaseContext) { 310 ReleaseDataContext* releaseContext) {
296 const SkPMColor pmcolor = SkPreMultiplyColor(color); 311 const SkPMColor pmcolor = SkPreMultiplyColor(color);
297 const SkImageInfo info = SkImageInfo::MakeN32Premul(10, 10); 312 const SkImageInfo info = SkImageInfo::MakeN32Premul(10, 10);
298 const size_t rowBytes = info.minRowBytes(); 313 const size_t rowBytes = info.minRowBytes();
299 const size_t size = rowBytes * info.height(); 314 const size_t size = rowBytes * info.height();
300 315
301 SkAutoTUnref<SkData> data(SkData::NewUninitialized(size)); 316 SkAutoTUnref<SkData> data(SkData::NewUninitialized(size));
302 void* addr = data->writable_data(); 317 void* addr = data->writable_data();
303 sk_memset32((SkPMColor*)addr, pmcolor, SkToInt(size >> 2)); 318 sk_memset32((SkPMColor*)addr, pmcolor, SkToInt(size >> 2));
304 319
305 switch (imageType) { 320 switch (imageType) {
306 case kRasterCopy_ImageType: 321 case kRasterCopy_ImageType:
307 return SkImage::NewRasterCopy(info, addr, rowBytes); 322 return SkImage::NewRasterCopy(info, addr, rowBytes);
308 case kRasterData_ImageType: 323 case kRasterData_ImageType:
309 return SkImage::NewRasterData(info, data, rowBytes); 324 return SkImage::NewRasterData(info, data, rowBytes);
310 case kRasterProc_ImageType: 325 case kRasterProc_ImageType:
311 SkASSERT(releaseContext); 326 SkASSERT(releaseContext);
312 releaseContext->fData = SkRef(data.get()); 327 releaseContext->fData = SkRef(data.get());
313 return SkImage::NewFromRaster(info, addr, rowBytes, 328 return SkImage::NewFromRaster(info, addr, rowBytes,
314 ReleaseDataContext::Release, releaseCo ntext); 329 ReleaseDataContext::Release, releaseCo ntext);
315 case kGpu_ImageType: { 330 case kGpu_ImageType: {
316 SkAutoTUnref<SkSurface> surf( 331 SkAutoTUnref<SkSurface> surf(
317 SkSurface::NewRenderTarget(context, SkSurface::kNo_Budgeted, inf o, 0)); 332 SkSurface::NewRenderTarget(context, SkSurface::kNo_Budgeted, inf o, 0));
318 surf->getCanvas()->clear(color); 333 surf->getCanvas()->clear(color);
319 // test our backing texture while were here... 334 // test our backing texture while were here...
335 test_texture_handle_genID(reporter, surf);
320 test_texture_handle(reporter, surf); 336 test_texture_handle(reporter, surf);
321 // redraw so our returned image looks as expected. 337 // redraw so our returned image looks as expected.
322 surf->getCanvas()->clear(color); 338 surf->getCanvas()->clear(color);
323 return surf->newImageSnapshot(); 339 return surf->newImageSnapshot();
324 } 340 }
325 case kCodec_ImageType: { 341 case kCodec_ImageType: {
326 SkBitmap bitmap; 342 SkBitmap bitmap;
327 bitmap.installPixels(info, addr, rowBytes); 343 bitmap.installPixels(info, addr, rowBytes);
328 SkAutoTUnref<SkData> src( 344 SkAutoTUnref<SkData> src(
329 SkImageEncoder::EncodeData(bitmap, SkImageEncoder::kPNG_Type, 1 00)); 345 SkImageEncoder::EncodeData(bitmap, SkImageEncoder::kPNG_Type, 1 00));
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after
963 // We expect the ref'd image to see the new color, but cpy'd one should stil l see the old color 979 // We expect the ref'd image to see the new color, but cpy'd one should stil l see the old color
964 test_image_color(reporter, refImg, expected1); 980 test_image_color(reporter, refImg, expected1);
965 test_image_color(reporter, cpyImg, expected0); 981 test_image_color(reporter, cpyImg, expected0);
966 982
967 // Now exercise the release proc 983 // Now exercise the release proc
968 REPORTER_ASSERT(reporter, !releaseCtx.fIsReleased); 984 REPORTER_ASSERT(reporter, !releaseCtx.fIsReleased);
969 refImg.reset(NULL); // force a release of the image 985 refImg.reset(NULL); // force a release of the image
970 REPORTER_ASSERT(reporter, releaseCtx.fIsReleased); 986 REPORTER_ASSERT(reporter, releaseCtx.fIsReleased);
971 } 987 }
972 #endif 988 #endif
OLDNEW
« no previous file with comments | « src/image/SkSurface_Gpu.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698