Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1845)

Unified Diff: tests/CanvasTest.cpp

Issue 614773004: Add tests for SkCanvas::drawImage[Rect]() Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/CanvasTest.cpp
diff --git a/tests/CanvasTest.cpp b/tests/CanvasTest.cpp
index 216a408155a035acd3a1446cb031a411753c9639..e3986b541737be1694bb532a8ac8164e84d7d7d6 100644
--- a/tests/CanvasTest.cpp
+++ b/tests/CanvasTest.cpp
@@ -152,12 +152,12 @@ static const char* const kNWayIndirect2StateAssertMessageFormat =
static const char* const kPdfAssertMessageFormat =
"PDF sanity check failed %s";
-static void createBitmap(SkBitmap* bm, SkColor color) {
+static void create_bitmap(SkBitmap* bm, SkColor color) {
bm->allocN32Pixels(kWidth, kHeight);
bm->eraseColor(color);
}
-static SkSurface* createSurface(SkColor color) {
+static SkSurface* create_surface(SkColor color) {
SkSurface* surface = SkSurface::NewRasterPMColor(kWidth, kHeight);
surface->getCanvas()->clear(color);
return surface;
@@ -249,7 +249,7 @@ const SkPoint kTestPoints[3] = {
const size_t kTestPointCount = 3;
static SkBitmap testBitmap() {
SkBitmap bitmap;
- createBitmap(&bitmap, 0x05060708);
+ create_bitmap(&bitmap, 0x05060708);
return bitmap;
}
SkBitmap kTestBitmap; // cannot be created during static init
@@ -267,7 +267,8 @@ SkPoint kTestPoints2[] = {
{ SkIntToScalar(9), SkIntToScalar(1) },
{ SkIntToScalar(10), SkIntToScalar(1) },
};
-
+SkSurface* kTestSurface;
+SkImage* kTestImage;
reed1 2014/09/30 13:44:55 ugh -- can we find a way to not use these globals?
Rémi Piotaix 2014/09/30 15:44:50 Seems that we can't. The use of the same bitmap/im
///////////////////////////////////////////////////////////////////////////////
// Macros for defining test steps
@@ -282,7 +283,7 @@ public: \
}; \
static NAME##_TestStep NAME##_TestStepInstance;
-#define TEST_STEP_NO_PDF(NAME, FUNCTION) \
+#define TEST_STEP_NO_PDF(NAME, FUNCTION) \
class NAME##_TestStep : public CanvasTestStep{ \
public: \
NAME##_TestStep() : CanvasTestStep(false) {} \
@@ -363,6 +364,8 @@ SIMPLE_TEST_STEP(DrawData, drawData(kTestText.c_str(), kTestText.size()));
SIMPLE_TEST_STEP(BeginGroup, beginCommentGroup(kTestText.c_str()));
SIMPLE_TEST_STEP(AddComment, addComment(kTestText.c_str(), kTestText.c_str()));
SIMPLE_TEST_STEP(EndGroup, endCommentGroup());
+SIMPLE_TEST_STEP(DrawImage, drawImage(kTestImage, 0, 0));
+SIMPLE_TEST_STEP(DrawImageRect, drawImageRect(kTestImage, 0, SkRect::MakeWH(kWidth, kHeight)));
///////////////////////////////////////////////////////////////////////////////
// Complex test steps
@@ -463,7 +466,7 @@ static void DrawPictureTestStep(SkCanvas* canvas,
skiatest::Reporter*,
CanvasTestStep*) {
SkPictureRecorder recorder;
- SkCanvas* testCanvas = recorder.beginRecording(SkIntToScalar(kWidth), SkIntToScalar(kHeight),
+ SkCanvas* testCanvas = recorder.beginRecording(SkIntToScalar(kWidth), SkIntToScalar(kHeight),
NULL, 0);
testCanvas->scale(SkIntToScalar(2), SkIntToScalar(1));
testCanvas->clipRect(kTestRect);
@@ -689,15 +692,15 @@ public:
testStep->setAssertMessageFormat(kPictureDrawAssertMessageFormat);
SkPictureRecorder referenceRecorder;
SkCanvas* referenceCanvas =
- referenceRecorder.DEPRECATED_beginRecording(SkIntToScalar(kWidth),
- SkIntToScalar(kHeight),
+ referenceRecorder.DEPRECATED_beginRecording(SkIntToScalar(kWidth),
+ SkIntToScalar(kHeight),
NULL, recordFlags);
testStep->draw(referenceCanvas, reporter);
SkPictureRecorder testRecorder;
SkCanvas* testCanvas =
- testRecorder.DEPRECATED_beginRecording(SkIntToScalar(kWidth),
- SkIntToScalar(kHeight),
+ testRecorder.DEPRECATED_beginRecording(SkIntToScalar(kWidth),
+ SkIntToScalar(kHeight),
NULL, recordFlags);
testStep->draw(testCanvas, reporter);
testStep->setAssertMessageFormat(kPictureSecondDrawAssertMessageFormat);
@@ -733,7 +736,7 @@ public:
CanvasTestStep* testStep,
const SkCanvas& referenceCanvas, bool silent) {
- SkAutoTUnref<SkSurface> surface(createSurface(0xFFFFFFFF));
+ SkAutoTUnref<SkSurface> surface(create_surface(0xFFFFFFFF));
SkAutoTUnref<SkDeferredCanvas> deferredCanvas(SkDeferredCanvas::Create(surface.get()));
testStep->setAssertMessageFormat(kDeferredDrawAssertMessageFormat);
@@ -775,7 +778,7 @@ static void TestProxyCanvasStateConsistency(
const SkCanvas& referenceCanvas) {
SkBitmap indirectStore;
- createBitmap(&indirectStore, 0xFFFFFFFF);
+ create_bitmap(&indirectStore, 0xFFFFFFFF);
SkCanvas indirectCanvas(indirectStore);
SkProxyCanvas proxyCanvas(&indirectCanvas);
testStep->setAssertMessageFormat(kProxyDrawAssertMessageFormat);
@@ -797,11 +800,11 @@ static void TestNWayCanvasStateConsistency(
const SkCanvas& referenceCanvas) {
SkBitmap indirectStore1;
- createBitmap(&indirectStore1, 0xFFFFFFFF);
+ create_bitmap(&indirectStore1, 0xFFFFFFFF);
SkCanvas indirectCanvas1(indirectStore1);
SkBitmap indirectStore2;
- createBitmap(&indirectStore2, 0xFFFFFFFF);
+ create_bitmap(&indirectStore2, 0xFFFFFFFF);
SkCanvas indirectCanvas2(indirectStore2);
SkISize canvasSize = referenceCanvas.getDeviceSize();
@@ -833,7 +836,7 @@ static void TestNWayCanvasStateConsistency(
static void TestOverrideStateConsistency(skiatest::Reporter* reporter,
CanvasTestStep* testStep) {
SkBitmap referenceStore;
- createBitmap(&referenceStore, 0xFFFFFFFF);
+ create_bitmap(&referenceStore, 0xFFFFFFFF);
SkCanvas referenceCanvas(referenceStore);
testStep->setAssertMessageFormat(kCanvasDrawAssertMessageFormat);
testStep->draw(&referenceCanvas, reporter);
@@ -905,6 +908,8 @@ DEF_TEST(Canvas, reporter) {
// Init global here because bitmap pixels cannot be alocated during
// static initialization
kTestBitmap = testBitmap();
+ kTestSurface = create_surface(SK_ColorGREEN);
+ kTestImage = kTestSurface->newImageSnapshot();
Justin Novosad 2014/09/30 18:06:46 I guess these globals could be packaged into a loc
Rémi Piotaix 2014/10/02 18:45:24 Done here: https://codereview.chromium.org/6170930
for (int testStep = 0; testStep < testStepArray().count(); testStep++) {
TestOverrideStateConsistency(reporter, testStepArray()[testStep]);
@@ -917,6 +922,8 @@ DEF_TEST(Canvas, reporter) {
// Explicitly call reset(), so we don't leak the pixels (since kTestBitmap is a global)
kTestBitmap.reset();
+ kTestSurface->unref();
+ kTestImage->unref();
test_newraster(reporter);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698