baf06bc89a
This reverts commitcfaa63237b
. Reason for revert: speculative revert to fix Google3 Original change's description: > Revert[2] "Remove SkDraw from device-draw methods, and enable device-centric clipping."" > > passes new (augmented) CanvasClipType unittest > fixed rasterclipstack::setnewsize > > This reverts commitea5e676a7b
. > > BUG=skia: > > Change-Id: I004653e0f4d01454662f8516fccab0046486f273 > Reviewed-on: https://skia-review.googlesource.com/9185 > Reviewed-by: Brian Salomon <bsalomon@google.com> > Commit-Queue: Mike Reed <reed@google.com> > TBR=bsalomon@google.com,reed@google.com,reviews@skia.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=skia: Change-Id: Ibd7ee6383999f008eb6ee59c1c3f1c06a86044ea Reviewed-on: https://skia-review.googlesource.com/9230 Reviewed-by: Cary Clark <caryclark@google.com> Commit-Queue: Cary Clark <caryclark@google.com>
166 lines
5.9 KiB
C++
166 lines
5.9 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 "SkArenaAlloc.h"
|
|
#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 "Test.h"
|
|
|
|
static SkBitmap make_bm(int w, int h) {
|
|
SkBitmap bm;
|
|
bm.allocN32Pixels(w, h);
|
|
return bm;
|
|
}
|
|
|
|
// TODO: can this be derived from SkBaseDevice?
|
|
class FakeDevice : public SkBitmapDevice {
|
|
public:
|
|
FakeDevice() : INHERITED(make_bm(100, 100), SkSurfaceProps(0, kUnknown_SkPixelGeometry)) {
|
|
}
|
|
|
|
void drawRect(const SkDraw& draw, const SkRect& r, const SkPaint& paint) override {
|
|
fLastMatrix = *draw.fMatrix;
|
|
this->INHERITED::drawRect(draw, r, paint);
|
|
}
|
|
|
|
SkMatrix fLastMatrix;
|
|
|
|
private:
|
|
typedef SkBitmapDevice INHERITED;
|
|
};
|
|
|
|
static void test_frontToBack(skiatest::Reporter* reporter) {
|
|
SkLayerDrawLooper::Builder looperBuilder;
|
|
SkLayerDrawLooper::LayerInfo layerInfo;
|
|
|
|
// Add the front layer, with the defaults.
|
|
(void)looperBuilder.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 = looperBuilder.addLayer(layerInfo);
|
|
layerPaint->setBlendMode(SkBlendMode::kSrc);
|
|
|
|
FakeDevice device;
|
|
SkCanvas canvas(&device);
|
|
SkPaint paint;
|
|
auto looper(looperBuilder.detach());
|
|
SkArenaAlloc alloc{48};
|
|
SkDrawLooper::Context* context = looper->makeContext(&canvas, &alloc);
|
|
|
|
// The back layer should come first.
|
|
REPORTER_ASSERT(reporter, context->next(&canvas, &paint));
|
|
REPORTER_ASSERT(reporter, paint.getBlendMode() == SkBlendMode::kSrc);
|
|
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, context->next(&canvas, &paint));
|
|
REPORTER_ASSERT(reporter, paint.getBlendMode() == SkBlendMode::kSrcOver);
|
|
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, !context->next(&canvas, &paint));
|
|
}
|
|
|
|
static void test_backToFront(skiatest::Reporter* reporter) {
|
|
SkLayerDrawLooper::Builder looperBuilder;
|
|
SkLayerDrawLooper::LayerInfo layerInfo;
|
|
|
|
// Add the back layer, with the defaults.
|
|
(void)looperBuilder.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 = looperBuilder.addLayerOnTop(layerInfo);
|
|
layerPaint->setBlendMode(SkBlendMode::kSrc);
|
|
|
|
FakeDevice device;
|
|
SkCanvas canvas(&device);
|
|
SkPaint paint;
|
|
auto looper(looperBuilder.detach());
|
|
SkArenaAlloc alloc{48};
|
|
SkDrawLooper::Context* context = looper->makeContext(&canvas, &alloc);
|
|
|
|
// The back layer should come first.
|
|
REPORTER_ASSERT(reporter, context->next(&canvas, &paint));
|
|
REPORTER_ASSERT(reporter, paint.getBlendMode() == SkBlendMode::kSrcOver);
|
|
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, context->next(&canvas, &paint));
|
|
REPORTER_ASSERT(reporter, paint.getBlendMode() == SkBlendMode::kSrc);
|
|
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, !context->next(&canvas, &paint));
|
|
}
|
|
|
|
static void test_mixed(skiatest::Reporter* reporter) {
|
|
SkLayerDrawLooper::Builder looperBuilder;
|
|
SkLayerDrawLooper::LayerInfo layerInfo;
|
|
|
|
// Add the back layer, with the defaults.
|
|
(void)looperBuilder.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 = looperBuilder.addLayerOnTop(layerInfo);
|
|
layerPaint->setBlendMode(SkBlendMode::kSrc);
|
|
|
|
FakeDevice device;
|
|
SkCanvas canvas(&device);
|
|
SkPaint paint;
|
|
sk_sp<SkDrawLooper> looper(looperBuilder.detach());
|
|
SkArenaAlloc alloc{48};
|
|
SkDrawLooper::Context* context = looper->makeContext(&canvas, &alloc);
|
|
|
|
// The back layer should come first.
|
|
REPORTER_ASSERT(reporter, context->next(&canvas, &paint));
|
|
REPORTER_ASSERT(reporter, paint.getBlendMode() == SkBlendMode::kSrcOver);
|
|
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, context->next(&canvas, &paint));
|
|
REPORTER_ASSERT(reporter, paint.getBlendMode() == SkBlendMode::kSrc);
|
|
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, !context->next(&canvas, &paint));
|
|
}
|
|
|
|
DEF_TEST(LayerDrawLooper, reporter) {
|
|
test_frontToBack(reporter);
|
|
test_backToFront(reporter);
|
|
test_mixed(reporter);
|
|
}
|