2014-04-11 18:33:31 +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/Test.h"
|
|
|
|
|
|
|
|
#include "include/core/SkPictureRecorder.h"
|
|
|
|
#include "include/core/SkShader.h"
|
|
|
|
#include "include/core/SkSurface.h"
|
|
|
|
#include "src/core/SkRecord.h"
|
|
|
|
#include "src/core/SkRecorder.h"
|
|
|
|
#include "src/core/SkRecords.h"
|
2014-04-15 14:27:14 +00:00
|
|
|
|
2014-04-08 20:17:26 +00:00
|
|
|
#define COUNT(T) + 1
|
|
|
|
static const int kRecordTypes = SK_RECORD_TYPES(COUNT);
|
|
|
|
#undef COUNT
|
|
|
|
|
2014-04-08 23:31:35 +00:00
|
|
|
// Tallies the types of commands it sees into a histogram.
|
2014-04-08 20:17:26 +00:00
|
|
|
class Tally {
|
|
|
|
public:
|
2014-04-08 23:31:35 +00:00
|
|
|
Tally() { sk_bzero(&fHistogram, sizeof(fHistogram)); }
|
2014-04-08 20:17:26 +00:00
|
|
|
|
2014-04-08 23:31:35 +00:00
|
|
|
template <typename T>
|
|
|
|
void operator()(const T&) { ++fHistogram[T::kType]; }
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
int count() const { return fHistogram[T::kType]; }
|
2014-04-08 20:17:26 +00:00
|
|
|
|
2014-04-22 16:57:20 +00:00
|
|
|
void apply(const SkRecord& record) {
|
2015-08-19 16:51:00 +00:00
|
|
|
for (int i = 0; i < record.count(); i++) {
|
2016-03-22 18:46:53 +00:00
|
|
|
record.visit(i, *this);
|
2014-04-22 16:57:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-08 20:17:26 +00:00
|
|
|
private:
|
2014-04-08 23:31:35 +00:00
|
|
|
int fHistogram[kRecordTypes];
|
2014-04-08 20:17:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
DEF_TEST(Recorder, r) {
|
|
|
|
SkRecord record;
|
2014-05-29 16:52:40 +00:00
|
|
|
SkRecorder recorder(&record, 1920, 1080);
|
2014-04-08 20:17:26 +00:00
|
|
|
|
|
|
|
recorder.drawRect(SkRect::MakeWH(10, 10), SkPaint());
|
|
|
|
|
2014-04-08 23:31:35 +00:00
|
|
|
Tally tally;
|
2014-04-22 16:57:20 +00:00
|
|
|
tally.apply(record);
|
2014-04-08 23:31:35 +00:00
|
|
|
REPORTER_ASSERT(r, 1 == tally.count<SkRecords::DrawRect>());
|
2014-04-08 20:17:26 +00:00
|
|
|
}
|
2014-04-15 14:27:14 +00:00
|
|
|
|
|
|
|
// Regression test for leaking refs held by optional arguments.
|
|
|
|
DEF_TEST(Recorder_RefLeaking, r) {
|
|
|
|
// We use SaveLayer to test:
|
|
|
|
// - its SkRect argument is optional and SkRect is POD. Just testing that that works.
|
|
|
|
// - its SkPaint argument is optional and SkPaint is not POD. The bug was here.
|
|
|
|
|
2014-04-15 18:00:57 +00:00
|
|
|
SkRect bounds = SkRect::MakeWH(320, 240);
|
2014-04-15 14:27:14 +00:00
|
|
|
SkPaint paint;
|
2019-04-09 17:55:36 +00:00
|
|
|
paint.setShader(SkShaders::Empty());
|
2014-04-15 14:27:14 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(r, paint.getShader()->unique());
|
|
|
|
{
|
|
|
|
SkRecord record;
|
2014-05-29 16:52:40 +00:00
|
|
|
SkRecorder recorder(&record, 1920, 1080);
|
2014-04-15 14:27:14 +00:00
|
|
|
recorder.saveLayer(&bounds, &paint);
|
|
|
|
REPORTER_ASSERT(r, !paint.getShader()->unique());
|
|
|
|
}
|
|
|
|
REPORTER_ASSERT(r, paint.getShader()->unique());
|
|
|
|
}
|
2014-08-07 19:19:50 +00:00
|
|
|
|
2014-10-16 18:58:39 +00:00
|
|
|
DEF_TEST(Recorder_drawImage_takeReference, reporter) {
|
|
|
|
|
2016-03-17 17:51:11 +00:00
|
|
|
sk_sp<SkImage> image;
|
2014-10-16 18:58:39 +00:00
|
|
|
{
|
2016-03-24 01:59:25 +00:00
|
|
|
auto surface(SkSurface::MakeRasterN32Premul(100, 100));
|
2014-10-16 18:58:39 +00:00
|
|
|
surface->getCanvas()->clear(SK_ColorGREEN);
|
2016-03-17 17:51:11 +00:00
|
|
|
image = surface->makeImageSnapshot();
|
2014-10-16 18:58:39 +00:00
|
|
|
}
|
Reland "Add new virts, hide old ones"
This reverts commit 8f924ac0ce63806886b7297e8be554984a6e7ce5.
Reason for revert: suppressions landed for fuchsia images to rebaseline
Original change's description:
> Revert "Add new virts, hide old ones"
>
> This reverts commit c56e2e5aa65dd129e5927224d2f6c1f82edff74e.
>
> Reason for revert: suspected of breaking chrome roll
>
> Original change's description:
> > Add new virts, hide old ones
> >
> > Add virtuals for the draw methods that now take sampling/filtermode.
> >
> > drawImage
> > drawImageRect
> > drawImageLattice
> > drawAtlas
> >
> > Add a flag that can remove the older virtuals, once each client has
> > stopped overriding them. In that situation, the older public methods
> > will simplify extract the sampling from the paint, and call the new
> > public methods.
> >
> > Bug: skia:11105, skia:7650
> > Change-Id: I8b0029727295caa983e8148fc743a55cfbecd043
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/347022
> > Commit-Queue: Mike Reed <reed@google.com>
> > Reviewed-by: Florin Malita <fmalita@chromium.org>
> > Reviewed-by: Brian Salomon <bsalomon@google.com>
>
> TBR=bsalomon@google.com,fmalita@chromium.org,reed@google.com
>
> Change-Id: I0a90952c11a180d918126ea06a630f4a0bf9b49b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: skia:11105
> Bug: skia:7650
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/348194
> Reviewed-by: Derek Sollenberger <djsollen@google.com>
> Commit-Queue: Derek Sollenberger <djsollen@google.com>
TBR=djsollen@google.com,bsalomon@google.com,fmalita@chromium.org,reed@google.com
# Not skipping CQ checks because this is a reland.
Bug: skia:11105
Bug: skia:7650
Change-Id: Ia2b4537a2d330460b7554278d2c05075cf27162a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/348876
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
2020-12-30 14:22:42 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
SkRecord record;
|
|
|
|
SkRecorder recorder(&record, 100, 100);
|
|
|
|
|
|
|
|
// DrawImage is supposed to take a reference
|
|
|
|
recorder.drawImage(image.get(), 0, 0, SkSamplingOptions());
|
|
|
|
REPORTER_ASSERT(reporter, !image->unique());
|
|
|
|
|
|
|
|
Tally tally;
|
|
|
|
tally.apply(record);
|
|
|
|
|
2021-01-22 03:25:21 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1 == tally.count<SkRecords::DrawImage>());
|
Reland "Add new virts, hide old ones"
This reverts commit 8f924ac0ce63806886b7297e8be554984a6e7ce5.
Reason for revert: suppressions landed for fuchsia images to rebaseline
Original change's description:
> Revert "Add new virts, hide old ones"
>
> This reverts commit c56e2e5aa65dd129e5927224d2f6c1f82edff74e.
>
> Reason for revert: suspected of breaking chrome roll
>
> Original change's description:
> > Add new virts, hide old ones
> >
> > Add virtuals for the draw methods that now take sampling/filtermode.
> >
> > drawImage
> > drawImageRect
> > drawImageLattice
> > drawAtlas
> >
> > Add a flag that can remove the older virtuals, once each client has
> > stopped overriding them. In that situation, the older public methods
> > will simplify extract the sampling from the paint, and call the new
> > public methods.
> >
> > Bug: skia:11105, skia:7650
> > Change-Id: I8b0029727295caa983e8148fc743a55cfbecd043
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/347022
> > Commit-Queue: Mike Reed <reed@google.com>
> > Reviewed-by: Florin Malita <fmalita@chromium.org>
> > Reviewed-by: Brian Salomon <bsalomon@google.com>
>
> TBR=bsalomon@google.com,fmalita@chromium.org,reed@google.com
>
> Change-Id: I0a90952c11a180d918126ea06a630f4a0bf9b49b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: skia:11105
> Bug: skia:7650
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/348194
> Reviewed-by: Derek Sollenberger <djsollen@google.com>
> Commit-Queue: Derek Sollenberger <djsollen@google.com>
TBR=djsollen@google.com,bsalomon@google.com,fmalita@chromium.org,reed@google.com
# Not skipping CQ checks because this is a reland.
Bug: skia:11105
Bug: skia:7650
Change-Id: Ia2b4537a2d330460b7554278d2c05075cf27162a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/348876
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
2020-12-30 14:22:42 +00:00
|
|
|
}
|
|
|
|
REPORTER_ASSERT(reporter, image->unique());
|
|
|
|
|
|
|
|
{
|
|
|
|
SkRecord record;
|
|
|
|
SkRecorder recorder(&record, 100, 100);
|
|
|
|
|
|
|
|
// DrawImageRect is supposed to take a reference
|
|
|
|
recorder.drawImageRect(image.get(), SkRect::MakeWH(100, 100), SkRect::MakeWH(100, 100),
|
|
|
|
SkSamplingOptions(), nullptr, SkCanvas::kFast_SrcRectConstraint);
|
|
|
|
REPORTER_ASSERT(reporter, !image->unique());
|
|
|
|
|
|
|
|
Tally tally;
|
|
|
|
tally.apply(record);
|
|
|
|
|
2021-01-22 03:25:21 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1 == tally.count<SkRecords::DrawImageRect>());
|
Reland "Add new virts, hide old ones"
This reverts commit 8f924ac0ce63806886b7297e8be554984a6e7ce5.
Reason for revert: suppressions landed for fuchsia images to rebaseline
Original change's description:
> Revert "Add new virts, hide old ones"
>
> This reverts commit c56e2e5aa65dd129e5927224d2f6c1f82edff74e.
>
> Reason for revert: suspected of breaking chrome roll
>
> Original change's description:
> > Add new virts, hide old ones
> >
> > Add virtuals for the draw methods that now take sampling/filtermode.
> >
> > drawImage
> > drawImageRect
> > drawImageLattice
> > drawAtlas
> >
> > Add a flag that can remove the older virtuals, once each client has
> > stopped overriding them. In that situation, the older public methods
> > will simplify extract the sampling from the paint, and call the new
> > public methods.
> >
> > Bug: skia:11105, skia:7650
> > Change-Id: I8b0029727295caa983e8148fc743a55cfbecd043
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/347022
> > Commit-Queue: Mike Reed <reed@google.com>
> > Reviewed-by: Florin Malita <fmalita@chromium.org>
> > Reviewed-by: Brian Salomon <bsalomon@google.com>
>
> TBR=bsalomon@google.com,fmalita@chromium.org,reed@google.com
>
> Change-Id: I0a90952c11a180d918126ea06a630f4a0bf9b49b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: skia:11105
> Bug: skia:7650
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/348194
> Reviewed-by: Derek Sollenberger <djsollen@google.com>
> Commit-Queue: Derek Sollenberger <djsollen@google.com>
TBR=djsollen@google.com,bsalomon@google.com,fmalita@chromium.org,reed@google.com
# Not skipping CQ checks because this is a reland.
Bug: skia:11105
Bug: skia:7650
Change-Id: Ia2b4537a2d330460b7554278d2c05075cf27162a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/348876
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
2020-12-30 14:22:42 +00:00
|
|
|
}
|
|
|
|
REPORTER_ASSERT(reporter, image->unique());
|
2014-10-16 18:58:39 +00:00
|
|
|
}
|
2020-11-25 19:29:30 +00:00
|
|
|
|
|
|
|
// skbug.com/10997
|
|
|
|
DEF_TEST(Recorder_boundsOverflow, reporter) {
|
|
|
|
SkRect bigBounds = {SK_ScalarMin, SK_ScalarMin, SK_ScalarMax, SK_ScalarMax};
|
|
|
|
|
|
|
|
SkRecord record;
|
|
|
|
SkRecorder recorder(&record, bigBounds);
|
|
|
|
REPORTER_ASSERT(reporter, recorder.imageInfo().width() > 0 &&
|
|
|
|
recorder.imageInfo().height() > 0);
|
|
|
|
}
|