2011-11-28 16:06:04 +00:00
|
|
|
/*
|
2012-02-22 21:00:42 +00:00
|
|
|
* Copyright 2012 Google Inc.
|
2011-11-28 16:06:04 +00:00
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2012-02-22 21:00:42 +00:00
|
|
|
|
|
|
|
/* Description:
|
|
|
|
* This test defines a series of elementatry test steps that perform
|
|
|
|
* a single or a small group of canvas API calls. Each test step is
|
|
|
|
* used in several test cases that verify that different types of SkCanvas
|
|
|
|
* flavors and derivatives pass it and yield consistent behavior. The
|
|
|
|
* test cases analyse results that are queryable through the API. They do
|
|
|
|
* not look at rendering results.
|
|
|
|
*
|
|
|
|
* Adding test stepss:
|
|
|
|
* The general pattern for creating a new test step is to write a test
|
|
|
|
* function of the form:
|
|
|
|
*
|
2012-08-23 18:14:13 +00:00
|
|
|
* static void MyTestStepFunction(SkCanvas* canvas,
|
2012-02-22 21:00:42 +00:00
|
|
|
* skiatest::Reporter* reporter,
|
|
|
|
* CanvasTestStep* testStep)
|
|
|
|
* {
|
|
|
|
* canvas->someCanvasAPImethod();
|
|
|
|
* (...)
|
|
|
|
* REPORTER_ASSERT_MESSAGE(reporter, (...), \
|
|
|
|
* testStep->assertMessage());
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* The definition of the test step function should be followed by an
|
|
|
|
* invocation of the TEST_STEP macro, which generates a class and
|
|
|
|
* instance for the test step:
|
|
|
|
*
|
|
|
|
* TEST_STEP(MyTestStep, MyTestStepFunction)
|
|
|
|
*
|
|
|
|
* There are also short hand macros for defining simple test steps
|
|
|
|
* in a single line of code. A simple test step is a one that is made
|
|
|
|
* of a single canvas API call.
|
|
|
|
*
|
|
|
|
* SIMPLE_TEST_STEP(MytestStep, someCanvasAPIMethod());
|
|
|
|
*
|
|
|
|
* There is another macro called SIMPLE_TEST_STEP_WITH_ASSERT that
|
|
|
|
* works the same way as SIMPLE_TEST_STEP, and additionally verifies
|
|
|
|
* that the invoked method returns a non-zero value.
|
|
|
|
*/
|
2011-11-28 16:06:04 +00:00
|
|
|
#include "SkBitmap.h"
|
|
|
|
#include "SkCanvas.h"
|
2012-02-22 21:00:42 +00:00
|
|
|
#include "SkDeferredCanvas.h"
|
|
|
|
#include "SkDevice.h"
|
|
|
|
#include "SkMatrix.h"
|
|
|
|
#include "SkNWayCanvas.h"
|
2015-02-20 14:17:26 +00:00
|
|
|
#include "SkPDFCanon.h"
|
2012-10-18 15:58:23 +00:00
|
|
|
#include "SkPDFDevice.h"
|
|
|
|
#include "SkPDFDocument.h"
|
2012-02-22 21:00:42 +00:00
|
|
|
#include "SkPaint.h"
|
|
|
|
#include "SkPath.h"
|
|
|
|
#include "SkPicture.h"
|
|
|
|
#include "SkPictureRecord.h"
|
2014-04-18 18:04:41 +00:00
|
|
|
#include "SkPictureRecorder.h"
|
2012-02-22 21:00:42 +00:00
|
|
|
#include "SkRect.h"
|
|
|
|
#include "SkRegion.h"
|
|
|
|
#include "SkShader.h"
|
|
|
|
#include "SkStream.h"
|
2014-02-04 15:34:10 +00:00
|
|
|
#include "SkSurface.h"
|
2012-02-22 21:00:42 +00:00
|
|
|
#include "SkTDArray.h"
|
|
|
|
#include "Test.h"
|
2011-11-28 16:06:04 +00:00
|
|
|
|
2014-10-03 20:26:55 +00:00
|
|
|
static const int kWidth = 2, kHeight = 2;
|
|
|
|
|
|
|
|
static void createBitmap(SkBitmap* bm, SkColor color) {
|
|
|
|
bm->allocN32Pixels(kWidth, kHeight);
|
|
|
|
bm->eraseColor(color);
|
|
|
|
}
|
|
|
|
|
|
|
|
static SkSurface* createSurface(SkColor color) {
|
2014-12-10 15:24:28 +00:00
|
|
|
SkSurface* surface = SkSurface::NewRasterN32Premul(kWidth, kHeight);
|
2014-10-03 20:26:55 +00:00
|
|
|
surface->getCanvas()->clear(color);
|
|
|
|
return surface;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Constants used by test steps
|
|
|
|
const SkPoint kTestPoints[] = {
|
|
|
|
{SkIntToScalar(0), SkIntToScalar(0)},
|
|
|
|
{SkIntToScalar(2), SkIntToScalar(1)},
|
|
|
|
{SkIntToScalar(0), SkIntToScalar(2)}
|
|
|
|
};
|
|
|
|
const SkPoint kTestPoints2[] = {
|
|
|
|
{ SkIntToScalar(0), SkIntToScalar(1) },
|
|
|
|
{ SkIntToScalar(1), SkIntToScalar(1) },
|
|
|
|
{ SkIntToScalar(2), SkIntToScalar(1) },
|
|
|
|
{ SkIntToScalar(3), SkIntToScalar(1) },
|
|
|
|
{ SkIntToScalar(4), SkIntToScalar(1) },
|
|
|
|
{ SkIntToScalar(5), SkIntToScalar(1) },
|
|
|
|
{ SkIntToScalar(6), SkIntToScalar(1) },
|
|
|
|
{ SkIntToScalar(7), SkIntToScalar(1) },
|
|
|
|
{ SkIntToScalar(8), SkIntToScalar(1) },
|
|
|
|
{ SkIntToScalar(9), SkIntToScalar(1) },
|
|
|
|
{ SkIntToScalar(10), SkIntToScalar(1) }
|
|
|
|
};
|
|
|
|
|
|
|
|
struct TestData {
|
|
|
|
public:
|
|
|
|
TestData()
|
|
|
|
: fRect(SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0),
|
|
|
|
SkIntToScalar(2), SkIntToScalar(1)))
|
|
|
|
, fMatrix(TestMatrix())
|
|
|
|
, fPath(TestPath())
|
|
|
|
, fNearlyZeroLengthPath(TestNearlyZeroLengthPath())
|
|
|
|
, fIRect(SkIRect::MakeXYWH(0, 0, 2, 1))
|
|
|
|
, fRegion(TestRegion())
|
|
|
|
, fColor(0x01020304)
|
|
|
|
, fPoints(kTestPoints)
|
|
|
|
, fPointCount(3)
|
|
|
|
, fWidth(2)
|
|
|
|
, fHeight(2)
|
|
|
|
, fText("Hello World")
|
|
|
|
, fPoints2(kTestPoints2)
|
|
|
|
, fBitmap(TestBitmap())
|
|
|
|
{ }
|
|
|
|
|
|
|
|
SkRect fRect;
|
|
|
|
SkMatrix fMatrix;;
|
|
|
|
SkPath fPath;
|
|
|
|
SkPath fNearlyZeroLengthPath;
|
|
|
|
SkIRect fIRect;
|
|
|
|
SkRegion fRegion;
|
|
|
|
SkColor fColor;
|
|
|
|
SkPaint fPaint;
|
|
|
|
const SkPoint* fPoints;
|
|
|
|
size_t fPointCount;
|
|
|
|
int fWidth;
|
|
|
|
int fHeight;
|
|
|
|
SkString fText;
|
|
|
|
const SkPoint* fPoints2;
|
|
|
|
SkBitmap fBitmap;
|
|
|
|
|
|
|
|
private:
|
|
|
|
static SkMatrix TestMatrix() {
|
|
|
|
SkMatrix matrix;
|
|
|
|
matrix.reset();
|
|
|
|
matrix.setScale(SkIntToScalar(2), SkIntToScalar(3));
|
|
|
|
|
|
|
|
return matrix;
|
|
|
|
}
|
|
|
|
static SkPath TestPath() {
|
|
|
|
SkPath path;
|
|
|
|
path.addRect(SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0),
|
|
|
|
SkIntToScalar(2), SkIntToScalar(1)));
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
static SkPath TestNearlyZeroLengthPath() {
|
|
|
|
SkPath path;
|
|
|
|
SkPoint pt1 = { 0, 0 };
|
|
|
|
SkPoint pt2 = { 0, SK_ScalarNearlyZero };
|
|
|
|
SkPoint pt3 = { SkIntToScalar(1), 0 };
|
|
|
|
SkPoint pt4 = { SkIntToScalar(1), SK_ScalarNearlyZero/2 };
|
|
|
|
path.moveTo(pt1);
|
|
|
|
path.lineTo(pt2);
|
|
|
|
path.lineTo(pt3);
|
|
|
|
path.lineTo(pt4);
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
static SkRegion TestRegion() {
|
|
|
|
SkRegion region;
|
|
|
|
SkIRect rect = SkIRect::MakeXYWH(0, 0, 2, 1);
|
|
|
|
region.setRect(rect);
|
|
|
|
return region;
|
|
|
|
}
|
|
|
|
static SkBitmap TestBitmap() {
|
|
|
|
SkBitmap bitmap;
|
|
|
|
createBitmap(&bitmap, 0x05060708);
|
|
|
|
return bitmap;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-03-08 03:57:19 +00:00
|
|
|
static bool equal_clips(const SkCanvas& a, const SkCanvas& b) {
|
|
|
|
if (a.isClipEmpty()) {
|
|
|
|
return b.isClipEmpty();
|
|
|
|
}
|
|
|
|
if (!a.isClipRect()) {
|
|
|
|
// this is liberally true, since we don't expose a way to know this exactly (for non-rects)
|
|
|
|
return !b.isClipRect();
|
|
|
|
}
|
|
|
|
SkIRect ar, br;
|
|
|
|
a.getClipDeviceBounds(&ar);
|
|
|
|
b.getClipDeviceBounds(&br);
|
|
|
|
return ar == br;
|
|
|
|
}
|
|
|
|
|
2012-04-13 13:50:27 +00:00
|
|
|
class Canvas2CanvasClipVisitor : public SkCanvas::ClipVisitor {
|
|
|
|
public:
|
|
|
|
Canvas2CanvasClipVisitor(SkCanvas* target) : fTarget(target) {}
|
|
|
|
|
2015-01-09 18:06:39 +00:00
|
|
|
void clipRect(const SkRect& r, SkRegion::Op op, bool aa) SK_OVERRIDE {
|
2012-04-13 13:50:27 +00:00
|
|
|
fTarget->clipRect(r, op, aa);
|
|
|
|
}
|
2015-01-09 18:06:39 +00:00
|
|
|
void clipRRect(const SkRRect& r, SkRegion::Op op, bool aa) SK_OVERRIDE {
|
2014-02-16 13:25:24 +00:00
|
|
|
fTarget->clipRRect(r, op, aa);
|
|
|
|
}
|
2015-01-09 18:06:39 +00:00
|
|
|
void clipPath(const SkPath& p, SkRegion::Op op, bool aa) SK_OVERRIDE {
|
2012-04-13 13:50:27 +00:00
|
|
|
fTarget->clipPath(p, op, aa);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SkCanvas* fTarget;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void test_clipVisitor(skiatest::Reporter* reporter, SkCanvas* canvas) {
|
|
|
|
SkISize size = canvas->getDeviceSize();
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-04-13 13:50:27 +00:00
|
|
|
SkBitmap bm;
|
2014-05-30 13:26:10 +00:00
|
|
|
bm.setInfo(SkImageInfo::MakeN32Premul(size.width(), size.height()));
|
2012-04-13 13:50:27 +00:00
|
|
|
SkCanvas c(bm);
|
|
|
|
|
|
|
|
Canvas2CanvasClipVisitor visitor(&c);
|
|
|
|
canvas->replayClips(&visitor);
|
|
|
|
|
2014-03-08 03:57:19 +00:00
|
|
|
REPORTER_ASSERT(reporter, equal_clips(c, *canvas));
|
2012-04-13 13:50:27 +00:00
|
|
|
}
|
|
|
|
|
2012-02-22 21:00:42 +00:00
|
|
|
// Format strings that describe the test context. The %s token is where
|
|
|
|
// the name of the test step is inserted. The context is required for
|
|
|
|
// disambiguating the error in the case of failures that are reported in
|
|
|
|
// functions that are called multiple times in different contexts (test
|
|
|
|
// cases and test steps).
|
|
|
|
static const char* const kDefaultAssertMessageFormat = "%s";
|
2012-08-23 18:14:13 +00:00
|
|
|
static const char* const kCanvasDrawAssertMessageFormat =
|
2012-02-22 21:00:42 +00:00
|
|
|
"Drawing test step %s with SkCanvas";
|
2012-08-23 18:14:13 +00:00
|
|
|
static const char* const kDeferredDrawAssertMessageFormat =
|
2012-02-22 21:00:42 +00:00
|
|
|
"Drawing test step %s with SkDeferredCanvas";
|
2012-08-23 18:14:13 +00:00
|
|
|
static const char* const kNWayDrawAssertMessageFormat =
|
2012-02-22 21:00:42 +00:00
|
|
|
"Drawing test step %s with SkNWayCanvas";
|
2012-08-23 18:14:13 +00:00
|
|
|
static const char* const kDeferredPreFlushAssertMessageFormat =
|
2012-02-22 21:00:42 +00:00
|
|
|
"test step %s, SkDeferredCanvas state consistency before flush";
|
2012-07-18 21:50:26 +00:00
|
|
|
static const char* const kDeferredPostFlushPlaybackAssertMessageFormat =
|
|
|
|
"test step %s, SkDeferredCanvas playback canvas state consistency after flush";
|
2012-09-20 19:35:43 +00:00
|
|
|
static const char* const kDeferredPostSilentFlushPlaybackAssertMessageFormat =
|
|
|
|
"test step %s, SkDeferredCanvas playback canvas state consistency after silent flush";
|
2012-02-22 21:00:42 +00:00
|
|
|
static const char* const kNWayStateAssertMessageFormat =
|
|
|
|
"test step %s, SkNWayCanvas state consistency";
|
|
|
|
static const char* const kNWayIndirect1StateAssertMessageFormat =
|
|
|
|
"test step %s, SkNWayCanvas indirect canvas 1 state consistency";
|
|
|
|
static const char* const kNWayIndirect2StateAssertMessageFormat =
|
|
|
|
"test step %s, SkNWayCanvas indirect canvas 2 state consistency";
|
2012-10-18 15:58:23 +00:00
|
|
|
static const char* const kPdfAssertMessageFormat =
|
|
|
|
"PDF sanity check failed %s";
|
2012-02-22 21:00:42 +00:00
|
|
|
|
|
|
|
class CanvasTestStep;
|
|
|
|
static SkTDArray<CanvasTestStep*>& testStepArray() {
|
|
|
|
static SkTDArray<CanvasTestStep*> theTests;
|
|
|
|
return theTests;
|
|
|
|
}
|
|
|
|
|
|
|
|
class CanvasTestStep {
|
|
|
|
public:
|
2012-10-18 15:58:23 +00:00
|
|
|
CanvasTestStep(bool fEnablePdfTesting = true) {
|
2012-02-22 21:00:42 +00:00
|
|
|
*testStepArray().append() = this;
|
|
|
|
fAssertMessageFormat = kDefaultAssertMessageFormat;
|
2012-10-18 15:58:23 +00:00
|
|
|
this->fEnablePdfTesting = fEnablePdfTesting;
|
2012-02-22 21:00:42 +00:00
|
|
|
}
|
2012-03-21 15:39:03 +00:00
|
|
|
virtual ~CanvasTestStep() { }
|
2012-02-22 21:00:42 +00:00
|
|
|
|
2014-10-03 20:26:55 +00:00
|
|
|
virtual void draw(SkCanvas*, const TestData&, skiatest::Reporter*) = 0;
|
2012-02-22 21:00:42 +00:00
|
|
|
virtual const char* name() const = 0;
|
|
|
|
|
|
|
|
const char* assertMessage() {
|
|
|
|
fAssertMessage.printf(fAssertMessageFormat, name());
|
|
|
|
return fAssertMessage.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
void setAssertMessageFormat(const char* format) {
|
|
|
|
fAssertMessageFormat = format;
|
|
|
|
}
|
|
|
|
|
2012-10-18 15:58:23 +00:00
|
|
|
bool enablePdfTesting() { return fEnablePdfTesting; }
|
|
|
|
|
2012-02-22 21:00:42 +00:00
|
|
|
private:
|
|
|
|
SkString fAssertMessage;
|
|
|
|
const char* fAssertMessageFormat;
|
2012-10-18 15:58:23 +00:00
|
|
|
bool fEnablePdfTesting;
|
2012-02-22 21:00:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Macros for defining test steps
|
|
|
|
|
|
|
|
#define TEST_STEP(NAME, FUNCTION) \
|
|
|
|
class NAME##_TestStep : public CanvasTestStep{ \
|
|
|
|
public: \
|
2014-10-03 20:26:55 +00:00
|
|
|
virtual void draw(SkCanvas* canvas, const TestData& d, \
|
|
|
|
skiatest::Reporter* reporter) { \
|
|
|
|
FUNCTION (canvas, d, reporter, this); \
|
2012-02-22 21:00:42 +00:00
|
|
|
} \
|
|
|
|
virtual const char* name() const {return #NAME ;} \
|
|
|
|
}; \
|
|
|
|
static NAME##_TestStep NAME##_TestStepInstance;
|
|
|
|
|
2014-10-03 20:26:55 +00:00
|
|
|
#define TEST_STEP_NO_PDF(NAME, FUNCTION) \
|
2012-10-18 15:58:23 +00:00
|
|
|
class NAME##_TestStep : public CanvasTestStep{ \
|
|
|
|
public: \
|
|
|
|
NAME##_TestStep() : CanvasTestStep(false) {} \
|
2014-10-03 20:26:55 +00:00
|
|
|
virtual void draw(SkCanvas* canvas, const TestData& d, \
|
|
|
|
skiatest::Reporter* reporter) { \
|
|
|
|
FUNCTION (canvas, d, reporter, this); \
|
2012-10-18 15:58:23 +00:00
|
|
|
} \
|
|
|
|
virtual const char* name() const {return #NAME ;} \
|
|
|
|
}; \
|
|
|
|
static NAME##_TestStep NAME##_TestStepInstance;
|
|
|
|
|
2014-10-03 20:26:55 +00:00
|
|
|
#define SIMPLE_TEST_STEP(NAME, CALL) \
|
|
|
|
static void NAME##TestStep(SkCanvas* canvas, const TestData& d, \
|
|
|
|
skiatest::Reporter*, CanvasTestStep*) { \
|
|
|
|
canvas-> CALL ; \
|
|
|
|
} \
|
2012-02-22 21:00:42 +00:00
|
|
|
TEST_STEP(NAME, NAME##TestStep )
|
|
|
|
|
|
|
|
#define SIMPLE_TEST_STEP_WITH_ASSERT(NAME, CALL) \
|
2014-10-03 20:26:55 +00:00
|
|
|
static void NAME##TestStep(SkCanvas* canvas, const TestData& d, \
|
|
|
|
skiatest::Reporter*, CanvasTestStep* testStep) { \
|
2012-02-22 21:00:42 +00:00
|
|
|
REPORTER_ASSERT_MESSAGE(reporter, canvas-> CALL , \
|
|
|
|
testStep->assertMessage()); \
|
|
|
|
} \
|
|
|
|
TEST_STEP(NAME, NAME##TestStep )
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2012-08-23 18:14:13 +00:00
|
|
|
// Basic test steps for most virtual methods in SkCanvas that draw or affect
|
2012-02-22 21:00:42 +00:00
|
|
|
// the state of the canvas.
|
|
|
|
|
2014-03-18 12:51:48 +00:00
|
|
|
SIMPLE_TEST_STEP(Translate, translate(SkIntToScalar(1), SkIntToScalar(2)));
|
|
|
|
SIMPLE_TEST_STEP(Scale, scale(SkIntToScalar(1), SkIntToScalar(2)));
|
|
|
|
SIMPLE_TEST_STEP(Rotate, rotate(SkIntToScalar(1)));
|
|
|
|
SIMPLE_TEST_STEP(Skew, skew(SkIntToScalar(1), SkIntToScalar(2)));
|
2014-10-03 20:26:55 +00:00
|
|
|
SIMPLE_TEST_STEP(Concat, concat(d.fMatrix));
|
|
|
|
SIMPLE_TEST_STEP(SetMatrix, setMatrix(d.fMatrix));
|
|
|
|
SIMPLE_TEST_STEP(ClipRect, clipRect(d.fRect));
|
|
|
|
SIMPLE_TEST_STEP(ClipPath, clipPath(d.fPath));
|
|
|
|
SIMPLE_TEST_STEP(ClipRegion, clipRegion(d.fRegion, SkRegion::kReplace_Op));
|
|
|
|
SIMPLE_TEST_STEP(Clear, clear(d.fColor));
|
|
|
|
SIMPLE_TEST_STEP(BeginGroup, beginCommentGroup(d.fText.c_str()));
|
|
|
|
SIMPLE_TEST_STEP(AddComment, addComment(d.fText.c_str(), d.fText.c_str()));
|
2013-05-29 13:24:23 +00:00
|
|
|
SIMPLE_TEST_STEP(EndGroup, endCommentGroup());
|
2012-02-22 21:00:42 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Complex test steps
|
|
|
|
|
2014-10-03 20:26:55 +00:00
|
|
|
static void SaveMatrixClipStep(SkCanvas* canvas, const TestData& d,
|
|
|
|
skiatest::Reporter* reporter, CanvasTestStep* testStep) {
|
2012-07-16 14:04:59 +00:00
|
|
|
int saveCount = canvas->getSaveCount();
|
2014-06-30 14:13:28 +00:00
|
|
|
canvas->save();
|
2012-07-16 14:04:59 +00:00
|
|
|
canvas->translate(SkIntToScalar(1), SkIntToScalar(2));
|
2014-10-03 20:26:55 +00:00
|
|
|
canvas->clipRegion(d.fRegion);
|
2012-07-16 14:04:59 +00:00
|
|
|
canvas->restore();
|
2012-08-23 18:14:13 +00:00
|
|
|
REPORTER_ASSERT_MESSAGE(reporter, canvas->getSaveCount() == saveCount,
|
2012-07-16 14:04:59 +00:00
|
|
|
testStep->assertMessage());
|
2012-08-23 18:14:13 +00:00
|
|
|
REPORTER_ASSERT_MESSAGE(reporter, canvas->getTotalMatrix().isIdentity(),
|
2012-07-16 14:04:59 +00:00
|
|
|
testStep->assertMessage());
|
2014-03-08 03:57:19 +00:00
|
|
|
// REPORTER_ASSERT_MESSAGE(reporter, canvas->getTotalClip() != kTestRegion, testStep->assertMessage());
|
2012-07-16 14:04:59 +00:00
|
|
|
}
|
|
|
|
TEST_STEP(SaveMatrixClip, SaveMatrixClipStep);
|
|
|
|
|
2014-10-03 20:26:55 +00:00
|
|
|
static void SaveLayerStep(SkCanvas* canvas, const TestData& d,
|
|
|
|
skiatest::Reporter* reporter, CanvasTestStep* testStep) {
|
2012-07-16 14:04:59 +00:00
|
|
|
int saveCount = canvas->getSaveCount();
|
|
|
|
canvas->saveLayer(NULL, NULL);
|
|
|
|
canvas->restore();
|
2012-08-23 18:14:13 +00:00
|
|
|
REPORTER_ASSERT_MESSAGE(reporter, canvas->getSaveCount() == saveCount,
|
2012-07-16 14:04:59 +00:00
|
|
|
testStep->assertMessage());
|
|
|
|
}
|
|
|
|
TEST_STEP(SaveLayer, SaveLayerStep);
|
|
|
|
|
2014-10-03 20:26:55 +00:00
|
|
|
static void BoundedSaveLayerStep(SkCanvas* canvas, const TestData& d,
|
|
|
|
skiatest::Reporter* reporter, CanvasTestStep* testStep) {
|
2012-07-16 14:04:59 +00:00
|
|
|
int saveCount = canvas->getSaveCount();
|
2014-10-03 20:26:55 +00:00
|
|
|
canvas->saveLayer(&d.fRect, NULL);
|
2012-07-16 14:04:59 +00:00
|
|
|
canvas->restore();
|
2012-08-23 18:14:13 +00:00
|
|
|
REPORTER_ASSERT_MESSAGE(reporter, canvas->getSaveCount() == saveCount,
|
2012-07-16 14:04:59 +00:00
|
|
|
testStep->assertMessage());
|
|
|
|
}
|
|
|
|
TEST_STEP(BoundedSaveLayer, BoundedSaveLayerStep);
|
|
|
|
|
2014-10-03 20:26:55 +00:00
|
|
|
static void PaintSaveLayerStep(SkCanvas* canvas, const TestData& d,
|
|
|
|
skiatest::Reporter* reporter, CanvasTestStep* testStep) {
|
2012-07-16 14:04:59 +00:00
|
|
|
int saveCount = canvas->getSaveCount();
|
2014-10-03 20:26:55 +00:00
|
|
|
canvas->saveLayer(NULL, &d.fPaint);
|
2012-07-16 14:04:59 +00:00
|
|
|
canvas->restore();
|
2012-08-23 18:14:13 +00:00
|
|
|
REPORTER_ASSERT_MESSAGE(reporter, canvas->getSaveCount() == saveCount,
|
2012-07-16 14:04:59 +00:00
|
|
|
testStep->assertMessage());
|
|
|
|
}
|
|
|
|
TEST_STEP(PaintSaveLayer, PaintSaveLayerStep);
|
|
|
|
|
2014-10-03 20:26:55 +00:00
|
|
|
static void TwoClipOpsStep(SkCanvas* canvas, const TestData& d,
|
|
|
|
skiatest::Reporter*, CanvasTestStep*) {
|
2012-07-12 17:47:34 +00:00
|
|
|
// This test exercises a functionality in SkPicture that leads to the
|
2012-08-23 18:14:13 +00:00
|
|
|
// recording of restore offset placeholders. This test will trigger an
|
2012-07-12 17:47:34 +00:00
|
|
|
// assertion at playback time if the placeholders are not properly
|
|
|
|
// filled when the recording ends.
|
2014-10-03 20:26:55 +00:00
|
|
|
canvas->clipRect(d.fRect);
|
|
|
|
canvas->clipRegion(d.fRegion);
|
2012-07-12 17:47:34 +00:00
|
|
|
}
|
|
|
|
TEST_STEP(TwoClipOps, TwoClipOpsStep);
|
|
|
|
|
2012-04-11 17:51:01 +00:00
|
|
|
// exercise fix for http://code.google.com/p/skia/issues/detail?id=560
|
|
|
|
// ('SkPathStroker::lineTo() fails for line with length SK_ScalarNearlyZero')
|
2014-10-03 20:26:55 +00:00
|
|
|
static void DrawNearlyZeroLengthPathTestStep(SkCanvas* canvas, const TestData& d,
|
|
|
|
skiatest::Reporter*, CanvasTestStep*) {
|
2012-04-11 17:51:01 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setStrokeWidth(SkIntToScalar(1));
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
|
2014-10-03 20:26:55 +00:00
|
|
|
canvas->drawPath(d.fNearlyZeroLengthPath, paint);
|
2012-04-11 17:51:01 +00:00
|
|
|
}
|
|
|
|
TEST_STEP(DrawNearlyZeroLengthPath, DrawNearlyZeroLengthPathTestStep);
|
|
|
|
|
2014-10-03 20:26:55 +00:00
|
|
|
static void DrawVerticesShaderTestStep(SkCanvas* canvas, const TestData& d,
|
|
|
|
skiatest::Reporter*, CanvasTestStep*) {
|
2012-02-22 21:00:42 +00:00
|
|
|
SkPoint pts[4];
|
|
|
|
pts[0].set(0, 0);
|
2014-10-03 20:26:55 +00:00
|
|
|
pts[1].set(SkIntToScalar(d.fWidth), 0);
|
|
|
|
pts[2].set(SkIntToScalar(d.fWidth), SkIntToScalar(d.fHeight));
|
|
|
|
pts[3].set(0, SkIntToScalar(d.fHeight));
|
2012-02-22 21:00:42 +00:00
|
|
|
SkPaint paint;
|
2014-10-03 20:26:55 +00:00
|
|
|
SkShader* shader = SkShader::CreateBitmapShader(d.fBitmap,
|
2012-02-22 21:00:42 +00:00
|
|
|
SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
|
|
|
|
paint.setShader(shader)->unref();
|
|
|
|
canvas->drawVertices(SkCanvas::kTriangleFan_VertexMode, 4, pts, pts,
|
|
|
|
NULL, NULL, NULL, 0, paint);
|
|
|
|
}
|
2012-10-18 15:58:23 +00:00
|
|
|
// NYI: issue 240.
|
|
|
|
TEST_STEP_NO_PDF(DrawVerticesShader, DrawVerticesShaderTestStep);
|
2012-02-22 21:00:42 +00:00
|
|
|
|
2014-10-03 20:26:55 +00:00
|
|
|
static void DrawPictureTestStep(SkCanvas* canvas, const TestData& d,
|
|
|
|
skiatest::Reporter*, CanvasTestStep*) {
|
2014-04-13 19:09:42 +00:00
|
|
|
SkPictureRecorder recorder;
|
2014-10-03 20:26:55 +00:00
|
|
|
SkCanvas* testCanvas = recorder.beginRecording(SkIntToScalar(d.fWidth), SkIntToScalar(d.fHeight),
|
2014-08-29 15:03:56 +00:00
|
|
|
NULL, 0);
|
2012-02-22 21:00:42 +00:00
|
|
|
testCanvas->scale(SkIntToScalar(2), SkIntToScalar(1));
|
2014-10-03 20:26:55 +00:00
|
|
|
testCanvas->clipRect(d.fRect);
|
|
|
|
testCanvas->drawRect(d.fRect, d.fPaint);
|
2014-04-13 19:09:42 +00:00
|
|
|
SkAutoTUnref<SkPicture> testPicture(recorder.endRecording());
|
|
|
|
|
2014-06-04 12:40:44 +00:00
|
|
|
canvas->drawPicture(testPicture);
|
2012-02-22 21:00:42 +00:00
|
|
|
}
|
|
|
|
TEST_STEP(DrawPicture, DrawPictureTestStep);
|
|
|
|
|
2014-10-03 20:26:55 +00:00
|
|
|
static void SaveRestoreTestStep(SkCanvas* canvas, const TestData& d,
|
|
|
|
skiatest::Reporter* reporter, CanvasTestStep* testStep) {
|
2012-07-16 14:04:59 +00:00
|
|
|
int baseSaveCount = canvas->getSaveCount();
|
2012-08-14 15:03:35 +00:00
|
|
|
int n = canvas->save();
|
2012-07-16 14:04:59 +00:00
|
|
|
REPORTER_ASSERT_MESSAGE(reporter, baseSaveCount == n, testStep->assertMessage());
|
|
|
|
REPORTER_ASSERT_MESSAGE(reporter, baseSaveCount + 1 == canvas->getSaveCount(),
|
2012-02-22 21:00:42 +00:00
|
|
|
testStep->assertMessage());
|
|
|
|
canvas->save();
|
|
|
|
canvas->save();
|
2012-07-16 14:04:59 +00:00
|
|
|
REPORTER_ASSERT_MESSAGE(reporter, baseSaveCount + 3 == canvas->getSaveCount(),
|
2012-02-22 21:00:42 +00:00
|
|
|
testStep->assertMessage());
|
2012-07-16 14:04:59 +00:00
|
|
|
canvas->restoreToCount(baseSaveCount + 1);
|
|
|
|
REPORTER_ASSERT_MESSAGE(reporter, baseSaveCount + 1 == canvas->getSaveCount(),
|
2012-02-22 21:00:42 +00:00
|
|
|
testStep->assertMessage());
|
|
|
|
|
|
|
|
// should this pin to 1, or be a no-op, or crash?
|
|
|
|
canvas->restoreToCount(0);
|
|
|
|
REPORTER_ASSERT_MESSAGE(reporter, 1 == canvas->getSaveCount(),
|
|
|
|
testStep->assertMessage());
|
|
|
|
}
|
|
|
|
TEST_STEP(SaveRestore, SaveRestoreTestStep);
|
2011-12-14 18:48:05 +00:00
|
|
|
|
2014-10-03 20:26:55 +00:00
|
|
|
static void NestedSaveRestoreWithSolidPaintTestStep(SkCanvas* canvas, const TestData& d,
|
|
|
|
skiatest::Reporter*, CanvasTestStep*) {
|
2012-08-16 20:53:31 +00:00
|
|
|
// This test step challenges the TestDeferredCanvasStateConsistency
|
|
|
|
// test cases because the opaque paint can trigger an optimization
|
|
|
|
// that discards previously recorded commands. The challenge is to maintain
|
|
|
|
// correct clip and matrix stack state.
|
|
|
|
canvas->resetMatrix();
|
|
|
|
canvas->rotate(SkIntToScalar(30));
|
|
|
|
canvas->save();
|
|
|
|
canvas->translate(SkIntToScalar(2), SkIntToScalar(1));
|
|
|
|
canvas->save();
|
|
|
|
canvas->scale(SkIntToScalar(3), SkIntToScalar(3));
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(0xFFFFFFFF);
|
|
|
|
canvas->drawPaint(paint);
|
|
|
|
canvas->restore();
|
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
TEST_STEP(NestedSaveRestoreWithSolidPaint, \
|
|
|
|
NestedSaveRestoreWithSolidPaintTestStep);
|
|
|
|
|
2014-10-03 20:26:55 +00:00
|
|
|
static void NestedSaveRestoreWithFlushTestStep(SkCanvas* canvas, const TestData& d,
|
|
|
|
skiatest::Reporter*, CanvasTestStep*) {
|
2012-08-16 20:53:31 +00:00
|
|
|
// This test step challenges the TestDeferredCanvasStateConsistency
|
|
|
|
// test case because the canvas flush on a deferred canvas will
|
|
|
|
// reset the recording session. The challenge is to maintain correct
|
|
|
|
// clip and matrix stack state on the playback canvas.
|
|
|
|
canvas->resetMatrix();
|
|
|
|
canvas->rotate(SkIntToScalar(30));
|
|
|
|
canvas->save();
|
|
|
|
canvas->translate(SkIntToScalar(2), SkIntToScalar(1));
|
|
|
|
canvas->save();
|
|
|
|
canvas->scale(SkIntToScalar(3), SkIntToScalar(3));
|
2014-10-03 20:26:55 +00:00
|
|
|
canvas->drawRect(d.fRect,d.fPaint);
|
2012-08-16 20:53:31 +00:00
|
|
|
canvas->flush();
|
|
|
|
canvas->restore();
|
|
|
|
canvas->restore();
|
|
|
|
}
|
2014-10-03 20:26:55 +00:00
|
|
|
TEST_STEP(NestedSaveRestoreWithFlush, NestedSaveRestoreWithFlushTestStep);
|
2011-11-28 16:06:04 +00:00
|
|
|
|
2014-10-03 20:26:55 +00:00
|
|
|
static void AssertCanvasStatesEqual(skiatest::Reporter* reporter, const TestData& d,
|
|
|
|
const SkCanvas* canvas1, const SkCanvas* canvas2,
|
2012-02-22 21:00:42 +00:00
|
|
|
CanvasTestStep* testStep) {
|
|
|
|
REPORTER_ASSERT_MESSAGE(reporter, canvas1->getDeviceSize() ==
|
|
|
|
canvas2->getDeviceSize(), testStep->assertMessage());
|
|
|
|
REPORTER_ASSERT_MESSAGE(reporter, canvas1->getSaveCount() ==
|
|
|
|
canvas2->getSaveCount(), testStep->assertMessage());
|
2012-08-16 20:53:31 +00:00
|
|
|
|
2012-02-22 21:00:42 +00:00
|
|
|
SkRect bounds1, bounds2;
|
|
|
|
REPORTER_ASSERT_MESSAGE(reporter,
|
2012-08-16 20:53:31 +00:00
|
|
|
canvas1->getClipBounds(&bounds1) == canvas2->getClipBounds(&bounds2),
|
2012-02-22 21:00:42 +00:00
|
|
|
testStep->assertMessage());
|
|
|
|
REPORTER_ASSERT_MESSAGE(reporter, bounds1 == bounds2,
|
2012-08-16 20:53:31 +00:00
|
|
|
testStep->assertMessage());
|
|
|
|
|
2012-02-22 21:00:42 +00:00
|
|
|
REPORTER_ASSERT_MESSAGE(reporter, canvas1->getDrawFilter() ==
|
|
|
|
canvas2->getDrawFilter(), testStep->assertMessage());
|
|
|
|
SkIRect deviceBounds1, deviceBounds2;
|
|
|
|
REPORTER_ASSERT_MESSAGE(reporter,
|
|
|
|
canvas1->getClipDeviceBounds(&deviceBounds1) ==
|
|
|
|
canvas2->getClipDeviceBounds(&deviceBounds2),
|
|
|
|
testStep->assertMessage());
|
2014-06-03 17:53:59 +00:00
|
|
|
REPORTER_ASSERT_MESSAGE(reporter, deviceBounds1 == deviceBounds2, testStep->assertMessage());
|
2012-02-22 21:00:42 +00:00
|
|
|
REPORTER_ASSERT_MESSAGE(reporter, canvas1->getTotalMatrix() ==
|
|
|
|
canvas2->getTotalMatrix(), testStep->assertMessage());
|
2014-03-08 03:57:19 +00:00
|
|
|
REPORTER_ASSERT_MESSAGE(reporter, equal_clips(*canvas1, *canvas2), testStep->assertMessage());
|
2011-11-28 16:06:04 +00:00
|
|
|
|
2012-02-22 21:00:42 +00:00
|
|
|
SkCanvas::LayerIter layerIter1(const_cast<SkCanvas*>(canvas1), false);
|
|
|
|
SkCanvas::LayerIter layerIter2(const_cast<SkCanvas*>(canvas2), false);
|
|
|
|
while (!layerIter1.done() && !layerIter2.done()) {
|
|
|
|
REPORTER_ASSERT_MESSAGE(reporter, layerIter1.matrix() ==
|
|
|
|
layerIter2.matrix(), testStep->assertMessage());
|
|
|
|
REPORTER_ASSERT_MESSAGE(reporter, layerIter1.clip() ==
|
|
|
|
layerIter2.clip(), testStep->assertMessage());
|
|
|
|
REPORTER_ASSERT_MESSAGE(reporter, layerIter1.paint() ==
|
|
|
|
layerIter2.paint(), testStep->assertMessage());
|
|
|
|
REPORTER_ASSERT_MESSAGE(reporter, layerIter1.x() ==
|
|
|
|
layerIter2.x(), testStep->assertMessage());
|
|
|
|
REPORTER_ASSERT_MESSAGE(reporter, layerIter1.y() ==
|
|
|
|
layerIter2.y(), testStep->assertMessage());
|
|
|
|
layerIter1.next();
|
|
|
|
layerIter2.next();
|
|
|
|
}
|
|
|
|
REPORTER_ASSERT_MESSAGE(reporter, layerIter1.done(),
|
|
|
|
testStep->assertMessage());
|
|
|
|
REPORTER_ASSERT_MESSAGE(reporter, layerIter2.done(),
|
|
|
|
testStep->assertMessage());
|
2014-10-27 22:31:34 +00:00
|
|
|
|
2012-02-22 21:00:42 +00:00
|
|
|
}
|
|
|
|
|
2012-10-18 15:58:23 +00:00
|
|
|
static void TestPdfDevice(skiatest::Reporter* reporter,
|
2014-10-03 20:26:55 +00:00
|
|
|
const TestData& d,
|
2012-10-18 15:58:23 +00:00
|
|
|
CanvasTestStep* testStep) {
|
2014-10-03 20:26:55 +00:00
|
|
|
SkISize pageSize = SkISize::Make(d.fWidth, d.fHeight);
|
2015-02-20 14:17:26 +00:00
|
|
|
SkPDFCanon canon;
|
|
|
|
SkAutoTUnref<SkPDFDevice> pdfDevice(
|
|
|
|
SkPDFDevice::Create(pageSize, 72.0f, &canon));
|
|
|
|
SkCanvas canvas(pdfDevice.get());
|
2012-10-18 15:58:23 +00:00
|
|
|
testStep->setAssertMessageFormat(kPdfAssertMessageFormat);
|
2014-10-03 20:26:55 +00:00
|
|
|
testStep->draw(&canvas, d, reporter);
|
2012-10-18 15:58:23 +00:00
|
|
|
SkPDFDocument doc;
|
2015-02-20 14:17:26 +00:00
|
|
|
doc.appendPage(pdfDevice.get());
|
2012-10-18 15:58:23 +00:00
|
|
|
SkDynamicMemoryWStream stream;
|
|
|
|
doc.emitPDF(&stream);
|
|
|
|
}
|
|
|
|
|
2012-08-07 16:48:22 +00:00
|
|
|
// The following class groups static functions that need to access
|
|
|
|
// the privates members of SkDeferredCanvas
|
|
|
|
class SkDeferredCanvasTester {
|
|
|
|
public:
|
|
|
|
static void TestDeferredCanvasStateConsistency(
|
|
|
|
skiatest::Reporter* reporter,
|
2014-10-03 20:26:55 +00:00
|
|
|
const TestData& d,
|
2012-08-07 16:48:22 +00:00
|
|
|
CanvasTestStep* testStep,
|
2012-09-20 19:35:43 +00:00
|
|
|
const SkCanvas& referenceCanvas, bool silent) {
|
2012-08-07 16:48:22 +00:00
|
|
|
|
2014-02-04 15:34:10 +00:00
|
|
|
SkAutoTUnref<SkSurface> surface(createSurface(0xFFFFFFFF));
|
|
|
|
SkAutoTUnref<SkDeferredCanvas> deferredCanvas(SkDeferredCanvas::Create(surface.get()));
|
|
|
|
|
2012-08-07 16:48:22 +00:00
|
|
|
testStep->setAssertMessageFormat(kDeferredDrawAssertMessageFormat);
|
2014-10-03 20:26:55 +00:00
|
|
|
testStep->draw(deferredCanvas, d, reporter);
|
2012-08-07 16:48:22 +00:00
|
|
|
testStep->setAssertMessageFormat(kDeferredPreFlushAssertMessageFormat);
|
2014-10-03 20:26:55 +00:00
|
|
|
AssertCanvasStatesEqual(reporter, d, deferredCanvas, &referenceCanvas, testStep);
|
2012-08-07 16:48:22 +00:00
|
|
|
|
2012-09-20 19:35:43 +00:00
|
|
|
if (silent) {
|
2013-05-28 17:39:08 +00:00
|
|
|
deferredCanvas->silentFlush();
|
2012-09-20 19:35:43 +00:00
|
|
|
} else {
|
2013-05-28 17:39:08 +00:00
|
|
|
deferredCanvas->flush();
|
2012-09-20 19:35:43 +00:00
|
|
|
}
|
|
|
|
|
2012-09-21 02:01:01 +00:00
|
|
|
testStep->setAssertMessageFormat(
|
2012-09-20 19:35:43 +00:00
|
|
|
silent ? kDeferredPostSilentFlushPlaybackAssertMessageFormat :
|
2012-08-07 16:48:22 +00:00
|
|
|
kDeferredPostFlushPlaybackAssertMessageFormat);
|
2014-10-03 20:26:55 +00:00
|
|
|
AssertCanvasStatesEqual(reporter, d, deferredCanvas->immediateCanvas(),
|
|
|
|
&referenceCanvas, testStep);
|
2012-08-07 16:48:22 +00:00
|
|
|
|
|
|
|
// Verified that deferred canvas state is not affected by flushing
|
|
|
|
// pending draw operations
|
|
|
|
|
|
|
|
// The following test code is commented out because it currently fails.
|
|
|
|
// Issue: http://code.google.com/p/skia/issues/detail?id=496
|
|
|
|
/*
|
|
|
|
testStep->setAssertMessageFormat(kDeferredPostFlushAssertMessageFormat);
|
|
|
|
AssertCanvasStatesEqual(reporter, &deferredCanvas, &referenceCanvas,
|
|
|
|
testStep);
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
};
|
2012-02-22 21:00:42 +00:00
|
|
|
|
2012-06-06 12:03:39 +00:00
|
|
|
// unused
|
2012-02-22 21:00:42 +00:00
|
|
|
static void TestNWayCanvasStateConsistency(
|
|
|
|
skiatest::Reporter* reporter,
|
2014-10-03 20:26:55 +00:00
|
|
|
const TestData& d,
|
2012-02-22 21:00:42 +00:00
|
|
|
CanvasTestStep* testStep,
|
|
|
|
const SkCanvas& referenceCanvas) {
|
|
|
|
|
|
|
|
SkBitmap indirectStore1;
|
2014-02-13 22:00:04 +00:00
|
|
|
createBitmap(&indirectStore1, 0xFFFFFFFF);
|
2014-06-27 05:12:09 +00:00
|
|
|
SkCanvas indirectCanvas1(indirectStore1);
|
2012-02-22 21:00:42 +00:00
|
|
|
|
|
|
|
SkBitmap indirectStore2;
|
2014-02-13 22:00:04 +00:00
|
|
|
createBitmap(&indirectStore2, 0xFFFFFFFF);
|
2014-06-27 05:12:09 +00:00
|
|
|
SkCanvas indirectCanvas2(indirectStore2);
|
2012-02-22 21:00:42 +00:00
|
|
|
|
2012-05-01 16:50:25 +00:00
|
|
|
SkISize canvasSize = referenceCanvas.getDeviceSize();
|
|
|
|
SkNWayCanvas nWayCanvas(canvasSize.width(), canvasSize.height());
|
2012-02-22 21:00:42 +00:00
|
|
|
nWayCanvas.addCanvas(&indirectCanvas1);
|
|
|
|
nWayCanvas.addCanvas(&indirectCanvas2);
|
|
|
|
|
|
|
|
testStep->setAssertMessageFormat(kNWayDrawAssertMessageFormat);
|
2014-10-03 20:26:55 +00:00
|
|
|
testStep->draw(&nWayCanvas, d, reporter);
|
2015-01-29 19:58:51 +00:00
|
|
|
// Verify that the SkNWayCanvas reports consitent state
|
2012-02-22 21:00:42 +00:00
|
|
|
testStep->setAssertMessageFormat(kNWayStateAssertMessageFormat);
|
2014-10-03 20:26:55 +00:00
|
|
|
AssertCanvasStatesEqual(reporter, d, &nWayCanvas, &referenceCanvas, testStep);
|
2012-02-22 21:00:42 +00:00
|
|
|
// Verify that the indirect canvases report consitent state
|
|
|
|
testStep->setAssertMessageFormat(kNWayIndirect1StateAssertMessageFormat);
|
2014-10-03 20:26:55 +00:00
|
|
|
AssertCanvasStatesEqual(reporter, d, &indirectCanvas1, &referenceCanvas, testStep);
|
2012-02-22 21:00:42 +00:00
|
|
|
testStep->setAssertMessageFormat(kNWayIndirect2StateAssertMessageFormat);
|
2014-10-03 20:26:55 +00:00
|
|
|
AssertCanvasStatesEqual(reporter, d, &indirectCanvas2, &referenceCanvas, testStep);
|
2012-02-22 21:00:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This sub-test verifies that the test step passes when executed
|
|
|
|
* with SkCanvas and with classes derrived from SkCanvas. It also verifies
|
|
|
|
* that the all canvas derivatives report the same state as an SkCanvas
|
|
|
|
* after having executed the test step.
|
|
|
|
*/
|
2014-10-03 20:26:55 +00:00
|
|
|
static void TestOverrideStateConsistency(skiatest::Reporter* reporter, const TestData& d,
|
2012-02-22 21:00:42 +00:00
|
|
|
CanvasTestStep* testStep) {
|
|
|
|
SkBitmap referenceStore;
|
2014-02-13 22:00:04 +00:00
|
|
|
createBitmap(&referenceStore, 0xFFFFFFFF);
|
2014-06-27 05:12:09 +00:00
|
|
|
SkCanvas referenceCanvas(referenceStore);
|
2012-02-22 21:00:42 +00:00
|
|
|
testStep->setAssertMessageFormat(kCanvasDrawAssertMessageFormat);
|
2014-10-03 20:26:55 +00:00
|
|
|
testStep->draw(&referenceCanvas, d, reporter);
|
2012-02-22 21:00:42 +00:00
|
|
|
|
2014-10-03 20:26:55 +00:00
|
|
|
SkDeferredCanvasTester::TestDeferredCanvasStateConsistency(reporter, d, testStep, referenceCanvas, false);
|
2012-09-20 19:35:43 +00:00
|
|
|
|
2014-10-03 20:26:55 +00:00
|
|
|
SkDeferredCanvasTester::TestDeferredCanvasStateConsistency(reporter, d, testStep, referenceCanvas, true);
|
2012-02-22 21:00:42 +00:00
|
|
|
|
2012-06-06 12:03:39 +00:00
|
|
|
// The following test code is disabled because SkNWayCanvas does not
|
2012-02-22 21:00:42 +00:00
|
|
|
// report correct clipping and device bounds information
|
|
|
|
// Issue: http://code.google.com/p/skia/issues/detail?id=501
|
2012-06-06 12:03:39 +00:00
|
|
|
|
|
|
|
if (false) { // avoid bit rot, suppress warning
|
2014-10-03 20:26:55 +00:00
|
|
|
TestNWayCanvasStateConsistency(reporter, d, testStep, referenceCanvas);
|
2012-06-06 12:03:39 +00:00
|
|
|
}
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-06-06 12:03:39 +00:00
|
|
|
if (false) { // avoid bit rot, suppress warning
|
|
|
|
test_clipVisitor(reporter, &referenceCanvas);
|
|
|
|
}
|
2012-02-22 21:00:42 +00:00
|
|
|
}
|
|
|
|
|
2014-02-27 20:32:51 +00:00
|
|
|
static void test_newraster(skiatest::Reporter* reporter) {
|
|
|
|
SkImageInfo info = SkImageInfo::MakeN32Premul(10, 10);
|
2014-12-10 15:24:28 +00:00
|
|
|
const size_t minRowBytes = info.minRowBytes();
|
|
|
|
const size_t size = info.getSafeSize(minRowBytes);
|
|
|
|
SkAutoMalloc storage(size);
|
|
|
|
SkPMColor* baseAddr = static_cast<SkPMColor*>(storage.get());
|
|
|
|
sk_bzero(baseAddr, size);
|
|
|
|
|
|
|
|
SkCanvas* canvas = SkCanvas::NewRasterDirect(info, baseAddr, minRowBytes);
|
2014-02-27 20:32:51 +00:00
|
|
|
REPORTER_ASSERT(reporter, canvas);
|
|
|
|
|
|
|
|
SkImageInfo info2;
|
|
|
|
size_t rowBytes;
|
|
|
|
const SkPMColor* addr = (const SkPMColor*)canvas->peekPixels(&info2, &rowBytes);
|
|
|
|
REPORTER_ASSERT(reporter, addr);
|
|
|
|
REPORTER_ASSERT(reporter, info == info2);
|
2014-12-10 15:24:28 +00:00
|
|
|
REPORTER_ASSERT(reporter, minRowBytes == rowBytes);
|
2014-02-27 20:32:51 +00:00
|
|
|
for (int y = 0; y < info.height(); ++y) {
|
|
|
|
for (int x = 0; x < info.width(); ++x) {
|
|
|
|
REPORTER_ASSERT(reporter, 0 == addr[x]);
|
|
|
|
}
|
|
|
|
addr = (const SkPMColor*)((const char*)addr + rowBytes);
|
|
|
|
}
|
|
|
|
SkDELETE(canvas);
|
|
|
|
|
|
|
|
// now try a deliberately bad info
|
2014-09-03 18:54:58 +00:00
|
|
|
info = info.makeWH(-1, info.height());
|
2014-12-10 15:24:28 +00:00
|
|
|
REPORTER_ASSERT(reporter, NULL == SkCanvas::NewRasterDirect(info, baseAddr, minRowBytes));
|
2014-02-27 20:32:51 +00:00
|
|
|
|
|
|
|
// too big
|
2014-09-03 18:54:58 +00:00
|
|
|
info = info.makeWH(1 << 30, 1 << 30);
|
2014-12-10 15:24:28 +00:00
|
|
|
REPORTER_ASSERT(reporter, NULL == SkCanvas::NewRasterDirect(info, baseAddr, minRowBytes));
|
2014-02-28 03:02:05 +00:00
|
|
|
|
2014-02-27 20:32:51 +00:00
|
|
|
// not a valid pixel type
|
2014-09-03 18:54:58 +00:00
|
|
|
info = SkImageInfo::Make(10, 10, kUnknown_SkColorType, info.alphaType());
|
2014-12-10 15:24:28 +00:00
|
|
|
REPORTER_ASSERT(reporter, NULL == SkCanvas::NewRasterDirect(info, baseAddr, minRowBytes));
|
2014-02-27 20:32:51 +00:00
|
|
|
|
|
|
|
// We should succeed with a zero-sized valid info
|
|
|
|
info = SkImageInfo::MakeN32Premul(0, 0);
|
2014-12-10 15:24:28 +00:00
|
|
|
canvas = SkCanvas::NewRasterDirect(info, baseAddr, minRowBytes);
|
2014-02-27 20:32:51 +00:00
|
|
|
REPORTER_ASSERT(reporter, canvas);
|
|
|
|
SkDELETE(canvas);
|
|
|
|
}
|
|
|
|
|
2013-12-12 21:11:12 +00:00
|
|
|
DEF_TEST(Canvas, reporter) {
|
2014-10-03 20:26:55 +00:00
|
|
|
TestData d;
|
2011-12-14 18:48:05 +00:00
|
|
|
|
2012-02-22 21:00:42 +00:00
|
|
|
for (int testStep = 0; testStep < testStepArray().count(); testStep++) {
|
2014-10-03 20:26:55 +00:00
|
|
|
TestOverrideStateConsistency(reporter, d, testStepArray()[testStep]);
|
2012-10-18 15:58:23 +00:00
|
|
|
if (testStepArray()[testStep]->enablePdfTesting()) {
|
2014-10-03 20:26:55 +00:00
|
|
|
TestPdfDevice(reporter, d, testStepArray()[testStep]);
|
2012-10-18 15:58:23 +00:00
|
|
|
}
|
2012-02-22 21:00:42 +00:00
|
|
|
}
|
2012-08-02 17:43:25 +00:00
|
|
|
|
2014-02-27 20:32:51 +00:00
|
|
|
test_newraster(reporter);
|
2011-11-28 16:06:04 +00:00
|
|
|
}
|
2014-11-26 16:55:51 +00:00
|
|
|
|
|
|
|
DEF_TEST(Canvas_SaveState, reporter) {
|
|
|
|
SkCanvas canvas(10, 10);
|
|
|
|
REPORTER_ASSERT(reporter, 1 == canvas.getSaveCount());
|
|
|
|
|
|
|
|
int n = canvas.save();
|
|
|
|
REPORTER_ASSERT(reporter, 1 == n);
|
|
|
|
REPORTER_ASSERT(reporter, 2 == canvas.getSaveCount());
|
|
|
|
|
|
|
|
n = canvas.saveLayer(NULL, NULL);
|
|
|
|
REPORTER_ASSERT(reporter, 2 == n);
|
|
|
|
REPORTER_ASSERT(reporter, 3 == canvas.getSaveCount());
|
|
|
|
|
|
|
|
canvas.restore();
|
|
|
|
REPORTER_ASSERT(reporter, 2 == canvas.getSaveCount());
|
|
|
|
canvas.restore();
|
|
|
|
REPORTER_ASSERT(reporter, 1 == canvas.getSaveCount());
|
|
|
|
}
|