skia2/tests/LayerDrawLooperTest.cpp
tfarina@chromium.org 8f6884aab8 Cleanup: Sanitize the order of includes under tests/
Initially this was to make sure Test.h appeared after the Sk*.h includes.

Patch generated by the following command line:

$ ~/chromium/src/tools/sort-headers.py tests/*.cpp

BUG=None
TEST=tests
R=robertphillips@google.com

Review URL: https://codereview.chromium.org/145313004

git-svn-id: http://skia.googlecode.com/svn/trunk@13177 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-24 20:56:26 +00:00

153 lines
5.6 KiB
C++

/*
* Copyright 2013 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkBitmap.h"
#include "SkBitmapDevice.h"
#include "SkCanvas.h"
#include "SkDraw.h"
#include "SkLayerDrawLooper.h"
#include "SkMatrix.h"
#include "SkPaint.h"
#include "SkRect.h"
#include "SkRefCnt.h"
#include "SkScalar.h"
#include "SkXfermode.h"
#include "Test.h"
class FakeDevice : public SkBitmapDevice {
public:
FakeDevice() : SkBitmapDevice(SkBitmap::kARGB_8888_Config, 100, 100, false) { }
virtual void drawRect(const SkDraw& draw, const SkRect& r,
const SkPaint& paint) SK_OVERRIDE {
fLastMatrix = *draw.fMatrix;
INHERITED::drawRect(draw, r, paint);
}
SkMatrix fLastMatrix;
private:
typedef SkBitmapDevice INHERITED;
};
static void test_frontToBack(skiatest::Reporter* reporter) {
SkAutoTUnref<SkLayerDrawLooper> looper(SkNEW(SkLayerDrawLooper));
SkLayerDrawLooper::LayerInfo layerInfo;
// Add the front layer, with the defaults.
(void)looper->addLayer(layerInfo);
// Add the back layer, with some layer info set.
layerInfo.fOffset.set(10.0f, 20.0f);
layerInfo.fPaintBits |= SkLayerDrawLooper::kXfermode_Bit;
SkPaint* layerPaint = looper->addLayer(layerInfo);
layerPaint->setXfermodeMode(SkXfermode::kSrc_Mode);
FakeDevice device;
SkCanvas canvas(&device);
SkPaint paint;
looper->init(&canvas);
// The back layer should come first.
REPORTER_ASSERT(reporter, looper->next(&canvas, &paint));
REPORTER_ASSERT(reporter, SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrc_Mode));
canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint);
REPORTER_ASSERT(reporter, 10.0f == device.fLastMatrix.getTranslateX());
REPORTER_ASSERT(reporter, 20.0f == device.fLastMatrix.getTranslateY());
paint.reset();
// Then the front layer.
REPORTER_ASSERT(reporter, looper->next(&canvas, &paint));
REPORTER_ASSERT(reporter, SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode));
canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint);
REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateX());
REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateY());
// Only two layers were added, so that should be the end.
REPORTER_ASSERT(reporter, !looper->next(&canvas, &paint));
}
static void test_backToFront(skiatest::Reporter* reporter) {
SkAutoTUnref<SkLayerDrawLooper> looper(SkNEW(SkLayerDrawLooper));
SkLayerDrawLooper::LayerInfo layerInfo;
// Add the back layer, with the defaults.
(void)looper->addLayerOnTop(layerInfo);
// Add the front layer, with some layer info set.
layerInfo.fOffset.set(10.0f, 20.0f);
layerInfo.fPaintBits |= SkLayerDrawLooper::kXfermode_Bit;
SkPaint* layerPaint = looper->addLayerOnTop(layerInfo);
layerPaint->setXfermodeMode(SkXfermode::kSrc_Mode);
FakeDevice device;
SkCanvas canvas(&device);
SkPaint paint;
looper->init(&canvas);
// The back layer should come first.
REPORTER_ASSERT(reporter, looper->next(&canvas, &paint));
REPORTER_ASSERT(reporter, SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode));
canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint);
REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateX());
REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateY());
paint.reset();
// Then the front layer.
REPORTER_ASSERT(reporter, looper->next(&canvas, &paint));
REPORTER_ASSERT(reporter, SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrc_Mode));
canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint);
REPORTER_ASSERT(reporter, 10.0f == device.fLastMatrix.getTranslateX());
REPORTER_ASSERT(reporter, 20.0f == device.fLastMatrix.getTranslateY());
// Only two layers were added, so that should be the end.
REPORTER_ASSERT(reporter, !looper->next(&canvas, &paint));
}
static void test_mixed(skiatest::Reporter* reporter) {
SkAutoTUnref<SkLayerDrawLooper> looper(SkNEW(SkLayerDrawLooper));
SkLayerDrawLooper::LayerInfo layerInfo;
// Add the back layer, with the defaults.
(void)looper->addLayer(layerInfo);
// Add the front layer, with some layer info set.
layerInfo.fOffset.set(10.0f, 20.0f);
layerInfo.fPaintBits |= SkLayerDrawLooper::kXfermode_Bit;
SkPaint* layerPaint = looper->addLayerOnTop(layerInfo);
layerPaint->setXfermodeMode(SkXfermode::kSrc_Mode);
FakeDevice device;
SkCanvas canvas(&device);
SkPaint paint;
looper->init(&canvas);
// The back layer should come first.
REPORTER_ASSERT(reporter, looper->next(&canvas, &paint));
REPORTER_ASSERT(reporter, SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode));
canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint);
REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateX());
REPORTER_ASSERT(reporter, 0.0f == device.fLastMatrix.getTranslateY());
paint.reset();
// Then the front layer.
REPORTER_ASSERT(reporter, looper->next(&canvas, &paint));
REPORTER_ASSERT(reporter, SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrc_Mode));
canvas.drawRect(SkRect::MakeWH(50.0f, 50.0f), paint);
REPORTER_ASSERT(reporter, 10.0f == device.fLastMatrix.getTranslateX());
REPORTER_ASSERT(reporter, 20.0f == device.fLastMatrix.getTranslateY());
// Only two layers were added, so that should be the end.
REPORTER_ASSERT(reporter, !looper->next(&canvas, &paint));
}
DEF_TEST(LayerDrawLooper, reporter) {
test_frontToBack(reporter);
test_backToFront(reporter);
test_mixed(reporter);
}