Install a hook to swap between SkPicture backends with a single define.
BUG=skia: R=robertphillips@google.com, reed@google.com, mtklein@google.com Author: mtklein@chromium.org Review URL: https://codereview.chromium.org/492023002
This commit is contained in:
parent
8ebdd99bb1
commit
c92e550d36
@ -5,47 +5,11 @@
|
||||
#include "SkCommandLineFlags.h"
|
||||
#include "SkPictureRecorder.h"
|
||||
|
||||
DEFINE_bool(skr, true, "Test that SKPs draw the same when re-recorded with SkRecord backend.");
|
||||
DEFINE_int32(skpMaxWidth, 1000, "Max SKPTask viewport width.");
|
||||
DEFINE_int32(skpMaxHeight, 1000, "Max SKPTask viewport height.");
|
||||
|
||||
namespace DM {
|
||||
|
||||
// Test that an SkPicture plays back the same when re-recorded into an
|
||||
// SkPicture backed by SkRecord.
|
||||
class SkrComparisonTask : public CpuTask {
|
||||
public:
|
||||
SkrComparisonTask(const Task& parent, const SkPicture* picture, SkBitmap reference)
|
||||
: CpuTask(parent)
|
||||
, fPicture(SkRef(picture))
|
||||
, fReference(reference)
|
||||
, fName(UnderJoin(parent.name().c_str(), "skr")) {}
|
||||
|
||||
virtual bool shouldSkip() const SK_OVERRIDE { return !FLAGS_skr; }
|
||||
virtual SkString name() const SK_OVERRIDE { return fName; }
|
||||
|
||||
virtual void draw() SK_OVERRIDE {
|
||||
SkPictureRecorder recorder;
|
||||
fPicture->draw(recorder.EXPERIMENTAL_beginRecording(fPicture->width(), fPicture->height()));
|
||||
SkAutoTDelete<const SkPicture> skrPicture(recorder.endRecording());
|
||||
|
||||
SkBitmap bitmap;
|
||||
AllocatePixels(kN32_SkColorType, fReference.width(), fReference.height(), &bitmap);
|
||||
DrawPicture(*skrPicture, &bitmap);
|
||||
|
||||
if (!BitmapsEqual(fReference, bitmap)) {
|
||||
this->fail();
|
||||
this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap)));
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
SkAutoTUnref<const SkPicture> fPicture;
|
||||
const SkBitmap fReference;
|
||||
const SkString fName;
|
||||
};
|
||||
|
||||
|
||||
SKPTask::SKPTask(Reporter* r, TaskRunner* tr, const SkPicture* pic, SkString filename)
|
||||
: CpuTask(r, tr), fPicture(SkRef(pic)), fName(FileToTaskName(filename)) {}
|
||||
|
||||
@ -57,7 +21,6 @@ void SKPTask::draw() {
|
||||
DrawPicture(*fPicture, &bitmap);
|
||||
|
||||
this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap)));
|
||||
this->spawnChild(SkNEW_ARGS(SkrComparisonTask, (*this, fPicture.get(), bitmap)));
|
||||
}
|
||||
|
||||
} // namespace DM
|
||||
|
@ -6,11 +6,11 @@
|
||||
#include "SkPicture.h"
|
||||
#include "SkPixelRef.h"
|
||||
|
||||
DEFINE_bool(serialize, true, "If true, run picture serialization tests.");
|
||||
DECLARE_bool(skr); // in DMReplayTask.cpp
|
||||
DEFINE_bool(serialize, true, "If true, run picture serialization tests via SkPictureData.");
|
||||
DEFINE_bool(serialize_skr, true, "If true, run picture serialization tests via SkRecord.");
|
||||
|
||||
static const char* kSuffixes[] = { "serialize", "serialize_skr" };
|
||||
static const bool* kEnabled[] = { &FLAGS_serialize, &FLAGS_skr };
|
||||
static const bool* kEnabled[] = { &FLAGS_serialize, &FLAGS_serialize_skr };
|
||||
|
||||
namespace DM {
|
||||
|
||||
|
@ -26,7 +26,7 @@ SkPicture* RecordPicture(skiagm::GM* gm, SkBBHFactory* factory, bool skr) {
|
||||
SkPictureRecorder recorder;
|
||||
|
||||
SkCanvas* canvas = skr ? recorder.EXPERIMENTAL_beginRecording(w, h, factory)
|
||||
: recorder. beginRecording(w, h, factory);
|
||||
: recorder. DEPRECATED_beginRecording(w, h, factory);
|
||||
canvas->concat(gm->getInitialTransform());
|
||||
gm->draw(canvas);
|
||||
canvas->flush();
|
||||
|
@ -82,7 +82,7 @@ static SkPicture* create_save_layer_opt_1(SkTDArray<DrawType>* preOptPattern,
|
||||
|
||||
SkPictureRecorder recorder;
|
||||
|
||||
SkCanvas* canvas = recorder.beginRecording(100, 100, NULL, 0);
|
||||
SkCanvas* canvas = recorder.DEPRECATED_beginRecording(100, 100, NULL, 0);
|
||||
// have to disable the optimizations while generating the picture
|
||||
recorder.internalOnly_EnableOpts(false);
|
||||
|
||||
@ -216,7 +216,7 @@ static SkPicture* create_save_layer_opt_2(SkTDArray<DrawType>* preOptPattern,
|
||||
|
||||
SkPictureRecorder recorder;
|
||||
|
||||
SkCanvas* canvas = recorder.beginRecording(100, 100, NULL, 0);
|
||||
SkCanvas* canvas = recorder.DEPRECATED_beginRecording(100, 100, NULL, 0);
|
||||
// have to disable the optimizations while generating the picture
|
||||
recorder.internalOnly_EnableOpts(false);
|
||||
|
||||
@ -359,7 +359,8 @@ protected:
|
||||
// re-render the 'pre' picture and thus 'apply' the optimization
|
||||
SkPictureRecorder recorder;
|
||||
|
||||
SkCanvas* recordCanvas = recorder.beginRecording(pre->width(), pre->height(), NULL, 0);
|
||||
SkCanvas* recordCanvas =
|
||||
recorder.DEPRECATED_beginRecording(pre->width(), pre->height(), NULL, 0);
|
||||
|
||||
pre->draw(recordCanvas);
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
'SK_SUPPORT_GPU=<(skia_gpu)',
|
||||
'SK_SUPPORT_OPENCL=<(skia_opencl)',
|
||||
'SK_FORCE_DISTANCEFIELD_FONTS=<(skia_force_distancefield_fonts)',
|
||||
'SK_PICTURE_USE_SK_RECORD',
|
||||
],
|
||||
'conditions' : [
|
||||
['skia_pic', {
|
||||
|
@ -41,7 +41,17 @@ public:
|
||||
SkBBHFactory* bbhFactory = NULL,
|
||||
uint32_t recordFlags = 0);
|
||||
|
||||
/** Same as beginRecording(), using a new faster backend. */
|
||||
// As usual, we have a deprecated old version and a maybe almost working
|
||||
// new version. We currently point beginRecording() to
|
||||
// DEPRECATED_beginRecording() unless SK_PICTURE_USE_SK_RECORD is defined,
|
||||
// then we use EXPERIMENTAL_beginRecording().
|
||||
|
||||
// Old slower backend.
|
||||
SkCanvas* DEPRECATED_beginRecording(int width, int height,
|
||||
SkBBHFactory* bbhFactory = NULL,
|
||||
uint32_t recordFlags = 0);
|
||||
|
||||
// New faster backend.
|
||||
SkCanvas* EXPERIMENTAL_beginRecording(int width, int height,
|
||||
SkBBHFactory* bbhFactory = NULL);
|
||||
|
||||
|
@ -279,7 +279,8 @@ SkPicture::SkPicture(int width, int height,
|
||||
// This for compatibility with serialization code only. This is not cheap.
|
||||
static SkPicture* backport(const SkRecord& src, int width, int height) {
|
||||
SkPictureRecorder recorder;
|
||||
SkRecordDraw(src, recorder.beginRecording(width, height), NULL/*bbh*/, NULL/*callback*/);
|
||||
SkRecordDraw(src,
|
||||
recorder.DEPRECATED_beginRecording(width, height), NULL/*bbh*/, NULL/*callback*/);
|
||||
return recorder.endRecording();
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,16 @@ SkPictureRecorder::~SkPictureRecorder() {}
|
||||
SkCanvas* SkPictureRecorder::beginRecording(int width, int height,
|
||||
SkBBHFactory* bbhFactory /* = NULL */,
|
||||
uint32_t recordFlags /* = 0 */) {
|
||||
#ifdef SK_PICTURE_USE_SK_RECORD
|
||||
return EXPERIMENTAL_beginRecording(width, height, bbhFactory);
|
||||
#else
|
||||
return DEPRECATED_beginRecording(width, height, bbhFactory, recordFlags);
|
||||
#endif
|
||||
}
|
||||
|
||||
SkCanvas* SkPictureRecorder::DEPRECATED_beginRecording(int width, int height,
|
||||
SkBBHFactory* bbhFactory /* = NULL */,
|
||||
uint32_t recordFlags /* = 0 */) {
|
||||
fWidth = width;
|
||||
fHeight = height;
|
||||
|
||||
|
@ -687,13 +687,13 @@ public:
|
||||
// are flattened during the second execution
|
||||
testStep->setAssertMessageFormat(kPictureDrawAssertMessageFormat);
|
||||
SkPictureRecorder referenceRecorder;
|
||||
SkCanvas* referenceCanvas = referenceRecorder.beginRecording(kWidth, kHeight,
|
||||
NULL, recordFlags);
|
||||
SkCanvas* referenceCanvas =
|
||||
referenceRecorder.DEPRECATED_beginRecording(kWidth, kHeight, NULL, recordFlags);
|
||||
testStep->draw(referenceCanvas, reporter);
|
||||
|
||||
SkPictureRecorder testRecorder;
|
||||
SkCanvas* testCanvas = testRecorder.beginRecording(kWidth, kHeight,
|
||||
NULL, recordFlags);
|
||||
SkCanvas* testCanvas =
|
||||
testRecorder.DEPRECATED_beginRecording(kWidth, kHeight, NULL, recordFlags);
|
||||
testStep->draw(testCanvas, reporter);
|
||||
testStep->setAssertMessageFormat(kPictureSecondDrawAssertMessageFormat);
|
||||
testStep->draw(testCanvas, reporter);
|
||||
|
@ -580,7 +580,7 @@ static void test_gatherpixelrefs(skiatest::Reporter* reporter) {
|
||||
|
||||
#define GENERATE_CANVAS(recorder, x) \
|
||||
(x) ? recorder.EXPERIMENTAL_beginRecording(100, 100) \
|
||||
: recorder.beginRecording(100,100);
|
||||
: recorder. DEPRECATED_beginRecording(100,100);
|
||||
|
||||
/* Hit a few SkPicture::Analysis cases not handled elsewhere. */
|
||||
static void test_analysis(skiatest::Reporter* reporter, bool useNewPath) {
|
||||
@ -897,7 +897,7 @@ static void test_gpu_picture_optimization(skiatest::Reporter* reporter,
|
||||
{
|
||||
SkPictureRecorder recorder;
|
||||
|
||||
SkCanvas* c = recorder.beginRecording(kWidth, kHeight);
|
||||
SkCanvas* c = recorder.DEPRECATED_beginRecording(kWidth, kHeight);
|
||||
// 1)
|
||||
c->saveLayer(NULL, NULL);
|
||||
c->restore();
|
||||
@ -1002,7 +1002,7 @@ static void test_gpu_picture_optimization(skiatest::Reporter* reporter,
|
||||
static void test_has_text(skiatest::Reporter* reporter, bool useNewPath) {
|
||||
SkPictureRecorder recorder;
|
||||
#define BEGIN_RECORDING useNewPath ? recorder.EXPERIMENTAL_beginRecording(100, 100) \
|
||||
: recorder. beginRecording(100, 100)
|
||||
: recorder. DEPRECATED_beginRecording(100, 100)
|
||||
|
||||
SkCanvas* canvas = BEGIN_RECORDING;
|
||||
{
|
||||
|
@ -45,7 +45,7 @@ static SkPicture* rerecord(const SkPicture& src, bool skr) {
|
||||
|
||||
SkPictureRecorder recorder;
|
||||
src.draw(skr ? recorder.EXPERIMENTAL_beginRecording(src.width(), src.height(), &factory)
|
||||
: recorder. beginRecording(src.width(), src.height(), &factory));
|
||||
: recorder. DEPRECATED_beginRecording(src.width(), src.height(), &factory));
|
||||
return recorder.endRecording();
|
||||
}
|
||||
|
||||
|
@ -66,7 +66,7 @@ static void rerecord(const SkPicture& src, SkBBHFactory* bbhFactory) {
|
||||
if (FLAGS_skr) {
|
||||
src.draw(recorder.EXPERIMENTAL_beginRecording(src.width(), src.height(), bbhFactory));
|
||||
} else {
|
||||
src.draw(recorder.beginRecording(src.width(), src.height(), bbhFactory));
|
||||
src.draw(recorder. DEPRECATED_beginRecording(src.width(), src.height(), bbhFactory));
|
||||
}
|
||||
SkAutoTUnref<SkPicture> pic(recorder.endRecording());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user