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"
|
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"
|
|
|
|
#include "SkProxyCanvas.h"
|
|
|
|
#include "SkRect.h"
|
|
|
|
#include "SkRegion.h"
|
|
|
|
#include "SkShader.h"
|
|
|
|
#include "SkStream.h"
|
|
|
|
#include "SkTDArray.h"
|
|
|
|
#include "Test.h"
|
2011-11-28 16:06:04 +00:00
|
|
|
|
2012-04-13 13:50:27 +00:00
|
|
|
class Canvas2CanvasClipVisitor : public SkCanvas::ClipVisitor {
|
|
|
|
public:
|
|
|
|
Canvas2CanvasClipVisitor(SkCanvas* target) : fTarget(target) {}
|
|
|
|
|
|
|
|
virtual void clipRect(const SkRect& r, SkRegion::Op op, bool aa) {
|
|
|
|
fTarget->clipRect(r, op, aa);
|
|
|
|
}
|
|
|
|
virtual void clipPath(const SkPath& p, SkRegion::Op op, bool aa) {
|
|
|
|
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;
|
|
|
|
bm.setConfig(SkBitmap::kARGB_8888_Config, size.width(), size.height());
|
|
|
|
SkCanvas c(bm);
|
|
|
|
|
|
|
|
Canvas2CanvasClipVisitor visitor(&c);
|
|
|
|
canvas->replayClips(&visitor);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, c.getTotalClip() == canvas->getTotalClip());
|
|
|
|
}
|
|
|
|
|
2012-02-22 21:00:42 +00:00
|
|
|
static const int kWidth = 2;
|
|
|
|
static const int kHeight = 2;
|
|
|
|
// Maximum stream length for picture serialization
|
2012-08-23 18:14:13 +00:00
|
|
|
static const size_t kMaxPictureBufferSize = 1024;
|
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 kPictureDrawAssertMessageFormat =
|
2012-02-22 21:00:42 +00:00
|
|
|
"Drawing test step %s with SkPicture";
|
2012-08-23 18:14:13 +00:00
|
|
|
static const char* const kPictureSecondDrawAssertMessageFormat =
|
2012-02-22 21:00:42 +00:00
|
|
|
"Duplicate draw of test step %s with SkPicture";
|
2012-08-23 18:14:13 +00:00
|
|
|
static const char* const kPictureReDrawAssertMessageFormat =
|
2012-02-22 21:00:42 +00:00
|
|
|
"Playing back test step %s from an SkPicture to another SkPicture";
|
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 kProxyDrawAssertMessageFormat =
|
2012-02-22 21:00:42 +00:00
|
|
|
"Drawing test step %s with SkProxyCanvas";
|
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 kRoundTripAssertMessageFormat =
|
2012-02-22 21:00:42 +00:00
|
|
|
"test step %s, SkPicture consistency after round trip";
|
2012-08-23 18:14:13 +00:00
|
|
|
static const char* const kPictureRecoringAssertMessageFormat =
|
2012-02-22 21:00:42 +00:00
|
|
|
"test step %s, SkPicture state consistency after recording";
|
2012-08-23 18:14:13 +00:00
|
|
|
static const char* const kPicturePlaybackAssertMessageFormat =
|
2012-02-22 21:00:42 +00:00
|
|
|
"test step %s, SkPicture state consistency in playback canvas";
|
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-08-23 18:14:13 +00:00
|
|
|
static const char* const kDeferredPostFlushAssertMessageFormat =
|
2012-02-22 21:00:42 +00:00
|
|
|
"test step %s, SkDeferredCanvas state consistency after flush";
|
|
|
|
static const char* const kPictureResourceReuseMessageFormat =
|
|
|
|
"test step %s, SkPicture duplicate flattened object test";
|
|
|
|
static const char* const kProxyStateAssertMessageFormat =
|
|
|
|
"test step %s, SkProxyCanvas state consistency";
|
|
|
|
static const char* const kProxyIndirectStateAssertMessageFormat =
|
|
|
|
"test step %s, SkProxyCanvas indirect canvas state consistency";
|
|
|
|
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
|
|
|
|
|
|
|
static void createBitmap(SkBitmap* bm, SkBitmap::Config config, SkColor color) {
|
|
|
|
bm->setConfig(config, kWidth, kHeight);
|
|
|
|
bm->allocPixels();
|
|
|
|
bm->eraseColor(color);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
virtual void draw(SkCanvas*, skiatest::Reporter*) = 0;
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Constants used by test steps
|
|
|
|
|
2012-08-23 18:14:13 +00:00
|
|
|
const SkRect kTestRect =
|
2012-02-22 21:00:42 +00:00
|
|
|
SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0),
|
|
|
|
SkIntToScalar(2), SkIntToScalar(1));
|
|
|
|
static SkMatrix testMatrix() {
|
|
|
|
SkMatrix matrix;
|
|
|
|
matrix.reset();
|
|
|
|
matrix.setScale(SkIntToScalar(2), SkIntToScalar(3));
|
|
|
|
return matrix;
|
|
|
|
}
|
|
|
|
const SkMatrix kTestMatrix = testMatrix();
|
|
|
|
static SkPath testPath() {
|
|
|
|
SkPath path;
|
|
|
|
path.addRect(SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0),
|
|
|
|
SkIntToScalar(2), SkIntToScalar(1)));
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
const SkPath kTestPath = testPath();
|
|
|
|
static SkRegion testRegion() {
|
|
|
|
SkRegion region;
|
|
|
|
SkIRect rect = SkIRect::MakeXYWH(0, 0, 2, 1);
|
|
|
|
region.setRect(rect);
|
|
|
|
return region;
|
|
|
|
}
|
|
|
|
const SkIRect kTestIRect = SkIRect::MakeXYWH(0, 0, 2, 1);
|
|
|
|
const SkRegion kTestRegion = testRegion();
|
|
|
|
const SkColor kTestColor = 0x01020304;
|
|
|
|
const SkPaint kTestPaint;
|
|
|
|
const SkPoint kTestPoints[3] = {
|
|
|
|
{SkIntToScalar(0), SkIntToScalar(0)},
|
|
|
|
{SkIntToScalar(2), SkIntToScalar(1)},
|
|
|
|
{SkIntToScalar(0), SkIntToScalar(2)}
|
|
|
|
};
|
|
|
|
const size_t kTestPointCount = 3;
|
|
|
|
static SkBitmap testBitmap() {
|
|
|
|
SkBitmap bitmap;
|
|
|
|
createBitmap(&bitmap, SkBitmap::kARGB_8888_Config, 0x05060708);
|
|
|
|
return bitmap;
|
|
|
|
}
|
|
|
|
SkBitmap kTestBitmap; // cannot be created during static init
|
|
|
|
SkString kTestText("Hello World");
|
2012-06-05 19:35:09 +00:00
|
|
|
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) },
|
|
|
|
};
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-02-22 21:00:42 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Macros for defining test steps
|
|
|
|
|
|
|
|
#define TEST_STEP(NAME, FUNCTION) \
|
|
|
|
class NAME##_TestStep : public CanvasTestStep{ \
|
|
|
|
public: \
|
|
|
|
virtual void draw(SkCanvas* canvas, skiatest::Reporter* reporter) { \
|
|
|
|
FUNCTION (canvas, reporter, this); \
|
|
|
|
} \
|
|
|
|
virtual const char* name() const {return #NAME ;} \
|
|
|
|
}; \
|
|
|
|
static NAME##_TestStep NAME##_TestStepInstance;
|
|
|
|
|
2012-10-18 15:58:23 +00:00
|
|
|
#define TEST_STEP_NO_PDF(NAME, FUNCTION) \
|
|
|
|
class NAME##_TestStep : public CanvasTestStep{ \
|
|
|
|
public: \
|
|
|
|
NAME##_TestStep() : CanvasTestStep(false) {} \
|
|
|
|
virtual void draw(SkCanvas* canvas, skiatest::Reporter* reporter) { \
|
|
|
|
FUNCTION (canvas, reporter, this); \
|
|
|
|
} \
|
|
|
|
virtual const char* name() const {return #NAME ;} \
|
|
|
|
}; \
|
|
|
|
static NAME##_TestStep NAME##_TestStepInstance;
|
|
|
|
|
2012-02-22 21:00:42 +00:00
|
|
|
#define SIMPLE_TEST_STEP(NAME, CALL) \
|
|
|
|
static void NAME##TestStep(SkCanvas* canvas, skiatest::Reporter*, \
|
|
|
|
CanvasTestStep*) { \
|
|
|
|
canvas-> CALL ; \
|
|
|
|
} \
|
|
|
|
TEST_STEP(NAME, NAME##TestStep )
|
|
|
|
|
|
|
|
#define SIMPLE_TEST_STEP_WITH_ASSERT(NAME, CALL) \
|
|
|
|
static void NAME##TestStep(SkCanvas* canvas, skiatest::Reporter* reporter, \
|
|
|
|
CanvasTestStep* testStep) { \
|
|
|
|
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.
|
|
|
|
|
2012-02-24 21:54:07 +00:00
|
|
|
SIMPLE_TEST_STEP_WITH_ASSERT(Translate,
|
|
|
|
translate(SkIntToScalar(1), SkIntToScalar(2)));
|
|
|
|
SIMPLE_TEST_STEP_WITH_ASSERT(Scale,
|
|
|
|
scale(SkIntToScalar(1), SkIntToScalar(2)));
|
|
|
|
SIMPLE_TEST_STEP_WITH_ASSERT(Rotate, rotate(SkIntToScalar(1)));
|
|
|
|
SIMPLE_TEST_STEP_WITH_ASSERT(Skew,
|
|
|
|
skew(SkIntToScalar(1), SkIntToScalar(2)));
|
|
|
|
SIMPLE_TEST_STEP_WITH_ASSERT(Concat, concat(kTestMatrix));
|
|
|
|
SIMPLE_TEST_STEP(SetMatrix, setMatrix(kTestMatrix));
|
2012-07-16 14:04:59 +00:00
|
|
|
SIMPLE_TEST_STEP(ClipRect, clipRect(kTestRect));
|
|
|
|
SIMPLE_TEST_STEP(ClipPath, clipPath(kTestPath));
|
|
|
|
SIMPLE_TEST_STEP(ClipRegion,
|
2012-02-24 21:54:07 +00:00
|
|
|
clipRegion(kTestRegion, SkRegion::kReplace_Op));
|
2012-02-22 21:00:42 +00:00
|
|
|
SIMPLE_TEST_STEP(Clear, clear(kTestColor));
|
|
|
|
SIMPLE_TEST_STEP(DrawPaint, drawPaint(kTestPaint));
|
|
|
|
SIMPLE_TEST_STEP(DrawPointsPoints, drawPoints(SkCanvas::kPoints_PointMode,
|
|
|
|
kTestPointCount, kTestPoints, kTestPaint));
|
|
|
|
SIMPLE_TEST_STEP(DrawPointsLiness, drawPoints(SkCanvas::kLines_PointMode,
|
|
|
|
kTestPointCount, kTestPoints, kTestPaint));
|
|
|
|
SIMPLE_TEST_STEP(DrawPointsPolygon, drawPoints(SkCanvas::kPolygon_PointMode,
|
|
|
|
kTestPointCount, kTestPoints, kTestPaint));
|
|
|
|
SIMPLE_TEST_STEP(DrawRect, drawRect(kTestRect, kTestPaint));
|
|
|
|
SIMPLE_TEST_STEP(DrawPath, drawPath(kTestPath, kTestPaint));
|
2012-02-23 21:34:34 +00:00
|
|
|
SIMPLE_TEST_STEP(DrawBitmap, drawBitmap(kTestBitmap, 0, 0));
|
2012-02-22 21:00:42 +00:00
|
|
|
SIMPLE_TEST_STEP(DrawBitmapPaint, drawBitmap(kTestBitmap, 0, 0, &kTestPaint));
|
|
|
|
SIMPLE_TEST_STEP(DrawBitmapRect, drawBitmapRect(kTestBitmap, NULL, kTestRect,
|
|
|
|
NULL));
|
|
|
|
SIMPLE_TEST_STEP(DrawBitmapRectSrcRect, drawBitmapRect(kTestBitmap,
|
|
|
|
&kTestIRect, kTestRect, NULL));
|
|
|
|
SIMPLE_TEST_STEP(DrawBitmapRectPaint, drawBitmapRect(kTestBitmap, NULL,
|
|
|
|
kTestRect, &kTestPaint));
|
|
|
|
SIMPLE_TEST_STEP(DrawBitmapMatrix, drawBitmapMatrix(kTestBitmap, kTestMatrix,
|
|
|
|
NULL));
|
|
|
|
SIMPLE_TEST_STEP(DrawBitmapMatrixPaint, drawBitmapMatrix(kTestBitmap,
|
|
|
|
kTestMatrix, &kTestPaint));
|
|
|
|
SIMPLE_TEST_STEP(DrawBitmapNine, drawBitmapNine(kTestBitmap, kTestIRect,
|
|
|
|
kTestRect, NULL));
|
|
|
|
SIMPLE_TEST_STEP(DrawBitmapNinePaint, drawBitmapNine(kTestBitmap, kTestIRect,
|
|
|
|
kTestRect, &kTestPaint));
|
2012-02-23 21:34:34 +00:00
|
|
|
SIMPLE_TEST_STEP(DrawSprite, drawSprite(kTestBitmap, 0, 0, NULL));
|
2012-02-22 21:00:42 +00:00
|
|
|
SIMPLE_TEST_STEP(DrawSpritePaint, drawSprite(kTestBitmap, 0, 0, &kTestPaint));
|
|
|
|
SIMPLE_TEST_STEP(DrawText, drawText(kTestText.c_str(), kTestText.size(),
|
|
|
|
0, 1, kTestPaint));
|
|
|
|
SIMPLE_TEST_STEP(DrawPosText, drawPosText(kTestText.c_str(),
|
2012-06-05 19:35:09 +00:00
|
|
|
kTestText.size(), kTestPoints2, kTestPaint));
|
2012-02-22 21:00:42 +00:00
|
|
|
SIMPLE_TEST_STEP(DrawTextOnPath, drawTextOnPath(kTestText.c_str(),
|
|
|
|
kTestText.size(), kTestPath, NULL, kTestPaint));
|
|
|
|
SIMPLE_TEST_STEP(DrawTextOnPathMatrix, drawTextOnPath(kTestText.c_str(),
|
|
|
|
kTestText.size(), kTestPath, &kTestMatrix, kTestPaint));
|
|
|
|
SIMPLE_TEST_STEP(DrawData, drawData(kTestText.c_str(), kTestText.size()));
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Complex test steps
|
|
|
|
|
2012-08-23 18:14:13 +00:00
|
|
|
// Save/restore calls cannot be in isolated simple test steps because the test
|
2012-07-16 14:04:59 +00:00
|
|
|
// cases that use SkPicture require that save and restore calls be balanced.
|
2012-08-23 18:14:13 +00:00
|
|
|
static void SaveMatrixStep(SkCanvas* canvas,
|
2012-07-16 14:04:59 +00:00
|
|
|
skiatest::Reporter* reporter,
|
|
|
|
CanvasTestStep* testStep) {
|
|
|
|
int saveCount = canvas->getSaveCount();
|
|
|
|
canvas->save(SkCanvas::kMatrix_SaveFlag);
|
|
|
|
canvas->clipRegion(kTestRegion);
|
|
|
|
canvas->translate(SkIntToScalar(1), SkIntToScalar(2));
|
|
|
|
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());
|
|
|
|
REPORTER_ASSERT_MESSAGE(reporter, canvas->getTotalClip() == kTestRegion,
|
|
|
|
testStep->assertMessage());
|
|
|
|
}
|
|
|
|
TEST_STEP(SaveMatrix, SaveMatrixStep);
|
|
|
|
|
2012-08-23 18:14:13 +00:00
|
|
|
static void SaveClipStep(SkCanvas* canvas,
|
2012-07-16 14:04:59 +00:00
|
|
|
skiatest::Reporter* reporter,
|
|
|
|
CanvasTestStep* testStep) {
|
|
|
|
int saveCount = canvas->getSaveCount();
|
|
|
|
canvas->save(SkCanvas::kClip_SaveFlag);
|
|
|
|
canvas->translate(SkIntToScalar(1), SkIntToScalar(2));
|
|
|
|
canvas->clipRegion(kTestRegion);
|
|
|
|
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());
|
|
|
|
REPORTER_ASSERT_MESSAGE(reporter, canvas->getTotalClip() != kTestRegion,
|
|
|
|
testStep->assertMessage());
|
|
|
|
}
|
|
|
|
TEST_STEP(SaveClip, SaveClipStep);
|
|
|
|
|
2012-08-23 18:14:13 +00:00
|
|
|
static void SaveMatrixClipStep(SkCanvas* canvas,
|
2012-07-16 14:04:59 +00:00
|
|
|
skiatest::Reporter* reporter,
|
|
|
|
CanvasTestStep* testStep) {
|
|
|
|
int saveCount = canvas->getSaveCount();
|
|
|
|
canvas->save(SkCanvas::kMatrixClip_SaveFlag);
|
|
|
|
canvas->translate(SkIntToScalar(1), SkIntToScalar(2));
|
|
|
|
canvas->clipRegion(kTestRegion);
|
|
|
|
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());
|
|
|
|
REPORTER_ASSERT_MESSAGE(reporter, canvas->getTotalClip() != kTestRegion,
|
|
|
|
testStep->assertMessage());
|
|
|
|
}
|
|
|
|
TEST_STEP(SaveMatrixClip, SaveMatrixClipStep);
|
|
|
|
|
2012-08-23 18:14:13 +00:00
|
|
|
static void SaveLayerStep(SkCanvas* canvas,
|
2012-07-16 14:04:59 +00:00
|
|
|
skiatest::Reporter* reporter,
|
|
|
|
CanvasTestStep* testStep) {
|
|
|
|
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);
|
|
|
|
|
2012-08-23 18:14:13 +00:00
|
|
|
static void BoundedSaveLayerStep(SkCanvas* canvas,
|
2012-07-16 14:04:59 +00:00
|
|
|
skiatest::Reporter* reporter,
|
|
|
|
CanvasTestStep* testStep) {
|
|
|
|
int saveCount = canvas->getSaveCount();
|
|
|
|
canvas->saveLayer(&kTestRect, 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(BoundedSaveLayer, BoundedSaveLayerStep);
|
|
|
|
|
2012-08-23 18:14:13 +00:00
|
|
|
static void PaintSaveLayerStep(SkCanvas* canvas,
|
2012-07-16 14:04:59 +00:00
|
|
|
skiatest::Reporter* reporter,
|
|
|
|
CanvasTestStep* testStep) {
|
|
|
|
int saveCount = canvas->getSaveCount();
|
|
|
|
canvas->saveLayer(NULL, &kTestPaint);
|
|
|
|
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);
|
|
|
|
|
2012-08-23 18:14:13 +00:00
|
|
|
static void TwoClipOpsStep(SkCanvas* canvas,
|
2012-07-16 14:04:59 +00:00
|
|
|
skiatest::Reporter* reporter,
|
|
|
|
CanvasTestStep* testStep) {
|
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.
|
|
|
|
canvas->clipRect(kTestRect);
|
|
|
|
canvas->clipRegion(kTestRegion);
|
|
|
|
}
|
|
|
|
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')
|
2012-08-23 18:14:13 +00:00
|
|
|
static void DrawNearlyZeroLengthPathTestStep(SkCanvas* canvas,
|
2012-04-11 17:51:01 +00:00
|
|
|
skiatest::Reporter* reporter,
|
|
|
|
CanvasTestStep* testStep) {
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setStrokeWidth(SkIntToScalar(1));
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
canvas->drawPath(path, paint);
|
|
|
|
}
|
|
|
|
TEST_STEP(DrawNearlyZeroLengthPath, DrawNearlyZeroLengthPathTestStep);
|
|
|
|
|
2012-08-23 18:14:13 +00:00
|
|
|
static void DrawVerticesShaderTestStep(SkCanvas* canvas,
|
2012-02-22 21:00:42 +00:00
|
|
|
skiatest::Reporter* reporter,
|
|
|
|
CanvasTestStep* testStep) {
|
|
|
|
SkPoint pts[4];
|
|
|
|
pts[0].set(0, 0);
|
|
|
|
pts[1].set(SkIntToScalar(kWidth), 0);
|
|
|
|
pts[2].set(SkIntToScalar(kWidth), SkIntToScalar(kHeight));
|
|
|
|
pts[3].set(0, SkIntToScalar(kHeight));
|
|
|
|
SkPaint paint;
|
|
|
|
SkShader* shader = SkShader::CreateBitmapShader(kTestBitmap,
|
|
|
|
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
|
|
|
|
2012-08-23 18:14:13 +00:00
|
|
|
static void DrawPictureTestStep(SkCanvas* canvas,
|
2012-02-22 21:00:42 +00:00
|
|
|
skiatest::Reporter* reporter,
|
|
|
|
CanvasTestStep* testStep) {
|
|
|
|
SkPicture* testPicture = SkNEW_ARGS(SkPicture, ());
|
|
|
|
SkAutoUnref aup(testPicture);
|
|
|
|
SkCanvas* testCanvas = testPicture->beginRecording(kWidth, kHeight);
|
|
|
|
testCanvas->scale(SkIntToScalar(2), SkIntToScalar(1));
|
|
|
|
testCanvas->clipRect(kTestRect);
|
|
|
|
testCanvas->drawRect(kTestRect, kTestPaint);
|
|
|
|
canvas->drawPicture(*testPicture);
|
|
|
|
}
|
|
|
|
TEST_STEP(DrawPicture, DrawPictureTestStep);
|
|
|
|
|
2012-08-23 18:14:13 +00:00
|
|
|
static void SaveRestoreTestStep(SkCanvas* canvas,
|
2012-02-22 21:00:42 +00:00
|
|
|
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
|
|
|
|
2012-08-23 18:14:13 +00:00
|
|
|
static void DrawLayerTestStep(SkCanvas* canvas,
|
2012-02-22 21:00:42 +00:00
|
|
|
skiatest::Reporter* reporter,
|
|
|
|
CanvasTestStep* testStep) {
|
|
|
|
REPORTER_ASSERT_MESSAGE(reporter, !canvas->isDrawingToLayer(),
|
|
|
|
testStep->assertMessage());
|
|
|
|
canvas->save();
|
|
|
|
REPORTER_ASSERT_MESSAGE(reporter, !canvas->isDrawingToLayer(),
|
|
|
|
testStep->assertMessage());
|
2012-07-16 14:04:59 +00:00
|
|
|
canvas->restore();
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2011-12-14 18:48:05 +00:00
|
|
|
const SkRect* bounds = NULL; // null means include entire bounds
|
|
|
|
const SkPaint* paint = NULL;
|
|
|
|
|
2012-02-22 21:00:42 +00:00
|
|
|
canvas->saveLayer(bounds, paint);
|
|
|
|
REPORTER_ASSERT_MESSAGE(reporter, canvas->isDrawingToLayer(),
|
|
|
|
testStep->assertMessage());
|
|
|
|
canvas->restore();
|
|
|
|
REPORTER_ASSERT_MESSAGE(reporter, !canvas->isDrawingToLayer(),
|
|
|
|
testStep->assertMessage());
|
|
|
|
|
|
|
|
canvas->saveLayer(bounds, paint);
|
|
|
|
canvas->saveLayer(bounds, paint);
|
|
|
|
REPORTER_ASSERT_MESSAGE(reporter, canvas->isDrawingToLayer(),
|
|
|
|
testStep->assertMessage());
|
|
|
|
canvas->restore();
|
|
|
|
REPORTER_ASSERT_MESSAGE(reporter, canvas->isDrawingToLayer(),
|
|
|
|
testStep->assertMessage());
|
|
|
|
canvas->restore();
|
2011-12-14 18:48:05 +00:00
|
|
|
// now layer count should be 0
|
2012-02-22 21:00:42 +00:00
|
|
|
REPORTER_ASSERT_MESSAGE(reporter, !canvas->isDrawingToLayer(),
|
|
|
|
testStep->assertMessage());
|
2011-12-14 18:48:05 +00:00
|
|
|
}
|
2012-02-22 21:00:42 +00:00
|
|
|
TEST_STEP(DrawLayer, DrawLayerTestStep);
|
2012-08-16 20:53:31 +00:00
|
|
|
|
|
|
|
static void NestedSaveRestoreWithSolidPaintTestStep(SkCanvas* canvas,
|
|
|
|
skiatest::Reporter* reporter,
|
|
|
|
CanvasTestStep* testStep) {
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
static void NestedSaveRestoreWithFlushTestStep(SkCanvas* canvas,
|
|
|
|
skiatest::Reporter* reporter,
|
|
|
|
CanvasTestStep* testStep) {
|
|
|
|
// 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));
|
|
|
|
canvas->drawRect(kTestRect,kTestPaint);
|
|
|
|
canvas->flush();
|
|
|
|
canvas->restore();
|
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
TEST_STEP(NestedSaveRestoreWithFlush, \
|
|
|
|
NestedSaveRestoreWithFlushTestStep);
|
2011-11-28 16:06:04 +00:00
|
|
|
|
2012-02-22 21:00:42 +00:00
|
|
|
static void AssertCanvasStatesEqual(skiatest::Reporter* reporter,
|
2012-08-23 18:14:13 +00:00
|
|
|
const SkCanvas* canvas1,
|
2012-02-22 21:00:42 +00:00
|
|
|
const SkCanvas* canvas2,
|
|
|
|
CanvasTestStep* testStep) {
|
|
|
|
REPORTER_ASSERT_MESSAGE(reporter, canvas1->getDeviceSize() ==
|
|
|
|
canvas2->getDeviceSize(), testStep->assertMessage());
|
|
|
|
REPORTER_ASSERT_MESSAGE(reporter, canvas1->getSaveCount() ==
|
|
|
|
canvas2->getSaveCount(), testStep->assertMessage());
|
|
|
|
REPORTER_ASSERT_MESSAGE(reporter, canvas1->isDrawingToLayer() ==
|
|
|
|
canvas2->isDrawingToLayer(), 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());
|
|
|
|
REPORTER_ASSERT_MESSAGE(reporter, deviceBounds1 == deviceBounds2,
|
|
|
|
testStep->assertMessage());
|
|
|
|
REPORTER_ASSERT_MESSAGE(reporter, canvas1->getBounder() ==
|
|
|
|
canvas2->getBounder(), testStep->assertMessage());
|
|
|
|
REPORTER_ASSERT_MESSAGE(reporter, canvas1->getTotalMatrix() ==
|
|
|
|
canvas2->getTotalMatrix(), testStep->assertMessage());
|
|
|
|
REPORTER_ASSERT_MESSAGE(reporter, canvas1->getClipType() ==
|
|
|
|
canvas2->getClipType(), testStep->assertMessage());
|
|
|
|
REPORTER_ASSERT_MESSAGE(reporter, canvas1->getTotalClip() ==
|
|
|
|
canvas2->getTotalClip(), testStep->assertMessage());
|
2011-11-28 16:06:04 +00:00
|
|
|
|
2012-02-22 21:00:42 +00:00
|
|
|
// The following test code is commented out because the test fails when
|
2012-08-23 18:14:13 +00:00
|
|
|
// the canvas is an SkPictureRecord or SkDeferredCanvas
|
2012-02-22 21:00:42 +00:00
|
|
|
// Issue: http://code.google.com/p/skia/issues/detail?id=498
|
|
|
|
// Also, creating a LayerIter on an SkProxyCanvas crashes
|
|
|
|
// Issue: http://code.google.com/p/skia/issues/detail?id=499
|
|
|
|
/*
|
|
|
|
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());
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
// The following class groups static functions that need to access
|
|
|
|
// the privates members of SkPictureRecord
|
|
|
|
class SkPictureTester {
|
|
|
|
private:
|
2012-07-10 19:38:01 +00:00
|
|
|
static int EQ(const SkFlatData* a, const SkFlatData* b) {
|
|
|
|
return *a == *b;
|
|
|
|
}
|
|
|
|
|
2012-02-22 21:00:42 +00:00
|
|
|
static void AssertFlattenedObjectsEqual(
|
|
|
|
SkPictureRecord* referenceRecord,
|
|
|
|
SkPictureRecord* testRecord,
|
|
|
|
skiatest::Reporter* reporter,
|
|
|
|
CanvasTestStep* testStep) {
|
|
|
|
|
|
|
|
REPORTER_ASSERT_MESSAGE(reporter,
|
2012-08-29 18:52:07 +00:00
|
|
|
referenceRecord->fBitmapHeap->count() ==
|
|
|
|
testRecord->fBitmapHeap->count(), testStep->assertMessage());
|
2012-02-22 21:00:42 +00:00
|
|
|
REPORTER_ASSERT_MESSAGE(reporter,
|
|
|
|
referenceRecord->fMatrices.count() ==
|
|
|
|
testRecord->fMatrices.count(), testStep->assertMessage());
|
|
|
|
for (int i = 0; i < referenceRecord->fMatrices.count(); ++i) {
|
|
|
|
REPORTER_ASSERT_MESSAGE(reporter,
|
2012-07-10 19:38:01 +00:00
|
|
|
EQ(referenceRecord->fMatrices[i], testRecord->fMatrices[i]),
|
2012-02-22 21:00:42 +00:00
|
|
|
testStep->assertMessage());
|
|
|
|
}
|
|
|
|
REPORTER_ASSERT_MESSAGE(reporter,
|
|
|
|
referenceRecord->fPaints.count() ==
|
|
|
|
testRecord->fPaints.count(), testStep->assertMessage());
|
|
|
|
for (int i = 0; i < referenceRecord->fPaints.count(); ++i) {
|
|
|
|
REPORTER_ASSERT_MESSAGE(reporter,
|
2012-07-10 19:38:01 +00:00
|
|
|
EQ(referenceRecord->fPaints[i], testRecord->fPaints[i]),
|
|
|
|
testStep->assertMessage());
|
2012-02-22 21:00:42 +00:00
|
|
|
}
|
|
|
|
REPORTER_ASSERT_MESSAGE(reporter,
|
|
|
|
referenceRecord->fRegions.count() ==
|
|
|
|
testRecord->fRegions.count(), testStep->assertMessage());
|
|
|
|
for (int i = 0; i < referenceRecord->fRegions.count(); ++i) {
|
|
|
|
REPORTER_ASSERT_MESSAGE(reporter,
|
2012-07-10 19:38:01 +00:00
|
|
|
EQ(referenceRecord->fRegions[i], testRecord->fRegions[i]),
|
|
|
|
testStep->assertMessage());
|
2012-02-22 21:00:42 +00:00
|
|
|
}
|
|
|
|
REPORTER_ASSERT_MESSAGE(reporter,
|
|
|
|
!referenceRecord->fPathHeap ==
|
|
|
|
!testRecord->fPathHeap,
|
|
|
|
testStep->assertMessage());
|
2012-02-23 14:59:22 +00:00
|
|
|
// The following tests are commented out because they currently
|
|
|
|
// fail. Issue: http://code.google.com/p/skia/issues/detail?id=507
|
|
|
|
/*
|
2012-02-22 21:00:42 +00:00
|
|
|
if (referenceRecord->fPathHeap) {
|
|
|
|
REPORTER_ASSERT_MESSAGE(reporter,
|
|
|
|
referenceRecord->fPathHeap->count() ==
|
|
|
|
testRecord->fPathHeap->count(),
|
|
|
|
testStep->assertMessage());
|
|
|
|
for (int i = 0; i < referenceRecord->fPathHeap->count(); ++i) {
|
|
|
|
REPORTER_ASSERT_MESSAGE(reporter,
|
|
|
|
(*referenceRecord->fPathHeap)[i] ==
|
|
|
|
(*testRecord->fPathHeap)[i], testStep->assertMessage());
|
|
|
|
}
|
|
|
|
}
|
2012-02-23 14:59:22 +00:00
|
|
|
*/
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-02-22 21:00:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2012-08-23 18:14:13 +00:00
|
|
|
static void TestPictureFlattenedObjectReuse(skiatest::Reporter* reporter,
|
2012-06-01 21:23:07 +00:00
|
|
|
CanvasTestStep* testStep,
|
|
|
|
uint32_t recordFlags) {
|
2012-02-22 21:00:42 +00:00
|
|
|
// Verify that when a test step is executed twice, no extra resources
|
|
|
|
// are flattened during the second execution
|
|
|
|
testStep->setAssertMessageFormat(kPictureDrawAssertMessageFormat);
|
|
|
|
SkPicture referencePicture;
|
|
|
|
SkCanvas* referenceCanvas = referencePicture.beginRecording(kWidth,
|
2012-06-01 21:23:07 +00:00
|
|
|
kHeight, recordFlags);
|
2012-02-22 21:00:42 +00:00
|
|
|
testStep->draw(referenceCanvas, reporter);
|
|
|
|
SkPicture testPicture;
|
2012-02-23 14:59:22 +00:00
|
|
|
SkCanvas* testCanvas = testPicture.beginRecording(kWidth,
|
2012-06-01 21:23:07 +00:00
|
|
|
kHeight, recordFlags);
|
2012-02-23 14:59:22 +00:00
|
|
|
testStep->draw(testCanvas, reporter);
|
2012-02-22 21:00:42 +00:00
|
|
|
testStep->setAssertMessageFormat(kPictureSecondDrawAssertMessageFormat);
|
2012-02-23 14:59:22 +00:00
|
|
|
testStep->draw(testCanvas, reporter);
|
2012-02-22 21:00:42 +00:00
|
|
|
|
|
|
|
SkPictureRecord* referenceRecord = static_cast<SkPictureRecord*>(
|
|
|
|
referenceCanvas);
|
|
|
|
SkPictureRecord* testRecord = static_cast<SkPictureRecord*>(
|
|
|
|
testCanvas);
|
|
|
|
testStep->setAssertMessageFormat(kPictureResourceReuseMessageFormat);
|
|
|
|
AssertFlattenedObjectsEqual(referenceRecord, testRecord,
|
2012-02-22 21:24:41 +00:00
|
|
|
reporter, testStep);
|
2012-02-22 21:00:42 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-10-18 15:58:23 +00:00
|
|
|
static void TestPdfDevice(skiatest::Reporter* reporter,
|
|
|
|
CanvasTestStep* testStep) {
|
|
|
|
SkISize pageSize = SkISize::Make(kWidth, kHeight);
|
|
|
|
SkPDFDevice device(pageSize, pageSize, SkMatrix::I());
|
|
|
|
SkCanvas canvas(&device);
|
|
|
|
testStep->setAssertMessageFormat(kPdfAssertMessageFormat);
|
|
|
|
testStep->draw(&canvas, reporter);
|
|
|
|
SkPDFDocument doc;
|
|
|
|
doc.appendPage(&device);
|
|
|
|
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,
|
|
|
|
CanvasTestStep* testStep,
|
2012-09-20 19:35:43 +00:00
|
|
|
const SkCanvas& referenceCanvas, bool silent) {
|
2012-08-07 16:48:22 +00:00
|
|
|
|
|
|
|
SkBitmap deferredStore;
|
|
|
|
createBitmap(&deferredStore, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF);
|
|
|
|
SkDevice deferredDevice(deferredStore);
|
|
|
|
SkDeferredCanvas deferredCanvas(&deferredDevice);
|
|
|
|
testStep->setAssertMessageFormat(kDeferredDrawAssertMessageFormat);
|
|
|
|
testStep->draw(&deferredCanvas, reporter);
|
|
|
|
testStep->setAssertMessageFormat(kDeferredPreFlushAssertMessageFormat);
|
|
|
|
AssertCanvasStatesEqual(reporter, &deferredCanvas, &referenceCanvas,
|
|
|
|
testStep);
|
|
|
|
|
2012-09-20 19:35:43 +00:00
|
|
|
if (silent) {
|
|
|
|
deferredCanvas.silentFlush();
|
|
|
|
} else {
|
|
|
|
deferredCanvas.flush();
|
|
|
|
}
|
|
|
|
|
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);
|
2012-08-23 18:14:13 +00:00
|
|
|
AssertCanvasStatesEqual(reporter,
|
2012-08-07 16:48:22 +00:00
|
|
|
deferredCanvas.immediateCanvas(),
|
|
|
|
&referenceCanvas, testStep);
|
|
|
|
|
|
|
|
// 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 TestProxyCanvasStateConsistency(
|
|
|
|
skiatest::Reporter* reporter,
|
|
|
|
CanvasTestStep* testStep,
|
|
|
|
const SkCanvas& referenceCanvas) {
|
|
|
|
|
|
|
|
SkBitmap indirectStore;
|
|
|
|
createBitmap(&indirectStore, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF);
|
|
|
|
SkDevice indirectDevice(indirectStore);
|
|
|
|
SkCanvas indirectCanvas(&indirectDevice);
|
|
|
|
SkProxyCanvas proxyCanvas(&indirectCanvas);
|
|
|
|
testStep->setAssertMessageFormat(kProxyDrawAssertMessageFormat);
|
|
|
|
testStep->draw(&proxyCanvas, reporter);
|
|
|
|
// Verify that the SkProxyCanvas reports consitent state
|
|
|
|
testStep->setAssertMessageFormat(kProxyStateAssertMessageFormat);
|
|
|
|
AssertCanvasStatesEqual(reporter, &proxyCanvas, &referenceCanvas,
|
|
|
|
testStep);
|
|
|
|
// Verify that the indirect canvas reports consitent state
|
|
|
|
testStep->setAssertMessageFormat(kProxyIndirectStateAssertMessageFormat);
|
|
|
|
AssertCanvasStatesEqual(reporter, &indirectCanvas, &referenceCanvas,
|
|
|
|
testStep);
|
|
|
|
}
|
|
|
|
|
2012-06-06 12:03:39 +00:00
|
|
|
// unused
|
2012-02-22 21:00:42 +00:00
|
|
|
static void TestNWayCanvasStateConsistency(
|
|
|
|
skiatest::Reporter* reporter,
|
|
|
|
CanvasTestStep* testStep,
|
|
|
|
const SkCanvas& referenceCanvas) {
|
|
|
|
|
|
|
|
SkBitmap indirectStore1;
|
|
|
|
createBitmap(&indirectStore1, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF);
|
|
|
|
SkDevice indirectDevice1(indirectStore1);
|
|
|
|
SkCanvas indirectCanvas1(&indirectDevice1);
|
|
|
|
|
|
|
|
SkBitmap indirectStore2;
|
|
|
|
createBitmap(&indirectStore2, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF);
|
|
|
|
SkDevice indirectDevice2(indirectStore2);
|
|
|
|
SkCanvas indirectCanvas2(&indirectDevice2);
|
|
|
|
|
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);
|
|
|
|
testStep->draw(&nWayCanvas, reporter);
|
|
|
|
// Verify that the SkProxyCanvas reports consitent state
|
|
|
|
testStep->setAssertMessageFormat(kNWayStateAssertMessageFormat);
|
|
|
|
AssertCanvasStatesEqual(reporter, &nWayCanvas, &referenceCanvas,
|
|
|
|
testStep);
|
|
|
|
// Verify that the indirect canvases report consitent state
|
|
|
|
testStep->setAssertMessageFormat(kNWayIndirect1StateAssertMessageFormat);
|
|
|
|
AssertCanvasStatesEqual(reporter, &indirectCanvas1, &referenceCanvas,
|
|
|
|
testStep);
|
|
|
|
testStep->setAssertMessageFormat(kNWayIndirect2StateAssertMessageFormat);
|
|
|
|
AssertCanvasStatesEqual(reporter, &indirectCanvas2, &referenceCanvas,
|
|
|
|
testStep);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2012-08-23 18:14:13 +00:00
|
|
|
static void TestOverrideStateConsistency(skiatest::Reporter* reporter,
|
2012-02-22 21:00:42 +00:00
|
|
|
CanvasTestStep* testStep) {
|
|
|
|
SkBitmap referenceStore;
|
|
|
|
createBitmap(&referenceStore, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF);
|
|
|
|
SkDevice referenceDevice(referenceStore);
|
|
|
|
SkCanvas referenceCanvas(&referenceDevice);
|
|
|
|
testStep->setAssertMessageFormat(kCanvasDrawAssertMessageFormat);
|
|
|
|
testStep->draw(&referenceCanvas, reporter);
|
|
|
|
|
2012-09-20 19:35:43 +00:00
|
|
|
SkDeferredCanvasTester::TestDeferredCanvasStateConsistency(reporter, testStep, referenceCanvas, false);
|
|
|
|
|
|
|
|
SkDeferredCanvasTester::TestDeferredCanvasStateConsistency(reporter, 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 SkProxyCanvas is
|
2012-02-22 21:00:42 +00:00
|
|
|
// missing a lot of virtual overrides on get* methods, which are used
|
|
|
|
// to verify canvas state.
|
|
|
|
// Issue: http://code.google.com/p/skia/issues/detail?id=500
|
|
|
|
|
2012-06-06 12:03:39 +00:00
|
|
|
if (false) { // avoid bit rot, suppress warning
|
|
|
|
TestProxyCanvasStateConsistency(reporter, testStep, referenceCanvas);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
TestNWayCanvasStateConsistency(reporter, testStep, referenceCanvas);
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
static void TestCanvas(skiatest::Reporter* reporter) {
|
|
|
|
// Init global here because bitmap pixels cannot be alocated during
|
|
|
|
// static initialization
|
|
|
|
kTestBitmap = testBitmap();
|
2011-12-14 18:48:05 +00:00
|
|
|
|
2012-02-22 21:00:42 +00:00
|
|
|
for (int testStep = 0; testStep < testStepArray().count(); testStep++) {
|
|
|
|
TestOverrideStateConsistency(reporter, testStepArray()[testStep]);
|
2012-06-01 21:23:07 +00:00
|
|
|
SkPictureTester::TestPictureFlattenedObjectReuse(reporter,
|
|
|
|
testStepArray()[testStep], 0);
|
2012-10-18 15:58:23 +00:00
|
|
|
if (testStepArray()[testStep]->enablePdfTesting()) {
|
|
|
|
TestPdfDevice(reporter, testStepArray()[testStep]);
|
|
|
|
}
|
2012-02-22 21:00:42 +00:00
|
|
|
}
|
2012-08-02 17:43:25 +00:00
|
|
|
|
|
|
|
// Explicitly call reset(), so we don't leak the pixels (since kTestBitmap is a global)
|
|
|
|
kTestBitmap.reset();
|
2011-11-28 16:06:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#include "TestClassDef.h"
|
|
|
|
DEFINE_TESTCLASS("Canvas", TestCanvasClass, TestCanvas)
|