skia2/tests/DeferredCanvasTest.cpp
junov@chromium.org 1f9767c03b Fixing backing store access in SkDeferredCanvas.
Chromium CL required for rolling skia DEPS past this change is posted here: https://chromiumcodereview.appspot.com/9341003/
 
BUG=http://code.google.com/p/skia/issues/detail?id=475
REVIEW=http://codereview.appspot.com/5626047/
TEST=DeferredCanvas unit test



git-svn-id: http://skia.googlecode.com/svn/trunk@3147 2bbb7eff-a529-9590-31e7-b0007b416f81
2012-02-07 16:27:57 +00:00

60 lines
1.8 KiB
C++

/*
* Copyright 2012 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "Test.h"
#include "SkBitmap.h"
#include "SkDeferredCanvas.h"
static const int gWidth = 2;
static const int gHeight = 2;
static void create(SkBitmap* bm, SkBitmap::Config config, SkColor color) {
bm->setConfig(config, gWidth, gHeight);
bm->allocPixels();
bm->eraseColor(color);
}
static void TestDeferredCanvasBitmapAccess(skiatest::Reporter* reporter) {
SkBitmap store;
create(&store, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF);
SkDevice device(store);
SkDeferredCanvas canvas(&device);
canvas.clear(0x00000000);
SkAutoLockPixels alp(store);
REPORTER_ASSERT(reporter, store.getColor(0,0) == 0xFFFFFFFF); //verify that clear was deferred
SkBitmap accessed = canvas.getDevice()->accessBitmap(false);
REPORTER_ASSERT(reporter, store.getColor(0,0) == 0x00000000); //verify that clear was executed
REPORTER_ASSERT(reporter, accessed.pixelRef() == store.pixelRef());
}
static void TestDeferredCanvasFlush(skiatest::Reporter* reporter) {
SkBitmap store;
create(&store, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF);
SkDevice device(store);
SkDeferredCanvas canvas(&device);
canvas.clear(0x00000000);
SkAutoLockPixels alp(store);
REPORTER_ASSERT(reporter, store.getColor(0,0) == 0xFFFFFFFF); //verify that clear was deferred
canvas.flush();
REPORTER_ASSERT(reporter, store.getColor(0,0) == 0x00000000); //verify that clear was executed
}
static void TestDeferredCanvas(skiatest::Reporter* reporter) {
TestDeferredCanvasBitmapAccess(reporter);
TestDeferredCanvasFlush(reporter);
}
#include "TestClassDef.h"
DEFINE_TESTCLASS("DeferredCanvas", TestDeferredCanvasClass, TestDeferredCanvas)