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

Side by Side Diff: tests/SurfaceTest.cpp

Issue 1168303006: Revert[2] SkDraw and all Blitters to use pixmap instead of bitmapi (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add dox to new test Created 5 years, 6 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/DeviceLooperTest.cpp ('k') | tests/TextureCompressionTest.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 "SkCanvas.h" 8 #include "SkCanvas.h"
9 #include "SkData.h" 9 #include "SkData.h"
10 #include "SkDevice.h"
10 #include "SkImageEncoder.h" 11 #include "SkImageEncoder.h"
11 #include "SkRRect.h" 12 #include "SkRRect.h"
12 #include "SkSurface.h" 13 #include "SkSurface.h"
13 #include "SkUtils.h" 14 #include "SkUtils.h"
14 #include "Test.h" 15 #include "Test.h"
15 16
16 #if SK_SUPPORT_GPU 17 #if SK_SUPPORT_GPU
17 #include "GrContextFactory.h" 18 #include "GrContextFactory.h"
18 #else 19 #else
19 class GrContextFactory; 20 class GrContextFactory;
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 REPORTER_ASSERT(reporter, addr2 == addr); 344 REPORTER_ASSERT(reporter, addr2 == addr);
344 REPORTER_ASSERT(reporter, info2 == info); 345 REPORTER_ASSERT(reporter, info2 == info);
345 REPORTER_ASSERT(reporter, rb2 == rowBytes); 346 REPORTER_ASSERT(reporter, rb2 == rowBytes);
346 } else { 347 } else {
347 REPORTER_ASSERT(reporter, NULL == addr2); 348 REPORTER_ASSERT(reporter, NULL == addr2);
348 } 349 }
349 } 350 }
350 } 351 }
351 } 352 }
352 353
354 // For compatibility with clients that still call accessBitmap(), we need to ens ure that we bump
355 // the bitmap's genID when we draw to it, else they won't know it has new values . When they are
356 // exclusively using surface/image, and we can hide accessBitmap from device, we can remove this
357 // test.
358 static void test_accessPixels(skiatest::Reporter* reporter, GrContextFactory* fa ctory) {
359 static const struct {
360 SurfaceType fType;
361 bool fPeekShouldSucceed;
362 } gRec[] = {
363 { kRaster_SurfaceType, true },
364 { kRasterDirect_SurfaceType, true },
365 #if SK_SUPPORT_GPU
366 { kGpu_SurfaceType, false },
367 { kGpuScratch_SurfaceType, false },
368 #endif
369 };
370
371 int cnt;
372 #if SK_SUPPORT_GPU
373 cnt = GrContextFactory::kGLContextTypeCnt;
374 #else
375 cnt = 1;
376 #endif
377
378 for (int i= 0; i < cnt; ++i) {
379 GrContext* context = NULL;
380 #if SK_SUPPORT_GPU
381 GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLContext Type) i;
382 if (!GrContextFactory::IsRenderingGLContext(glCtxType)) {
383 continue;
384 }
385 context = factory->get(glCtxType);
386
387 if (NULL == context) {
388 continue;
389 }
390 #endif
391 for (size_t j = 0; j < SK_ARRAY_COUNT(gRec); ++j) {
392 SkImageInfo info, requestInfo;
393
394 SkAutoTUnref<SkSurface> surface(createSurface(gRec[j].fType, context ,
395 &requestInfo));
396 SkCanvas* canvas = surface->getCanvas();
397 canvas->clear(0);
398
399 SkBaseDevice* device = canvas->getDevice_just_for_deprecated_compati bility_testing();
400 SkBitmap bm = device->accessBitmap(false);
401 uint32_t genID0 = bm.getGenerationID();
402 // Now we draw something, which needs to "dirty" the genID (sorta li ke copy-on-write)
403 canvas->drawColor(SK_ColorBLUE);
404 // Now check that we get a different genID
405 uint32_t genID1 = bm.getGenerationID();
406 REPORTER_ASSERT(reporter, genID0 != genID1);
407 }
408 }
409 }
410
353 static void TestSurfaceCopyOnWrite(skiatest::Reporter* reporter, SurfaceType sur faceType, 411 static void TestSurfaceCopyOnWrite(skiatest::Reporter* reporter, SurfaceType sur faceType,
354 GrContext* context) { 412 GrContext* context) {
355 // Verify that the right canvas commands trigger a copy on write 413 // Verify that the right canvas commands trigger a copy on write
356 SkSurface* surface = createSurface(surfaceType, context); 414 SkSurface* surface = createSurface(surfaceType, context);
357 SkAutoTUnref<SkSurface> aur_surface(surface); 415 SkAutoTUnref<SkSurface> aur_surface(surface);
358 SkCanvas* canvas = surface->getCanvas(); 416 SkCanvas* canvas = surface->getCanvas();
359 417
360 const SkRect testRect = 418 const SkRect testRect =
361 SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0), 419 SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0),
362 SkIntToScalar(4), SkIntToScalar(5)); 420 SkIntToScalar(4), SkIntToScalar(5));
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 TestSurfaceWritableAfterSnapshotRelease(reporter, kRaster_SurfaceType, NULL) ; 638 TestSurfaceWritableAfterSnapshotRelease(reporter, kRaster_SurfaceType, NULL) ;
581 TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kDiscard _ContentChangeMode); 639 TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kDiscard _ContentChangeMode);
582 TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kRetain_ ContentChangeMode); 640 TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kRetain_ ContentChangeMode);
583 641
584 test_empty_image(reporter); 642 test_empty_image(reporter);
585 test_empty_surface(reporter, NULL); 643 test_empty_surface(reporter, NULL);
586 644
587 test_imagepeek(reporter, factory); 645 test_imagepeek(reporter, factory);
588 test_canvaspeek(reporter, factory); 646 test_canvaspeek(reporter, factory);
589 647
648 test_accessPixels(reporter, factory);
649
590 #if SK_SUPPORT_GPU 650 #if SK_SUPPORT_GPU
591 TestGetTexture(reporter, kRaster_SurfaceType, NULL); 651 TestGetTexture(reporter, kRaster_SurfaceType, NULL);
592 if (factory) { 652 if (factory) {
593 for (int i= 0; i < GrContextFactory::kGLContextTypeCnt; ++i) { 653 for (int i= 0; i < GrContextFactory::kGLContextTypeCnt; ++i) {
594 GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLCon textType) i; 654 GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLCon textType) i;
595 if (!GrContextFactory::IsRenderingGLContext(glCtxType)) { 655 if (!GrContextFactory::IsRenderingGLContext(glCtxType)) {
596 continue; 656 continue;
597 } 657 }
598 GrContext* context = factory->get(glCtxType); 658 GrContext* context = factory->get(glCtxType);
599 if (context) { 659 if (context) {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 // Now lets jam new colors into our "external" texture, and see if the image s notice 736 // Now lets jam new colors into our "external" texture, and see if the image s notice
677 const SkPMColor expected1 = SkPreMultiplyColor(SK_ColorBLUE); 737 const SkPMColor expected1 = SkPreMultiplyColor(SK_ColorBLUE);
678 sk_memset32(storage, expected1, w * h); 738 sk_memset32(storage, expected1, w * h);
679 tex->writePixels(0, 0, w, h, kSkia8888_GrPixelConfig, storage, GrContext::kF lushWrites_PixelOp); 739 tex->writePixels(0, 0, w, h, kSkia8888_GrPixelConfig, storage, GrContext::kF lushWrites_PixelOp);
680 740
681 // We expect the ref'd image to see the new color, but cpy'd one should stil l see the old color 741 // We expect the ref'd image to see the new color, but cpy'd one should stil l see the old color
682 test_image_color(reporter, refImg, expected1); 742 test_image_color(reporter, refImg, expected1);
683 test_image_color(reporter, cpyImg, expected0); 743 test_image_color(reporter, cpyImg, expected0);
684 } 744 }
685 #endif 745 #endif
OLDNEW
« no previous file with comments | « tests/DeviceLooperTest.cpp ('k') | tests/TextureCompressionTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698