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
diff --git a/tests/CanvasTest.cpp b/tests/CanvasTest.cpp
index 5d6a8d8..d460051 100644
--- a/tests/CanvasTest.cpp
+++ b/tests/CanvasTest.cpp
@@ -463,7 +463,8 @@
                                 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 @@
         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 778cc3f..a8cd5d0 100644
--- a/tests/ImageFilterTest.cpp
+++ b/tests/ImageFilterTest.cpp
@@ -421,7 +421,8 @@
     }
 }
 
-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 @@
     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 @@
     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 @@
     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 @@
     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 @@
 
     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 a94412e..d413a08 100755
--- a/tests/PathOpsSkpClipTest.cpp
+++ b/tests/PathOpsSkpClipTest.cpp
@@ -394,22 +394,21 @@
 
 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 @@
             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 @@
             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 627e96e..8b19df2 100644
--- a/tests/PictureTest.cpp
+++ b/tests/PictureTest.cpp
@@ -882,7 +882,7 @@
         {
             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 @@
         {
             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 @@
 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* 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 2dc0c62..4e11f12 100644
--- a/tests/SerializationTest.cpp
+++ b/tests/SerializationTest.cpp
@@ -263,7 +263,8 @@
 
 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 @@
     // 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 @@
     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 @@
     // 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());