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/src/utils/SkDumpCanvas.cpp b/src/utils/SkDumpCanvas.cpp
index 5e3d153..e7b64a4 100644
--- a/src/utils/SkDumpCanvas.cpp
+++ b/src/utils/SkDumpCanvas.cpp
@@ -434,13 +434,15 @@
void SkDumpCanvas::onDrawPicture(const SkPicture* picture, const SkMatrix* matrix,
const SkPaint* paint) {
- this->dump(kDrawPicture_Verb, NULL, "drawPicture(%p) %d:%d", picture,
- picture->width(), picture->height());
+ this->dump(kDrawPicture_Verb, NULL, "drawPicture(%p) %f:%f:%f:%f", picture,
+ picture->cullRect().fLeft, picture->cullRect().fTop,
+ picture->cullRect().fRight, picture->cullRect().fBottom);
fNestLevel += 1;
this->INHERITED::onDrawPicture(picture, matrix, paint);
fNestLevel -= 1;
- this->dump(kDrawPicture_Verb, NULL, "endPicture(%p) %d:%d", &picture,
- picture->width(), picture->height());
+ this->dump(kDrawPicture_Verb, NULL, "endPicture(%p) %f:%f:%f:%f", &picture,
+ picture->cullRect().fLeft, picture->cullRect().fTop,
+ picture->cullRect().fRight, picture->cullRect().fBottom);
}
void SkDumpCanvas::drawVertices(VertexMode vmode, int vertexCount,
diff --git a/src/utils/SkGatherPixelRefsAndRects.cpp b/src/utils/SkGatherPixelRefsAndRects.cpp
index f46fe8e..ee5b147 100644
--- a/src/utils/SkGatherPixelRefsAndRects.cpp
+++ b/src/utils/SkGatherPixelRefsAndRects.cpp
@@ -11,15 +11,15 @@
void SkPictureUtils::GatherPixelRefsAndRects(SkPicture* pict,
SkPictureUtils::SkPixelRefContainer* prCont) {
- if (0 == pict->width() || 0 == pict->height()) {
+ if (pict->cullRect().isEmpty()) {
return ;
}
- SkGatherPixelRefsAndRectsDevice device(pict->width(), pict->height(), prCont);
+ SkGatherPixelRefsAndRectsDevice device(SkScalarCeilToInt(pict->cullRect().width()),
+ SkScalarCeilToInt(pict->cullRect().height()),
+ prCont);
SkNoSaveLayerCanvas canvas(&device);
- canvas.clipRect(SkRect::MakeWH(SkIntToScalar(pict->width()),
- SkIntToScalar(pict->height())),
- SkRegion::kIntersect_Op, false);
+ canvas.clipRect(pict->cullRect(), SkRegion::kIntersect_Op, false);
canvas.drawPicture(pict);
}
diff --git a/src/utils/SkPictureUtils.cpp b/src/utils/SkPictureUtils.cpp
index 85d523f..4f4d2bf 100644
--- a/src/utils/SkPictureUtils.cpp
+++ b/src/utils/SkPictureUtils.cpp
@@ -196,16 +196,16 @@
}
// this test also handles if either area or pict's width/height are empty
- if (!SkRect::Intersects(area,
- SkRect::MakeWH(SkIntToScalar(pict->width()),
- SkIntToScalar(pict->height())))) {
+ if (!SkRect::Intersects(area, pict->cullRect())) {
return NULL;
}
SkTDArray<SkPixelRef*> array;
PixelRefSet prset(&array);
- GatherPixelRefDevice device(pict->width(), pict->height(), &prset);
+ GatherPixelRefDevice device(SkScalarCeilToInt(pict->cullRect().width()),
+ SkScalarCeilToInt(pict->cullRect().height()),
+ &prset);
SkNoSaveLayerCanvas canvas(&device);
canvas.clipRect(area, SkRegion::kIntersect_Op, false);
diff --git a/src/utils/debugger/SkDebugCanvas.cpp b/src/utils/debugger/SkDebugCanvas.cpp
index 2b0eab7..85fb7a4 100644
--- a/src/utils/debugger/SkDebugCanvas.cpp
+++ b/src/utils/debugger/SkDebugCanvas.cpp
@@ -14,11 +14,10 @@
#include "SkDevice.h"
#include "SkXfermode.h"
-SkDebugCanvas::SkDebugCanvas(int width, int height)
- : INHERITED(width, height)
+SkDebugCanvas::SkDebugCanvas(int windowWidth, int windowHeight)
+ : INHERITED(windowWidth, windowHeight)
, fPicture(NULL)
- , fWidth(width)
- , fHeight(height)
+ , fWindowSize(SkISize::Make(windowWidth, windowHeight))
, fFilter(false)
, fMegaVizMode(false)
, fIndex(0)
@@ -76,7 +75,7 @@
SkCanvas canvas(bitmap);
canvas.translate(SkIntToScalar(-x), SkIntToScalar(-y));
- applyUserTransform(&canvas);
+ this->applyUserTransform(&canvas);
int layer = 0;
SkColor prev = bitmap.getColor(0,0);
@@ -255,10 +254,10 @@
}
canvas->clear(SK_ColorTRANSPARENT);
canvas->resetMatrix();
- SkRect rect = SkRect::MakeWH(SkIntToScalar(fWidth),
- SkIntToScalar(fHeight));
- canvas->clipRect(rect, SkRegion::kReplace_Op );
- applyUserTransform(canvas);
+ SkRect rect = SkRect::MakeWH(SkIntToScalar(fWindowSize.fWidth),
+ SkIntToScalar(fWindowSize.fHeight));
+ canvas->clipRect(rect, SkRegion::kReplace_Op);
+ this->applyUserTransform(canvas);
fOutstandingSaveCount = 0;
}
@@ -292,17 +291,7 @@
for (; i <= index; i++) {
if (i == index && fFilter) {
- SkPaint p;
- p.setColor(0xAAFFFFFF);
- canvas->save();
- canvas->resetMatrix();
- SkRect mask;
- mask.set(SkIntToScalar(0), SkIntToScalar(0),
- SkIntToScalar(fWidth), SkIntToScalar(fHeight));
- canvas->clipRect(mask, SkRegion::kReplace_Op, false);
- canvas->drawRectCoords(SkIntToScalar(0), SkIntToScalar(0),
- SkIntToScalar(fWidth), SkIntToScalar(fHeight), p);
- canvas->restore();
+ canvas->clear(0xAAFFFFFF);
}
if (fCommandVector[i]->isVisible()) {
@@ -321,12 +310,13 @@
}
if (fMegaVizMode) {
- SkRect r = SkRect::MakeWH(SkIntToScalar(fWidth), SkIntToScalar(fHeight));
+ SkRect r = SkRect::MakeWH(SkIntToScalar(fWindowSize.fWidth),
+ SkIntToScalar(fWindowSize.fHeight));
r.outset(SK_Scalar1, SK_Scalar1);
canvas->save();
// nuke the CTM
- canvas->setMatrix(SkMatrix::I());
+ canvas->resetMatrix();
// turn off clipping
canvas->clipRect(r, SkRegion::kReplace_Op);
diff --git a/src/utils/debugger/SkDebugCanvas.h b/src/utils/debugger/SkDebugCanvas.h
index 94ad426..2e9a032 100644
--- a/src/utils/debugger/SkDebugCanvas.h
+++ b/src/utils/debugger/SkDebugCanvas.h
@@ -145,10 +145,7 @@
*/
void toggleCommand(int index, bool toggle);
- void setBounds(int width, int height) {
- fWidth = width;
- fHeight = height;
- }
+ void setWindowSize(int width, int height) { fWindowSize.set(width, height); }
void setUserMatrix(SkMatrix matrix) {
fUserMatrix = matrix;
@@ -259,8 +256,7 @@
private:
SkTDArray<SkDrawCommand*> fCommandVector;
SkPicture* fPicture;
- int fWidth;
- int fHeight;
+ SkISize fWindowSize;
bool fFilter;
bool fMegaVizMode;
int fIndex;
diff --git a/src/utils/debugger/SkDrawCommand.cpp b/src/utils/debugger/SkDrawCommand.cpp
index 3b1a028..3a07396 100644
--- a/src/utils/debugger/SkDrawCommand.cpp
+++ b/src/utils/debugger/SkDrawCommand.cpp
@@ -523,7 +523,9 @@
}
SkString* temp = new SkString;
- temp->appendf("SkPicture: W: %d H: %d", picture->width(), picture->height());
+ temp->appendf("SkPicture: L: %f T: %f R: %f B: %f",
+ picture->cullRect().fLeft, picture->cullRect().fTop,
+ picture->cullRect().fRight, picture->cullRect().fBottom);
fInfo.push(temp);
if (NULL != matrix) {
fInfo.push(SkObjectParser::MatrixToString(*matrix));
@@ -541,9 +543,7 @@
canvas->clear(0xFFFFFFFF);
canvas->save();
- SkRect bounds = SkRect::MakeWH(SkIntToScalar(fPicture->width()),
- SkIntToScalar(fPicture->height()));
- xlate_and_scale_to_bounds(canvas, bounds);
+ xlate_and_scale_to_bounds(canvas, fPicture->cullRect());
canvas->drawPicture(fPicture.get());