aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar robertphillips <robertphillips@google.com>2014-08-29 08:03:56 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-08-29 08:03:56 -0700
commita8d7f0b13cd4c6d773fcf055fe17db75d260fa05 (patch)
tree37e85b212ccd5761b9a736282e75ebf838840798 /tests
parent77d724c07878b21602e96e095f6a446c429a079a (diff)
Try out scalar picture sizes
This paves the way for removing the 'fTile' parameter from SkPictureShader (although that should be a different CL). If we like this we could also move to providing an entire cull SkRect. R=reed@google.com, mtklein@google.com, fmalita@google.com, fmalita@chromium.org Author: robertphillips@google.com Review URL: https://codereview.chromium.org/513983002
Diffstat (limited to 'tests')
-rw-r--r--tests/CanvasTest.cpp11
-rw-r--r--tests/ImageFilterTest.cpp31
-rwxr-xr-xtests/PathOpsSkpClipTest.cpp27
-rw-r--r--tests/PictureTest.cpp11
-rw-r--r--tests/SerializationTest.cpp13
5 files changed, 56 insertions, 37 deletions
diff --git a/tests/CanvasTest.cpp b/tests/CanvasTest.cpp
index 5d6a8d8a6f..d4600514b7 100644
--- a/tests/CanvasTest.cpp
+++ b/tests/CanvasTest.cpp
@@ -463,7 +463,8 @@ static void DrawPictureTestStep(SkCanvas* canvas,
skiatest::Reporter*,
CanvasTestStep*) {
SkPictureRecorder recorder;
- SkCanvas* testCanvas = recorder.beginRecording(kWidth, kHeight, NULL, 0);
+ SkCanvas* testCanvas = recorder.beginRecording(SkIntToScalar(kWidth), SkIntToScalar(kHeight),
+ NULL, 0);
testCanvas->scale(SkIntToScalar(2), SkIntToScalar(1));
testCanvas->clipRect(kTestRect);
testCanvas->drawRect(kTestRect, kTestPaint);
@@ -688,12 +689,16 @@ public:
testStep->setAssertMessageFormat(kPictureDrawAssertMessageFormat);
SkPictureRecorder referenceRecorder;
SkCanvas* referenceCanvas =
- referenceRecorder.DEPRECATED_beginRecording(kWidth, kHeight, NULL, recordFlags);
+ referenceRecorder.DEPRECATED_beginRecording(SkIntToScalar(kWidth),
+ SkIntToScalar(kHeight),
+ NULL, recordFlags);
testStep->draw(referenceCanvas, reporter);
SkPictureRecorder testRecorder;
SkCanvas* testCanvas =
- testRecorder.DEPRECATED_beginRecording(kWidth, kHeight, NULL, recordFlags);
+ testRecorder.DEPRECATED_beginRecording(SkIntToScalar(kWidth),
+ SkIntToScalar(kHeight),
+ NULL, recordFlags);
testStep->draw(testCanvas, reporter);
testStep->setAssertMessageFormat(kPictureSecondDrawAssertMessageFormat);
testStep->draw(testCanvas, reporter);
diff --git a/tests/ImageFilterTest.cpp b/tests/ImageFilterTest.cpp
index 778cc3f434..a8cd5d0cf9 100644
--- a/tests/ImageFilterTest.cpp
+++ b/tests/ImageFilterTest.cpp
@@ -421,7 +421,8 @@ DEF_TEST(ImageFilterDrawTiled, reporter) {
}
}
-static void drawSaveLayerPicture(int width, int height, int tileSize, SkBBHFactory* factory, SkBitmap* result) {
+static void draw_saveLayer_picture(int width, int height, int tileSize,
+ SkBBHFactory* factory, SkBitmap* result) {
SkMatrix matrix;
matrix.setTranslate(SkIntToScalar(50), 0);
@@ -434,7 +435,9 @@ static void drawSaveLayerPicture(int width, int height, int tileSize, SkBBHFacto
paint.setImageFilter(imageFilter.get());
SkPictureRecorder recorder;
SkRect bounds = SkRect::Make(SkIRect::MakeXYWH(0, 0, 50, 50));
- SkCanvas* recordingCanvas = recorder.beginRecording(width, height, factory, 0);
+ SkCanvas* recordingCanvas = recorder.beginRecording(SkIntToScalar(width),
+ SkIntToScalar(height),
+ factory, 0);
recordingCanvas->translate(-55, 0);
recordingCanvas->saveLayer(&bounds, &paint);
recordingCanvas->restore();
@@ -457,8 +460,8 @@ DEF_TEST(ImageFilterDrawMatrixBBH, reporter) {
SkBitmap result1, result2;
SkRTreeFactory factory;
- drawSaveLayerPicture(width, height, tileSize, &factory, &result1);
- drawSaveLayerPicture(width, height, tileSize, NULL, &result2);
+ draw_saveLayer_picture(width, height, tileSize, &factory, &result1);
+ draw_saveLayer_picture(width, height, tileSize, NULL, &result2);
for (int y = 0; y < height; y++) {
int diffs = memcmp(result1.getAddr32(0, y), result2.getAddr32(0, y), result1.rowBytes());
@@ -513,7 +516,7 @@ DEF_TEST(ImageFilterDilateThenBlurBounds, reporter) {
REPORTER_ASSERT(reporter, bounds == expectedBounds);
}
-static void drawBlurredRect(SkCanvas* canvas) {
+static void draw_blurred_rect(SkCanvas* canvas) {
SkAutoTUnref<SkImageFilter> filter(SkBlurImageFilter::Create(SkIntToScalar(8), 0));
SkPaint filterPaint;
filterPaint.setColor(SK_ColorWHITE);
@@ -525,7 +528,7 @@ static void drawBlurredRect(SkCanvas* canvas) {
canvas->restore();
}
-static void drawPictureClipped(SkCanvas* canvas, const SkRect& clipRect, const SkPicture* picture) {
+static void draw_picture_clipped(SkCanvas* canvas, const SkRect& clipRect, const SkPicture* picture) {
canvas->save();
canvas->clipRect(clipRect);
canvas->drawPicture(picture);
@@ -555,17 +558,21 @@ DEF_TEST(ImageFilterDrawTiledBlurRTree, reporter) {
SkPictureRecorder recorder1, recorder2;
// The only difference between these two pictures is that one has RTree aceleration.
- SkCanvas* recordingCanvas1 = recorder1.beginRecording(width, height, NULL, 0);
- SkCanvas* recordingCanvas2 = recorder2.beginRecording(width, height, &factory, 0);
- drawBlurredRect(recordingCanvas1);
- drawBlurredRect(recordingCanvas2);
+ SkCanvas* recordingCanvas1 = recorder1.beginRecording(SkIntToScalar(width),
+ SkIntToScalar(height),
+ NULL, 0);
+ SkCanvas* recordingCanvas2 = recorder2.beginRecording(SkIntToScalar(width),
+ SkIntToScalar(height),
+ &factory, 0);
+ draw_blurred_rect(recordingCanvas1);
+ draw_blurred_rect(recordingCanvas2);
SkAutoTUnref<SkPicture> picture1(recorder1.endRecording());
SkAutoTUnref<SkPicture> picture2(recorder2.endRecording());
for (int y = 0; y < height; y += tileSize) {
for (int x = 0; x < width; x += tileSize) {
SkRect tileRect = SkRect::Make(SkIRect::MakeXYWH(x, y, tileSize, tileSize));
- drawPictureClipped(&canvas1, tileRect, picture1);
- drawPictureClipped(&canvas2, tileRect, picture2);
+ draw_picture_clipped(&canvas1, tileRect, picture1);
+ draw_picture_clipped(&canvas2, tileRect, picture2);
}
}
for (int y = 0; y < height; y++) {
diff --git a/tests/PathOpsSkpClipTest.cpp b/tests/PathOpsSkpClipTest.cpp
index a94412e989..d413a08a66 100755
--- a/tests/PathOpsSkpClipTest.cpp
+++ b/tests/PathOpsSkpClipTest.cpp
@@ -394,22 +394,21 @@ static bool addError(TestState* data, const TestResult& testResult) {
static SkMSec timePict(SkPicture* pic, SkCanvas* canvas) {
canvas->save();
- int pWidth = pic->width();
- int pHeight = pic->height();
- const int maxDimension = 1000;
+ SkScalar pWidth = pic->cullRect().width();
+ SkScalar pHeight = pic->cullRect().height();
+ const SkScalar maxDimension = 1000.0f;
const int slices = 3;
- int xInterval = SkTMax(pWidth - maxDimension, 0) / (slices - 1);
- int yInterval = SkTMax(pHeight - maxDimension, 0) / (slices - 1);
- SkRect rect = {0, 0, SkIntToScalar(SkTMin(maxDimension, pWidth)),
- SkIntToScalar(SkTMin(maxDimension, pHeight))};
+ SkScalar xInterval = SkTMax(pWidth - maxDimension, 0.0f) / (slices - 1);
+ SkScalar yInterval = SkTMax(pHeight - maxDimension, 0.0f) / (slices - 1);
+ SkRect rect = {0, 0, SkTMin(maxDimension, pWidth), SkTMin(maxDimension, pHeight) };
canvas->clipRect(rect);
SkMSec start = SkTime::GetMSecs();
for (int x = 0; x < slices; ++x) {
for (int y = 0; y < slices; ++y) {
pic->draw(canvas);
- canvas->translate(0, SkIntToScalar(yInterval));
+ canvas->translate(0, yInterval);
}
- canvas->translate(SkIntToScalar(xInterval), SkIntToScalar(-yInterval * slices));
+ canvas->translate(xInterval, -yInterval * slices);
}
SkMSec end = SkTime::GetMSecs();
canvas->restore();
@@ -473,16 +472,16 @@ void TestResult::testOne() {
SkDebugf("unable to decode %s\n", fFilename);
goto finish;
}
- int width = pic->width();
- int height = pic->height();
+ SkScalar width = pic->cullRect().width();
+ SkScalar height = pic->cullRect().height();
SkBitmap oldBitmap, opBitmap;
fScale = 1;
while (width / fScale > 32767 || height / fScale > 32767) {
++fScale;
}
do {
- int dimX = (width + fScale - 1) / fScale;
- int dimY = (height + fScale - 1) / fScale;
+ int dimX = SkScalarCeilToInt(width / fScale);
+ int dimY = SkScalarCeilToInt(height / fScale);
if (oldBitmap.allocN32Pixels(dimX, dimY) &&
opBitmap.allocN32Pixels(dimX, dimY)) {
break;
@@ -490,7 +489,7 @@ void TestResult::testOne() {
SkDebugf("-%d-", fScale);
} while (++fScale < 256);
if (fScale >= 256) {
- SkDebugf("unable to allocate bitmap for %s (w=%d h=%d)\n", fFilename,
+ SkDebugf("unable to allocate bitmap for %s (w=%f h=%f)\n", fFilename,
width, height);
goto finish;
}
diff --git a/tests/PictureTest.cpp b/tests/PictureTest.cpp
index 627e96e20f..8b19df2161 100644
--- a/tests/PictureTest.cpp
+++ b/tests/PictureTest.cpp
@@ -882,7 +882,7 @@ static void test_gpu_picture_optimization(skiatest::Reporter* reporter,
{
SkPictureRecorder recorder;
- SkCanvas* c = recorder.beginRecording(kWidth, kHeight);
+ SkCanvas* c = recorder.beginRecording(SkIntToScalar(kWidth), SkIntToScalar(kHeight));
c->saveLayer(NULL, NULL);
c->restore();
@@ -914,7 +914,8 @@ static void test_gpu_picture_optimization(skiatest::Reporter* reporter,
{
SkPictureRecorder recorder;
- SkCanvas* c = recorder.beginRecording(kWidth, kHeight);
+ SkCanvas* c = recorder.beginRecording(SkIntToScalar(kWidth),
+ SkIntToScalar(kHeight));
// 1)
c->saveLayer(NULL, NULL); // layer #0
c->restore();
@@ -1187,7 +1188,8 @@ private:
void check_save_state(skiatest::Reporter* reporter, SkPicture* picture,
unsigned int numSaves, unsigned int numSaveLayers,
unsigned int numRestores) {
- SaveCountingCanvas canvas(picture->width(), picture->height());
+ SaveCountingCanvas canvas(SkScalarCeilToInt(picture->cullRect().width()),
+ SkScalarCeilToInt(picture->cullRect().height()));
picture->draw(&canvas);
@@ -1443,7 +1445,8 @@ static SkData* encode_bitmap_to_data(size_t*, const SkBitmap& bm) {
static SkData* serialized_picture_from_bitmap(const SkBitmap& bitmap) {
SkPictureRecorder recorder;
- SkCanvas* canvas = recorder.beginRecording(bitmap.width(), bitmap.height());
+ SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(bitmap.width()),
+ SkIntToScalar(bitmap.height()));
canvas->drawBitmap(bitmap, 0, 0);
SkAutoTUnref<SkPicture> picture(recorder.endRecording());
diff --git a/tests/SerializationTest.cpp b/tests/SerializationTest.cpp
index 2dc0c62cb5..4e11f120db 100644
--- a/tests/SerializationTest.cpp
+++ b/tests/SerializationTest.cpp
@@ -263,7 +263,8 @@ static void TestBitmapSerialization(const SkBitmap& validBitmap,
static SkBitmap draw_picture(SkPicture& picture) {
SkBitmap bitmap;
- bitmap.allocN32Pixels(picture.width(), picture.height());
+ bitmap.allocN32Pixels(SkScalarCeilToInt(picture.cullRect().width()),
+ SkScalarCeilToInt(picture.cullRect().height()));
SkCanvas canvas(bitmap);
picture.draw(&canvas);
return bitmap;
@@ -315,7 +316,9 @@ static void TestPictureTypefaceSerialization(skiatest::Reporter* reporter) {
// Paint some text.
SkPictureRecorder recorder;
SkIRect canvasRect = SkIRect::MakeWH(kBitmapSize, kBitmapSize);
- SkCanvas* canvas = recorder.beginRecording(canvasRect.width(), canvasRect.height(), NULL, 0);
+ SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(canvasRect.width()),
+ SkIntToScalar(canvasRect.height()),
+ NULL, 0);
canvas->drawColor(SK_ColorWHITE);
canvas->drawText("A", 1, 24, 32, paint);
SkAutoTUnref<SkPicture> picture(recorder.endRecording());
@@ -364,7 +367,7 @@ static bool make_checkerboard_bitmap(SkBitmap& bitmap) {
return success;
}
-static bool drawSomething(SkCanvas* canvas) {
+static bool draw_something(SkCanvas* canvas) {
SkPaint paint;
SkBitmap bitmap;
bool success = make_checkerboard_bitmap(bitmap);
@@ -478,7 +481,9 @@ DEF_TEST(Serialization, reporter) {
// Test simple SkPicture serialization
{
SkPictureRecorder recorder;
- bool didDraw = drawSomething(recorder.beginRecording(kBitmapSize, kBitmapSize, NULL, 0));
+ bool didDraw = draw_something(recorder.beginRecording(SkIntToScalar(kBitmapSize),
+ SkIntToScalar(kBitmapSize),
+ NULL, 0));
REPORTER_ASSERT(reporter, didDraw);
SkAutoTUnref<SkPicture> pict(recorder.endRecording());