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

Side by Side Diff: tests/DeferredCanvasTest.cpp

Issue 12567025: Integrating SkSurface with SkDeferredCanvas (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 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 | Annotate | Revision Log
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2012 Google Inc. 3 * Copyright 2012 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "Test.h" 8 #include "Test.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkBitmapProcShader.h" 10 #include "SkBitmapProcShader.h"
11 #include "SkDeferredCanvas.h" 11 #include "SkDeferredCanvas.h"
12 #include "SkDevice.h" 12 #include "SkDevice.h"
13 #include "SkGradientShader.h" 13 #include "SkGradientShader.h"
14 #include "SkShader.h" 14 #include "SkShader.h"
15 #include "SkSurface.h"
16 #if SK_SUPPORT_GPU
17 #include "GrContextFactory.h"
18 #else
19 class GrContextFactory;
20 #endif
15 21
16 static const int gWidth = 2; 22 static const int gWidth = 2;
17 static const int gHeight = 2; 23 static const int gHeight = 2;
18 24
19 static void create(SkBitmap* bm, SkBitmap::Config config, SkColor color) { 25 static void create(SkBitmap* bm, SkBitmap::Config config, SkColor color) {
20 bm->setConfig(config, gWidth, gHeight); 26 bm->setConfig(config, gWidth, gHeight);
21 bm->allocPixels(); 27 bm->allocPixels();
22 bm->eraseColor(color); 28 bm->eraseColor(color);
23 } 29 }
24 30
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 { 464 {
459 SkDevice device(store); 465 SkDevice device(store);
460 SkDeferredCanvas canvas(&device); 466 SkDeferredCanvas canvas(&device);
461 canvas.setBitmapSizeThreshold(40001); 467 canvas.setBitmapSizeThreshold(40001);
462 canvas.drawBitmap(sourceImage, 0, 0, NULL); 468 canvas.drawBitmap(sourceImage, 0, 0, NULL);
463 size_t newBytesAllocated = canvas.storageAllocatedForRecording(); 469 size_t newBytesAllocated = canvas.storageAllocatedForRecording();
464 REPORTER_ASSERT(reporter, newBytesAllocated > 0); 470 REPORTER_ASSERT(reporter, newBytesAllocated > 0);
465 } 471 }
466 } 472 }
467 473
474 static void TestDeferredCanvasSurface(skiatest::Reporter* reporter, GrContextFac tory* factory) {
475 SkImage::Info imageSpec = {
476 10, // width
477 10, // height
478 SkImage::kPMColor_ColorType,
479 SkImage::kPremul_AlphaType
480 };
481 SkSurface* surface;
482 bool useGpu = NULL != factory;
483 #if SK_SUPPORT_GPU
484 if (useGpu) {
485 GrContext* context = factory->get(GrContextFactory::kNative_GLContextTyp e);
486 surface = SkSurface::NewRenderTarget(context, imageSpec);
487 } else {
488 surface = SkSurface::NewRaster(imageSpec);
489 }
490 #else
491 SkASSERT(!useGpu);
492 surface = SkSurface::NewRaster(imageSpec);
493 #endif
494 SkASSERT(NULL != surface);
495 SkAutoTUnref<SkSurface> aur(surface);
496 SkDeferredCanvas canvas(surface);
497
498 SkImage* image1 = canvas.newImageShapshot();
499 SkAutoTUnref<SkImage> aur_i1(image1);
500 void* pixels1 = useGpu ? surface->getCanvas()->getDevice()->accessBitmap(fal se).getTexture() :
501 surface->getCanvas()->getDevice()->accessBitmap(false).getPixels();
502 canvas.clear(SK_ColorBLACK);
503 SkImage* image2 = surface->newImageShapshot();
504 SkAutoTUnref<SkImage> aur_i2(image2);
505 // Images identical because of deferral
506 REPORTER_ASSERT(reporter, image1->uniqueID() == image2->uniqueID());
507 SkImage* image3 = canvas.newImageShapshot(); // triggers a flush
508 SkAutoTUnref<SkImage> aur_i3(image3);
509 REPORTER_ASSERT(reporter, image1->uniqueID() != image3->uniqueID());
510 // Verify that backing store is now a different buffer because of copy on wr ite
511 void* pixels2 = useGpu ? surface->getCanvas()->getDevice()->accessBitmap(fal se).getTexture() :
512 surface->getCanvas()->getDevice()->accessBitmap(false).getPixels();
513 REPORTER_ASSERT(reporter, pixels1 != pixels2);
514 canvas.clear(SK_ColorWHITE);
515 canvas.flush();
516 void* pixels3 = useGpu ? surface->getCanvas()->getDevice()->accessBitmap(fal se).getTexture() :
517 surface->getCanvas()->getDevice()->accessBitmap(false).getPixels();
518 canvas.clear(SK_ColorBLACK);
519 canvas.flush();
520 void* pixels4 = useGpu ? surface->getCanvas()->getDevice()->accessBitmap(fal se).getTexture() :
521 surface->getCanvas()->getDevice()->accessBitmap(false).getPixels();
522 // Since no snapshot was acquired in the pixels3 state, the flush should
523 // not trigger a copy on write.
524 REPORTER_ASSERT(reporter, pixels3 == pixels4);
525 }
526
468 static void TestDeferredCanvas(skiatest::Reporter* reporter) { 527 static void TestDeferredCanvas(skiatest::Reporter* reporter) {
469 TestDeferredCanvasBitmapAccess(reporter); 528 TestDeferredCanvasBitmapAccess(reporter);
470 TestDeferredCanvasFlush(reporter); 529 TestDeferredCanvasFlush(reporter);
471 TestDeferredCanvasFreshFrame(reporter); 530 TestDeferredCanvasFreshFrame(reporter);
472 TestDeferredCanvasMemoryLimit(reporter); 531 TestDeferredCanvasMemoryLimit(reporter);
473 TestDeferredCanvasBitmapCaching(reporter); 532 TestDeferredCanvasBitmapCaching(reporter);
474 TestDeferredCanvasSkip(reporter); 533 TestDeferredCanvasSkip(reporter);
475 TestDeferredCanvasBitmapShaderNoLeak(reporter); 534 TestDeferredCanvasBitmapShaderNoLeak(reporter);
476 TestDeferredCanvasBitmapSizeThreshold(reporter); 535 TestDeferredCanvasBitmapSizeThreshold(reporter);
536 TestDeferredCanvasSurface(reporter, NULL);
537 }
538
539 static void TestDeferredCanvasGpu(skiatest::Reporter* reporter, GrContextFactory * factory) {
540 TestDeferredCanvasSurface(reporter, factory);
477 } 541 }
478 542
479 #include "TestClassDef.h" 543 #include "TestClassDef.h"
480 DEFINE_TESTCLASS("DeferredCanvas", TestDeferredCanvasClass, TestDeferredCanvas) 544 DEFINE_TESTCLASS("DeferredCanvas", TestDeferredCanvasClass, TestDeferredCanvas)
545 DEFINE_GPUTESTCLASS("DeferredCanvasGpu", TestDeferredCanvasGpuClass, TestDeferre dCanvasGpu)
546
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698