2013-05-22 12:35:50 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2013-10-12 17:25:17 +00:00
|
|
|
|
2017-02-08 20:12:19 +00:00
|
|
|
#include "SkArenaAlloc.h"
|
2013-05-22 12:35:50 +00:00
|
|
|
#include "SkBitmap.h"
|
2017-01-13 22:43:16 +00:00
|
|
|
#include "SkBitmapDevice.h"
|
2013-05-22 12:35:50 +00:00
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkDraw.h"
|
|
|
|
#include "SkLayerDrawLooper.h"
|
|
|
|
#include "SkMatrix.h"
|
|
|
|
#include "SkPaint.h"
|
|
|
|
#include "SkRect.h"
|
|
|
|
#include "SkRefCnt.h"
|
|
|
|
#include "SkScalar.h"
|
2014-01-24 20:56:26 +00:00
|
|
|
#include "Test.h"
|
2013-05-22 12:35:50 +00:00
|
|
|
|
2014-02-16 00:59:25 +00:00
|
|
|
static SkBitmap make_bm(int w, int h) {
|
|
|
|
SkBitmap bm;
|
|
|
|
bm.allocN32Pixels(w, h);
|
|
|
|
return bm;
|
|
|
|
}
|
|
|
|
|
2015-06-22 16:46:59 +00:00
|
|
|
// TODO: can this be derived from SkBaseDevice?
|
2013-08-29 11:54:56 +00:00
|
|
|
class FakeDevice : public SkBitmapDevice {
|
2013-05-22 12:35:50 +00:00
|
|
|
public:
|
2015-06-22 16:46:59 +00:00
|
|
|
FakeDevice() : INHERITED(make_bm(100, 100), SkSurfaceProps(0, kUnknown_SkPixelGeometry)) {
|
|
|
|
}
|
2013-05-22 12:35:50 +00:00
|
|
|
|
Revert "Revert "Revert "Revert[2] "Remove SkDraw from device-draw methods, and enable device-centric clipping."""""
This reverts commit 025e2444c1f5a0c3cdc0bf60d1fa59941a0b5db4.
Reason for revert: layouttest failures -- need to rebase these (tiny diffs in gradients)
https://storage.googleapis.com/chromium-layout-test-archives/linux_trusty_blink_rel/6018/layout-test-results/results.html
Original change's description:
> Revert "Revert "Revert[2] "Remove SkDraw from device-draw methods, and enable device-centric clipping.""""
>
> This reverts commit baf06bc89a0ee2ac4033281e7310f6c727faab79.
>
> Reason for revert: reland to diagnose possible g3 failure
>
> Original change's description:
> > Revert "Revert[2] "Remove SkDraw from device-draw methods, and enable device-centric clipping."""
> >
> > This reverts commit cfaa63237b152ae216f1351207bce3ea9808814c.
> >
> > 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 commit ea5e676a7b75600edcde3912886486004ccd7626.
> > >
> > > 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>
> >
>
> TBR=bsalomon@google.com,reviews@skia.org,caryclark@google.com,reed@google.com,mtklein@chromium.org
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=skia:
>
> Change-Id: I093fa8788056be39af01191bbf3a9e5de9f73954
> Reviewed-on: https://skia-review.googlesource.com/9244
> Reviewed-by: Mike Reed <reed@google.com>
> Commit-Queue: Mike Reed <reed@google.com>
>
TBR=mtklein@chromium.org,bsalomon@google.com,reviews@skia.org,caryclark@google.com,reed@google.com
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=skia:
Change-Id: I58f810a8ff241dbaf3133e2fe844548fcd0fa67a
Reviewed-on: https://skia-review.googlesource.com/9245
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
2017-03-04 21:47:47 +00:00
|
|
|
void drawRect(const SkDraw& draw, const SkRect& r, const SkPaint& paint) override {
|
|
|
|
fLastMatrix = *draw.fMatrix;
|
|
|
|
this->INHERITED::drawRect(draw, r, paint);
|
2013-05-22 12:35:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SkMatrix fLastMatrix;
|
2013-08-29 11:54:56 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
typedef SkBitmapDevice INHERITED;
|
2013-05-22 12:35:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void test_frontToBack(skiatest::Reporter* reporter) {
|
2014-02-14 10:06:42 +00:00
|
|
|
SkLayerDrawLooper::Builder looperBuilder;
|
2013-05-22 12:35:50 +00:00
|
|
|
SkLayerDrawLooper::LayerInfo layerInfo;
|
|
|
|
|
|
|
|
// Add the front layer, with the defaults.
|
2014-02-14 10:06:42 +00:00
|
|
|
(void)looperBuilder.addLayer(layerInfo);
|
2013-05-22 12:35:50 +00:00
|
|
|
|
|
|
|
// Add the back layer, with some layer info set.
|
2013-11-25 19:44:07 +00:00
|
|
|
layerInfo.fOffset.set(10.0f, 20.0f);
|
2013-05-22 12:35:50 +00:00
|
|
|
layerInfo.fPaintBits |= SkLayerDrawLooper::kXfermode_Bit;
|
2014-02-14 10:06:42 +00:00
|
|
|
SkPaint* layerPaint = looperBuilder.addLayer(layerInfo);
|
2016-10-06 00:33:02 +00:00
|
|
|
layerPaint->setBlendMode(SkBlendMode::kSrc);
|
2013-05-22 12:35:50 +00:00
|
|
|
|
|
|
|
FakeDevice device;
|
|
|
|
SkCanvas canvas(&device);
|
|
|
|
SkPaint paint;
|
2016-03-21 20:25:16 +00:00
|
|
|
auto looper(looperBuilder.detach());
|
2017-02-08 20:12:19 +00:00
|
|
|
SkArenaAlloc alloc{48};
|
|
|
|
SkDrawLooper::Context* context = looper->makeContext(&canvas, &alloc);
|
2013-05-22 12:35:50 +00:00
|
|
|
|
|
|
|
// The back layer should come first.
|
2014-03-12 09:42:01 +00:00
|
|
|
REPORTER_ASSERT(reporter, context->next(&canvas, &paint));
|
2016-10-06 00:33:02 +00:00
|
|
|
REPORTER_ASSERT(reporter, paint.getBlendMode() == SkBlendMode::kSrc);
|
2013-11-25 19:44:07 +00:00
|
|
|
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());
|
2013-05-22 12:35:50 +00:00
|
|
|
paint.reset();
|
|
|
|
|
|
|
|
// Then the front layer.
|
2014-03-12 09:42:01 +00:00
|
|
|
REPORTER_ASSERT(reporter, context->next(&canvas, &paint));
|
2016-10-06 00:33:02 +00:00
|
|
|
REPORTER_ASSERT(reporter, paint.getBlendMode() == SkBlendMode::kSrcOver);
|
2013-11-25 19:44:07 +00:00
|
|
|
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());
|
2013-05-22 12:35:50 +00:00
|
|
|
|
|
|
|
// Only two layers were added, so that should be the end.
|
2014-03-12 09:42:01 +00:00
|
|
|
REPORTER_ASSERT(reporter, !context->next(&canvas, &paint));
|
2013-05-22 12:35:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_backToFront(skiatest::Reporter* reporter) {
|
2014-02-14 10:06:42 +00:00
|
|
|
SkLayerDrawLooper::Builder looperBuilder;
|
2013-05-22 12:35:50 +00:00
|
|
|
SkLayerDrawLooper::LayerInfo layerInfo;
|
|
|
|
|
|
|
|
// Add the back layer, with the defaults.
|
2014-02-14 10:06:42 +00:00
|
|
|
(void)looperBuilder.addLayerOnTop(layerInfo);
|
2013-05-22 12:35:50 +00:00
|
|
|
|
|
|
|
// Add the front layer, with some layer info set.
|
2013-11-25 19:44:07 +00:00
|
|
|
layerInfo.fOffset.set(10.0f, 20.0f);
|
2013-05-22 12:35:50 +00:00
|
|
|
layerInfo.fPaintBits |= SkLayerDrawLooper::kXfermode_Bit;
|
2014-02-14 10:06:42 +00:00
|
|
|
SkPaint* layerPaint = looperBuilder.addLayerOnTop(layerInfo);
|
2016-10-06 00:33:02 +00:00
|
|
|
layerPaint->setBlendMode(SkBlendMode::kSrc);
|
2013-05-22 12:35:50 +00:00
|
|
|
|
|
|
|
FakeDevice device;
|
|
|
|
SkCanvas canvas(&device);
|
|
|
|
SkPaint paint;
|
2016-03-21 20:25:16 +00:00
|
|
|
auto looper(looperBuilder.detach());
|
2017-02-08 20:12:19 +00:00
|
|
|
SkArenaAlloc alloc{48};
|
|
|
|
SkDrawLooper::Context* context = looper->makeContext(&canvas, &alloc);
|
2013-05-22 12:35:50 +00:00
|
|
|
|
|
|
|
// The back layer should come first.
|
2014-03-12 09:42:01 +00:00
|
|
|
REPORTER_ASSERT(reporter, context->next(&canvas, &paint));
|
2016-10-06 00:33:02 +00:00
|
|
|
REPORTER_ASSERT(reporter, paint.getBlendMode() == SkBlendMode::kSrcOver);
|
2013-11-25 19:44:07 +00:00
|
|
|
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());
|
2013-05-22 12:35:50 +00:00
|
|
|
paint.reset();
|
|
|
|
|
|
|
|
// Then the front layer.
|
2014-03-12 09:42:01 +00:00
|
|
|
REPORTER_ASSERT(reporter, context->next(&canvas, &paint));
|
2016-10-06 00:33:02 +00:00
|
|
|
REPORTER_ASSERT(reporter, paint.getBlendMode() == SkBlendMode::kSrc);
|
2013-11-25 19:44:07 +00:00
|
|
|
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());
|
2013-05-22 12:35:50 +00:00
|
|
|
|
|
|
|
// Only two layers were added, so that should be the end.
|
2014-03-12 09:42:01 +00:00
|
|
|
REPORTER_ASSERT(reporter, !context->next(&canvas, &paint));
|
2013-05-22 12:35:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_mixed(skiatest::Reporter* reporter) {
|
2014-02-14 10:06:42 +00:00
|
|
|
SkLayerDrawLooper::Builder looperBuilder;
|
2013-05-22 12:35:50 +00:00
|
|
|
SkLayerDrawLooper::LayerInfo layerInfo;
|
|
|
|
|
|
|
|
// Add the back layer, with the defaults.
|
2014-02-14 10:06:42 +00:00
|
|
|
(void)looperBuilder.addLayer(layerInfo);
|
2013-05-22 12:35:50 +00:00
|
|
|
|
|
|
|
// Add the front layer, with some layer info set.
|
2013-11-25 19:44:07 +00:00
|
|
|
layerInfo.fOffset.set(10.0f, 20.0f);
|
2013-05-22 12:35:50 +00:00
|
|
|
layerInfo.fPaintBits |= SkLayerDrawLooper::kXfermode_Bit;
|
2014-02-14 10:06:42 +00:00
|
|
|
SkPaint* layerPaint = looperBuilder.addLayerOnTop(layerInfo);
|
2016-10-06 00:33:02 +00:00
|
|
|
layerPaint->setBlendMode(SkBlendMode::kSrc);
|
2013-05-22 12:35:50 +00:00
|
|
|
|
|
|
|
FakeDevice device;
|
|
|
|
SkCanvas canvas(&device);
|
|
|
|
SkPaint paint;
|
2016-03-21 20:25:16 +00:00
|
|
|
sk_sp<SkDrawLooper> looper(looperBuilder.detach());
|
2017-02-08 20:12:19 +00:00
|
|
|
SkArenaAlloc alloc{48};
|
|
|
|
SkDrawLooper::Context* context = looper->makeContext(&canvas, &alloc);
|
2013-05-22 12:35:50 +00:00
|
|
|
|
|
|
|
// The back layer should come first.
|
2014-03-12 09:42:01 +00:00
|
|
|
REPORTER_ASSERT(reporter, context->next(&canvas, &paint));
|
2016-10-06 00:33:02 +00:00
|
|
|
REPORTER_ASSERT(reporter, paint.getBlendMode() == SkBlendMode::kSrcOver);
|
2013-11-25 19:44:07 +00:00
|
|
|
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());
|
2013-05-22 12:35:50 +00:00
|
|
|
paint.reset();
|
|
|
|
|
|
|
|
// Then the front layer.
|
2014-03-12 09:42:01 +00:00
|
|
|
REPORTER_ASSERT(reporter, context->next(&canvas, &paint));
|
2016-10-06 00:33:02 +00:00
|
|
|
REPORTER_ASSERT(reporter, paint.getBlendMode() == SkBlendMode::kSrc);
|
2013-11-25 19:44:07 +00:00
|
|
|
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());
|
2013-05-22 12:35:50 +00:00
|
|
|
|
|
|
|
// Only two layers were added, so that should be the end.
|
2014-03-12 09:42:01 +00:00
|
|
|
REPORTER_ASSERT(reporter, !context->next(&canvas, &paint));
|
2013-05-22 12:35:50 +00:00
|
|
|
}
|
|
|
|
|
2013-12-12 21:11:12 +00:00
|
|
|
DEF_TEST(LayerDrawLooper, reporter) {
|
2013-05-22 12:35:50 +00:00
|
|
|
test_frontToBack(reporter);
|
|
|
|
test_backToFront(reporter);
|
|
|
|
test_mixed(reporter);
|
|
|
|
}
|