2014-04-30 13:18:12 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tests/RecordTestUtils.h"
|
|
|
|
#include "tests/Test.h"
|
2014-04-30 13:18:12 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkColorFilter.h"
|
|
|
|
#include "include/core/SkPictureRecorder.h"
|
|
|
|
#include "include/core/SkSurface.h"
|
2019-08-05 14:41:10 +00:00
|
|
|
#include "include/effects/SkImageFilters.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/core/SkRecord.h"
|
|
|
|
#include "src/core/SkRecordOpts.h"
|
|
|
|
#include "src/core/SkRecorder.h"
|
|
|
|
#include "src/core/SkRecords.h"
|
2014-05-07 14:47:44 +00:00
|
|
|
|
2014-04-30 13:18:12 +00:00
|
|
|
static const int W = 1920, H = 1080;
|
|
|
|
|
2014-12-11 15:07:37 +00:00
|
|
|
DEF_TEST(RecordOpts_NoopDraw, r) {
|
2014-05-07 17:17:48 +00:00
|
|
|
SkRecord record;
|
2014-05-29 16:52:40 +00:00
|
|
|
SkRecorder recorder(&record, W, H);
|
2014-05-07 17:17:48 +00:00
|
|
|
|
2014-12-11 15:07:37 +00:00
|
|
|
recorder.drawRect(SkRect::MakeWH(200, 200), SkPaint());
|
|
|
|
recorder.drawRect(SkRect::MakeWH(300, 300), SkPaint());
|
|
|
|
recorder.drawRect(SkRect::MakeWH(100, 100), SkPaint());
|
2014-05-07 17:17:48 +00:00
|
|
|
|
2014-12-11 15:07:37 +00:00
|
|
|
record.replace<SkRecords::NoOp>(1); // NoOps should be allowed.
|
2014-05-07 17:17:48 +00:00
|
|
|
|
|
|
|
SkRecordNoopSaveRestores(&record);
|
|
|
|
|
2014-12-11 15:07:37 +00:00
|
|
|
REPORTER_ASSERT(r, 2 == count_instances_of_type<SkRecords::DrawRect>(record));
|
2014-05-07 17:17:48 +00:00
|
|
|
}
|
|
|
|
|
2014-05-05 17:09:05 +00:00
|
|
|
DEF_TEST(RecordOpts_SingleNoopSaveRestore, r) {
|
|
|
|
SkRecord record;
|
2014-05-29 16:52:40 +00:00
|
|
|
SkRecorder recorder(&record, W, H);
|
2014-05-05 17:09:05 +00:00
|
|
|
|
|
|
|
recorder.save();
|
|
|
|
recorder.clipRect(SkRect::MakeWH(200, 200));
|
|
|
|
recorder.restore();
|
|
|
|
|
|
|
|
SkRecordNoopSaveRestores(&record);
|
2015-08-19 16:51:00 +00:00
|
|
|
for (int i = 0; i < 3; i++) {
|
2014-05-05 17:09:05 +00:00
|
|
|
assert_type<SkRecords::NoOp>(r, record, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-30 13:18:12 +00:00
|
|
|
DEF_TEST(RecordOpts_NoopSaveRestores, r) {
|
|
|
|
SkRecord record;
|
2014-05-29 16:52:40 +00:00
|
|
|
SkRecorder recorder(&record, W, H);
|
2014-04-30 13:18:12 +00:00
|
|
|
|
|
|
|
// The second pass will clean up this pair after the first pass noops all the innards.
|
|
|
|
recorder.save();
|
|
|
|
// A simple pointless pair of save/restore.
|
|
|
|
recorder.save();
|
|
|
|
recorder.restore();
|
|
|
|
|
|
|
|
// As long as we don't draw in there, everything is a noop.
|
|
|
|
recorder.save();
|
|
|
|
recorder.clipRect(SkRect::MakeWH(200, 200));
|
|
|
|
recorder.clipRect(SkRect::MakeWH(100, 100));
|
|
|
|
recorder.restore();
|
|
|
|
recorder.restore();
|
|
|
|
|
|
|
|
SkRecordNoopSaveRestores(&record);
|
2015-08-19 16:51:00 +00:00
|
|
|
for (int index = 0; index < record.count(); index++) {
|
2014-05-05 17:09:05 +00:00
|
|
|
assert_type<SkRecords::NoOp>(r, record, index);
|
2014-04-30 13:18:12 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-07 14:47:44 +00:00
|
|
|
|
2014-09-10 23:08:27 +00:00
|
|
|
DEF_TEST(RecordOpts_SaveSaveLayerRestoreRestore, r) {
|
|
|
|
SkRecord record;
|
|
|
|
SkRecorder recorder(&record, W, H);
|
|
|
|
|
|
|
|
// A previous bug NoOp'd away the first 3 commands.
|
|
|
|
recorder.save();
|
2015-08-27 14:41:13 +00:00
|
|
|
recorder.saveLayer(nullptr, nullptr);
|
2014-09-10 23:08:27 +00:00
|
|
|
recorder.restore();
|
|
|
|
recorder.restore();
|
|
|
|
|
|
|
|
SkRecordNoopSaveRestores(&record);
|
2014-12-11 15:07:37 +00:00
|
|
|
switch (record.count()) {
|
|
|
|
case 4:
|
|
|
|
assert_type<SkRecords::Save> (r, record, 0);
|
|
|
|
assert_type<SkRecords::SaveLayer>(r, record, 1);
|
|
|
|
assert_type<SkRecords::Restore> (r, record, 2);
|
|
|
|
assert_type<SkRecords::Restore> (r, record, 3);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
assert_type<SkRecords::SaveLayer>(r, record, 0);
|
|
|
|
assert_type<SkRecords::Restore> (r, record, 1);
|
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
REPORTER_ASSERT(r, false);
|
|
|
|
}
|
2014-09-10 23:08:27 +00:00
|
|
|
}
|
|
|
|
|
2017-03-06 20:47:09 +00:00
|
|
|
#ifndef SK_BUILD_FOR_ANDROID_FRAMEWORK
|
2014-05-07 14:47:44 +00:00
|
|
|
static void assert_savelayer_restore(skiatest::Reporter* r,
|
|
|
|
SkRecord* record,
|
2015-08-19 16:51:00 +00:00
|
|
|
int i,
|
2014-05-07 14:47:44 +00:00
|
|
|
bool shouldBeNoOped) {
|
|
|
|
SkRecordNoopSaveLayerDrawRestores(record);
|
2016-01-07 19:28:08 +00:00
|
|
|
if (shouldBeNoOped) {
|
|
|
|
assert_type<SkRecords::NoOp>(r, *record, i);
|
|
|
|
assert_type<SkRecords::NoOp>(r, *record, i+1);
|
|
|
|
} else {
|
|
|
|
assert_type<SkRecords::SaveLayer>(r, *record, i);
|
|
|
|
assert_type<SkRecords::Restore>(r, *record, i+1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void assert_savelayer_draw_restore(skiatest::Reporter* r,
|
|
|
|
SkRecord* record,
|
|
|
|
int i,
|
|
|
|
bool shouldBeNoOped) {
|
|
|
|
SkRecordNoopSaveLayerDrawRestores(record);
|
2014-05-07 14:47:44 +00:00
|
|
|
if (shouldBeNoOped) {
|
|
|
|
assert_type<SkRecords::NoOp>(r, *record, i);
|
|
|
|
assert_type<SkRecords::NoOp>(r, *record, i+2);
|
|
|
|
} else {
|
|
|
|
assert_type<SkRecords::SaveLayer>(r, *record, i);
|
|
|
|
assert_type<SkRecords::Restore>(r, *record, i+2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(RecordOpts_NoopSaveLayerDrawRestore, r) {
|
|
|
|
SkRecord record;
|
2014-05-29 16:52:40 +00:00
|
|
|
SkRecorder recorder(&record, W, H);
|
2014-05-07 14:47:44 +00:00
|
|
|
|
|
|
|
SkRect bounds = SkRect::MakeWH(100, 200);
|
|
|
|
SkRect draw = SkRect::MakeWH(50, 60);
|
|
|
|
|
2015-01-16 13:04:36 +00:00
|
|
|
SkPaint alphaOnlyLayerPaint, translucentLayerPaint, xfermodeLayerPaint;
|
|
|
|
alphaOnlyLayerPaint.setColor(0x03000000); // Only alpha.
|
|
|
|
translucentLayerPaint.setColor(0x03040506); // Not only alpha.
|
2016-10-06 00:33:02 +00:00
|
|
|
xfermodeLayerPaint.setBlendMode(SkBlendMode::kDstIn); // Any effect will do.
|
2014-05-07 14:47:44 +00:00
|
|
|
|
2015-01-16 13:04:36 +00:00
|
|
|
SkPaint opaqueDrawPaint, translucentDrawPaint;
|
|
|
|
opaqueDrawPaint.setColor(0xFF020202); // Opaque.
|
|
|
|
translucentDrawPaint.setColor(0x0F020202); // Not opaque.
|
2014-05-07 14:47:44 +00:00
|
|
|
|
2015-01-15 16:08:10 +00:00
|
|
|
// SaveLayer/Restore removed: No paint = no point.
|
2015-08-27 14:41:13 +00:00
|
|
|
recorder.saveLayer(nullptr, nullptr);
|
2015-01-16 13:04:36 +00:00
|
|
|
recorder.drawRect(draw, opaqueDrawPaint);
|
2014-05-07 14:47:44 +00:00
|
|
|
recorder.restore();
|
2016-01-07 19:28:08 +00:00
|
|
|
assert_savelayer_draw_restore(r, &record, 0, true);
|
2014-05-07 14:47:44 +00:00
|
|
|
|
2015-01-15 16:08:10 +00:00
|
|
|
// Bounds don't matter.
|
2015-08-27 14:41:13 +00:00
|
|
|
recorder.saveLayer(&bounds, nullptr);
|
2015-01-16 13:04:36 +00:00
|
|
|
recorder.drawRect(draw, opaqueDrawPaint);
|
2014-05-07 14:47:44 +00:00
|
|
|
recorder.restore();
|
2016-01-07 19:28:08 +00:00
|
|
|
assert_savelayer_draw_restore(r, &record, 3, true);
|
2014-05-07 14:47:44 +00:00
|
|
|
|
|
|
|
// TODO(mtklein): test case with null draw paint
|
|
|
|
|
|
|
|
// No change: layer paint isn't alpha-only.
|
2015-08-27 14:41:13 +00:00
|
|
|
recorder.saveLayer(nullptr, &translucentLayerPaint);
|
2015-01-16 13:04:36 +00:00
|
|
|
recorder.drawRect(draw, opaqueDrawPaint);
|
2014-05-07 14:47:44 +00:00
|
|
|
recorder.restore();
|
2016-01-07 19:28:08 +00:00
|
|
|
assert_savelayer_draw_restore(r, &record, 6, false);
|
2014-05-07 14:47:44 +00:00
|
|
|
|
|
|
|
// No change: layer paint has an effect.
|
2015-08-27 14:41:13 +00:00
|
|
|
recorder.saveLayer(nullptr, &xfermodeLayerPaint);
|
2015-01-16 13:04:36 +00:00
|
|
|
recorder.drawRect(draw, opaqueDrawPaint);
|
2014-05-07 14:47:44 +00:00
|
|
|
recorder.restore();
|
2016-01-07 19:28:08 +00:00
|
|
|
assert_savelayer_draw_restore(r, &record, 9, false);
|
2014-05-07 14:47:44 +00:00
|
|
|
|
2015-01-16 13:04:36 +00:00
|
|
|
// SaveLayer/Restore removed: we can fold in the alpha!
|
2015-08-27 14:41:13 +00:00
|
|
|
recorder.saveLayer(nullptr, &alphaOnlyLayerPaint);
|
2015-01-16 13:04:36 +00:00
|
|
|
recorder.drawRect(draw, translucentDrawPaint);
|
2014-05-07 14:47:44 +00:00
|
|
|
recorder.restore();
|
2016-01-07 19:28:08 +00:00
|
|
|
assert_savelayer_draw_restore(r, &record, 12, true);
|
2014-05-07 14:47:44 +00:00
|
|
|
|
|
|
|
// SaveLayer/Restore removed: we can fold in the alpha!
|
2015-08-27 14:41:13 +00:00
|
|
|
recorder.saveLayer(nullptr, &alphaOnlyLayerPaint);
|
2015-01-16 13:04:36 +00:00
|
|
|
recorder.drawRect(draw, opaqueDrawPaint);
|
2014-05-07 14:47:44 +00:00
|
|
|
recorder.restore();
|
2016-01-07 19:28:08 +00:00
|
|
|
assert_savelayer_draw_restore(r, &record, 15, true);
|
2014-05-07 14:47:44 +00:00
|
|
|
|
|
|
|
const SkRecords::DrawRect* drawRect = assert_type<SkRecords::DrawRect>(r, record, 16);
|
2015-08-27 14:41:13 +00:00
|
|
|
REPORTER_ASSERT(r, drawRect != nullptr);
|
2014-05-07 14:47:44 +00:00
|
|
|
REPORTER_ASSERT(r, drawRect->paint.getColor() == 0x03020202);
|
2016-01-07 19:28:08 +00:00
|
|
|
|
|
|
|
// saveLayer w/ backdrop should NOT go away
|
2019-08-05 14:41:10 +00:00
|
|
|
sk_sp<SkImageFilter> filter(SkImageFilters::Blur(3, 3, nullptr));
|
2017-04-28 17:48:37 +00:00
|
|
|
recorder.saveLayer({ nullptr, nullptr, filter.get(), nullptr, nullptr, 0});
|
2016-01-07 19:28:08 +00:00
|
|
|
recorder.drawRect(draw, opaqueDrawPaint);
|
|
|
|
recorder.restore();
|
|
|
|
assert_savelayer_draw_restore(r, &record, 18, false);
|
2017-04-28 17:48:37 +00:00
|
|
|
|
|
|
|
// saveLayer w/ clip mask should also NOT go away
|
|
|
|
{
|
|
|
|
sk_sp<SkSurface> surface(SkSurface::MakeRasterN32Premul(10, 10));
|
2017-05-01 21:34:14 +00:00
|
|
|
recorder.saveLayer({ nullptr, nullptr, nullptr, surface->makeImageSnapshot().get(),
|
|
|
|
nullptr, 0});
|
2017-04-28 17:48:37 +00:00
|
|
|
recorder.drawRect(draw, opaqueDrawPaint);
|
|
|
|
recorder.restore();
|
|
|
|
assert_savelayer_draw_restore(r, &record, 21, false);
|
|
|
|
}
|
2014-05-07 14:47:44 +00:00
|
|
|
}
|
2017-03-06 20:47:09 +00:00
|
|
|
#endif
|
2015-01-26 08:14:26 +00:00
|
|
|
|
|
|
|
static void assert_merge_svg_opacity_and_filter_layers(skiatest::Reporter* r,
|
|
|
|
SkRecord* record,
|
2015-08-19 16:51:00 +00:00
|
|
|
int i,
|
2015-01-26 08:14:26 +00:00
|
|
|
bool shouldBeNoOped) {
|
|
|
|
SkRecordMergeSvgOpacityAndFilterLayers(record);
|
|
|
|
if (shouldBeNoOped) {
|
|
|
|
assert_type<SkRecords::NoOp>(r, *record, i);
|
|
|
|
assert_type<SkRecords::NoOp>(r, *record, i + 6);
|
|
|
|
} else {
|
|
|
|
assert_type<SkRecords::SaveLayer>(r, *record, i);
|
|
|
|
assert_type<SkRecords::Restore>(r, *record, i + 6);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(RecordOpts_MergeSvgOpacityAndFilterLayers, r) {
|
|
|
|
SkRecord record;
|
|
|
|
SkRecorder recorder(&record, W, H);
|
|
|
|
|
|
|
|
SkRect bounds = SkRect::MakeWH(SkIntToScalar(100), SkIntToScalar(200));
|
|
|
|
SkRect clip = SkRect::MakeWH(SkIntToScalar(50), SkIntToScalar(60));
|
|
|
|
|
|
|
|
SkPaint alphaOnlyLayerPaint;
|
|
|
|
alphaOnlyLayerPaint.setColor(0x03000000); // Only alpha.
|
|
|
|
SkPaint translucentLayerPaint;
|
|
|
|
translucentLayerPaint.setColor(0x03040506); // Not only alpha.
|
|
|
|
SkPaint xfermodePaint;
|
2016-10-06 00:33:02 +00:00
|
|
|
xfermodePaint.setBlendMode(SkBlendMode::kDstIn);
|
2015-01-26 08:14:26 +00:00
|
|
|
SkPaint colorFilterPaint;
|
|
|
|
colorFilterPaint.setColorFilter(
|
2019-04-08 20:23:20 +00:00
|
|
|
SkColorFilters::Blend(SK_ColorLTGRAY, SkBlendMode::kSrcIn));
|
2015-01-26 08:14:26 +00:00
|
|
|
|
|
|
|
SkPaint opaqueFilterLayerPaint;
|
|
|
|
opaqueFilterLayerPaint.setColor(0xFF020202); // Opaque.
|
|
|
|
SkPaint translucentFilterLayerPaint;
|
|
|
|
translucentFilterLayerPaint.setColor(0x0F020202); // Not opaque.
|
2016-03-18 14:25:55 +00:00
|
|
|
sk_sp<SkPicture> shape;
|
2015-01-26 08:14:26 +00:00
|
|
|
{
|
|
|
|
SkPictureRecorder recorder;
|
|
|
|
SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(100), SkIntToScalar(100));
|
|
|
|
SkPaint shapePaint;
|
|
|
|
shapePaint.setColor(SK_ColorWHITE);
|
|
|
|
canvas->drawRect(SkRect::MakeWH(SkIntToScalar(50), SkIntToScalar(50)), shapePaint);
|
2016-03-18 14:25:55 +00:00
|
|
|
shape = recorder.finishRecordingAsPicture();
|
2015-01-26 08:14:26 +00:00
|
|
|
}
|
2019-08-05 14:41:10 +00:00
|
|
|
translucentFilterLayerPaint.setImageFilter(SkImageFilters::Picture(shape));
|
2015-01-26 08:14:26 +00:00
|
|
|
|
|
|
|
int index = 0;
|
|
|
|
|
|
|
|
{
|
2019-08-05 14:41:10 +00:00
|
|
|
sk_sp<SkImageFilter> filter(SkImageFilters::Blur(3, 3, nullptr));
|
2016-01-07 19:28:08 +00:00
|
|
|
// first (null) should be optimized, 2nd should not
|
|
|
|
SkImageFilter* filters[] = { nullptr, filter.get() };
|
|
|
|
|
2015-01-26 08:14:26 +00:00
|
|
|
// Any combination of these should cause the pattern to be optimized.
|
2015-08-27 14:41:13 +00:00
|
|
|
SkRect* firstBounds[] = { nullptr, &bounds };
|
|
|
|
SkPaint* firstPaints[] = { nullptr, &alphaOnlyLayerPaint };
|
|
|
|
SkRect* secondBounds[] = { nullptr, &bounds };
|
2015-01-26 08:14:26 +00:00
|
|
|
SkPaint* secondPaints[] = { &opaqueFilterLayerPaint, &translucentFilterLayerPaint };
|
|
|
|
|
2016-01-07 19:28:08 +00:00
|
|
|
for (auto outerF : filters) {
|
|
|
|
bool outerNoOped = !outerF;
|
|
|
|
for (auto innerF : filters) {
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(firstBounds); ++ i) {
|
|
|
|
for (size_t j = 0; j < SK_ARRAY_COUNT(firstPaints); ++j) {
|
|
|
|
for (size_t k = 0; k < SK_ARRAY_COUNT(secondBounds); ++k) {
|
|
|
|
for (size_t m = 0; m < SK_ARRAY_COUNT(secondPaints); ++m) {
|
|
|
|
bool innerNoOped = !secondBounds[k] && !secondPaints[m] && !innerF;
|
|
|
|
|
2017-04-28 17:48:37 +00:00
|
|
|
recorder.saveLayer({firstBounds[i], firstPaints[j], outerF,
|
|
|
|
nullptr, nullptr, 0});
|
2016-01-07 19:28:08 +00:00
|
|
|
recorder.save();
|
|
|
|
recorder.clipRect(clip);
|
2017-04-28 17:48:37 +00:00
|
|
|
recorder.saveLayer({secondBounds[k], secondPaints[m], innerF,
|
|
|
|
nullptr, nullptr, 0});
|
2016-01-07 19:28:08 +00:00
|
|
|
recorder.restore();
|
|
|
|
recorder.restore();
|
|
|
|
recorder.restore();
|
|
|
|
assert_merge_svg_opacity_and_filter_layers(r, &record, index,
|
|
|
|
outerNoOped);
|
2017-03-07 01:02:32 +00:00
|
|
|
#ifndef SK_BUILD_FOR_ANDROID_FRAMEWORK
|
2016-01-07 19:28:08 +00:00
|
|
|
assert_savelayer_restore(r, &record, index + 3, innerNoOped);
|
2017-03-07 01:02:32 +00:00
|
|
|
#endif
|
2016-01-07 19:28:08 +00:00
|
|
|
index += 7;
|
|
|
|
}
|
|
|
|
}
|
2015-01-26 08:14:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// These should cause the pattern to stay unoptimized:
|
|
|
|
struct {
|
|
|
|
SkPaint* firstPaint;
|
|
|
|
SkPaint* secondPaint;
|
|
|
|
} noChangeTests[] = {
|
2015-08-27 14:41:13 +00:00
|
|
|
// No change: nullptr filter layer paint not implemented.
|
|
|
|
{ &alphaOnlyLayerPaint, nullptr },
|
2015-01-26 08:14:26 +00:00
|
|
|
// No change: layer paint is not alpha-only.
|
|
|
|
{ &translucentLayerPaint, &opaqueFilterLayerPaint },
|
|
|
|
// No change: layer paint has an xfereffect.
|
|
|
|
{ &xfermodePaint, &opaqueFilterLayerPaint },
|
|
|
|
// No change: filter layer paint has an xfereffect.
|
|
|
|
{ &alphaOnlyLayerPaint, &xfermodePaint },
|
|
|
|
// No change: layer paint has a color filter.
|
|
|
|
{ &colorFilterPaint, &opaqueFilterLayerPaint },
|
|
|
|
// No change: filter layer paint has a color filter (until the optimization accounts for
|
|
|
|
// constant color draws that can filter the color).
|
|
|
|
{ &alphaOnlyLayerPaint, &colorFilterPaint }
|
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(noChangeTests); ++i) {
|
2015-08-27 14:41:13 +00:00
|
|
|
recorder.saveLayer(nullptr, noChangeTests[i].firstPaint);
|
2015-01-26 08:14:26 +00:00
|
|
|
recorder.save();
|
|
|
|
recorder.clipRect(clip);
|
2015-08-27 14:41:13 +00:00
|
|
|
recorder.saveLayer(nullptr, noChangeTests[i].secondPaint);
|
2015-01-26 08:14:26 +00:00
|
|
|
recorder.restore();
|
|
|
|
recorder.restore();
|
|
|
|
recorder.restore();
|
|
|
|
assert_merge_svg_opacity_and_filter_layers(r, &record, index, false);
|
|
|
|
index += 7;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test the folded alpha value.
|
2015-08-27 14:41:13 +00:00
|
|
|
recorder.saveLayer(nullptr, &alphaOnlyLayerPaint);
|
2015-01-26 08:14:26 +00:00
|
|
|
recorder.save();
|
|
|
|
recorder.clipRect(clip);
|
2015-08-27 14:41:13 +00:00
|
|
|
recorder.saveLayer(nullptr, &opaqueFilterLayerPaint);
|
2015-01-26 08:14:26 +00:00
|
|
|
recorder.restore();
|
|
|
|
recorder.restore();
|
|
|
|
recorder.restore();
|
|
|
|
assert_merge_svg_opacity_and_filter_layers(r, &record, index, true);
|
|
|
|
|
|
|
|
const SkRecords::SaveLayer* saveLayer = assert_type<SkRecords::SaveLayer>(r, record, index + 3);
|
2015-08-27 14:41:13 +00:00
|
|
|
REPORTER_ASSERT(r, saveLayer != nullptr);
|
2015-01-26 08:14:26 +00:00
|
|
|
REPORTER_ASSERT(r, saveLayer->paint->getColor() == 0x03020202);
|
|
|
|
|
|
|
|
index += 7;
|
|
|
|
|
|
|
|
// Test that currently we do not fold alphas for patterns without the clip. This is just not
|
|
|
|
// implemented.
|
2015-08-27 14:41:13 +00:00
|
|
|
recorder.saveLayer(nullptr, &alphaOnlyLayerPaint);
|
|
|
|
recorder.saveLayer(nullptr, &opaqueFilterLayerPaint);
|
2015-01-26 08:14:26 +00:00
|
|
|
recorder.restore();
|
|
|
|
recorder.restore();
|
|
|
|
SkRecordMergeSvgOpacityAndFilterLayers(&record);
|
|
|
|
assert_type<SkRecords::SaveLayer>(r, record, index);
|
|
|
|
assert_type<SkRecords::SaveLayer>(r, record, index + 1);
|
|
|
|
assert_type<SkRecords::Restore>(r, record, index + 2);
|
|
|
|
assert_type<SkRecords::Restore>(r, record, index + 3);
|
|
|
|
index += 4;
|
|
|
|
}
|
2016-09-06 13:54:41 +00:00
|
|
|
|
|
|
|
static void do_draw(SkCanvas* canvas, SkColor color, bool doLayer) {
|
|
|
|
canvas->drawColor(SK_ColorWHITE);
|
|
|
|
|
|
|
|
SkPaint p;
|
|
|
|
p.setColor(color);
|
|
|
|
|
|
|
|
if (doLayer) {
|
|
|
|
canvas->saveLayer(nullptr, nullptr);
|
2016-10-06 00:33:02 +00:00
|
|
|
p.setBlendMode(SkBlendMode::kSrc);
|
2016-09-06 13:54:41 +00:00
|
|
|
canvas->drawPaint(p);
|
|
|
|
canvas->restore();
|
|
|
|
} else {
|
|
|
|
canvas->drawPaint(p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool is_equal(SkSurface* a, SkSurface* b) {
|
|
|
|
const SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1);
|
|
|
|
SkPMColor ca, cb;
|
|
|
|
a->readPixels(info, &ca, sizeof(SkPMColor), 0, 0);
|
|
|
|
b->readPixels(info, &cb, sizeof(SkPMColor), 0, 0);
|
|
|
|
return ca == cb;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test drawing w/ and w/o a simple layer (no bounds or paint), so see that drawing ops
|
|
|
|
// that *should* draw the same in fact do.
|
|
|
|
//
|
|
|
|
// Perform this test twice : once directly, and once via a picture
|
|
|
|
//
|
|
|
|
static void do_savelayer_srcmode(skiatest::Reporter* r, SkColor color) {
|
|
|
|
for (int doPicture = 0; doPicture <= 1; ++doPicture) {
|
|
|
|
sk_sp<SkSurface> surf0 = SkSurface::MakeRasterN32Premul(10, 10);
|
|
|
|
sk_sp<SkSurface> surf1 = SkSurface::MakeRasterN32Premul(10, 10);
|
|
|
|
SkCanvas* c0 = surf0->getCanvas();
|
|
|
|
SkCanvas* c1 = surf1->getCanvas();
|
|
|
|
|
|
|
|
SkPictureRecorder rec0, rec1;
|
|
|
|
if (doPicture) {
|
|
|
|
c0 = rec0.beginRecording(10, 10);
|
|
|
|
c1 = rec1.beginRecording(10, 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
do_draw(c0, color, false);
|
|
|
|
do_draw(c1, color, true);
|
|
|
|
|
|
|
|
if (doPicture) {
|
|
|
|
surf0->getCanvas()->drawPicture(rec0.finishRecordingAsPicture());
|
|
|
|
surf1->getCanvas()->drawPicture(rec1.finishRecordingAsPicture());
|
|
|
|
}
|
|
|
|
|
|
|
|
// we replicate the assert so we can see which line is reported if there is a failure
|
|
|
|
if (doPicture) {
|
|
|
|
REPORTER_ASSERT(r, is_equal(surf0.get(), surf1.get()));
|
|
|
|
} else {
|
|
|
|
REPORTER_ASSERT(r, is_equal(surf0.get(), surf1.get()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(savelayer_srcmode_opaque, r) {
|
|
|
|
do_savelayer_srcmode(r, SK_ColorRED);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(savelayer_srcmode_alpha, r) {
|
|
|
|
do_savelayer_srcmode(r, 0x80FF0000);
|
|
|
|
}
|
|
|
|
|