[PDF] Fix some scalar/int assumptions.
Review URL: http://codereview.appspot.com/5516043
git-svn-id: http://skia.googlecode.com/svn/trunk@2975 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gm/drawbitmaprect.cpp b/gm/drawbitmaprect.cpp
index 1f8210b..5832a9c 100644
--- a/gm/drawbitmaprect.cpp
+++ b/gm/drawbitmaprect.cpp
@@ -81,7 +81,7 @@
SkBitmap::kARGB_8888_Config,
kBmpSize, kBmpSize);
}
- SkRect dstRect = { 0, 0, 64, 64};
+ SkRect dstRect = { 0, 0, SkIntToScalar(64), SkIntToScalar(64)};
static const int kMaxSrcRectSize = 1 << (SkNextLog2(kBmpSize) + 2);
static const int kPadX = 30;
diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp
index f46cade..ced3107 100644
--- a/src/pdf/SkPDFDevice.cpp
+++ b/src/pdf/SkPDFDevice.cpp
@@ -179,7 +179,7 @@
}
void updateClip(const SkClipStack& clipStack, const SkRegion& clipRegion,
- const SkIPoint& translation);
+ const SkPoint& translation);
void updateMatrix(const SkMatrix& matrix);
void updateDrawingState(const GraphicStateEntry& state);
@@ -283,7 +283,7 @@
// on the page to optimize this.
void GraphicStackState::updateClip(const SkClipStack& clipStack,
const SkRegion& clipRegion,
- const SkIPoint& translation) {
+ const SkPoint& translation) {
if (clipStack == currentEntry()->fClipStack) {
return;
}
@@ -488,7 +488,8 @@
// Compute the size of the drawing area.
SkVector drawingSize;
SkMatrix inverse;
- drawingSize.set(contentSize.fWidth, contentSize.fHeight);
+ drawingSize.set(SkIntToScalar(contentSize.fWidth),
+ SkIntToScalar(contentSize.fHeight));
initialTransform->invert(&inverse);
inverse.mapVectors(&drawingSize, 1);
SkISize size = SkSize::Make(drawingSize.fX, drawingSize.fY).toRound();
@@ -502,6 +503,7 @@
return bitmap;
}
+// TODO(vandebo) change pageSize to SkSize.
SkPDFDevice::SkPDFDevice(const SkISize& pageSize, const SkISize& contentSize,
const SkMatrix& initialTransform)
: SkDevice(makeContentBitmap(contentSize, &initialTransform)),
@@ -512,8 +514,8 @@
// Skia generally uses the top left as the origin but PDF natively has the
// origin at the bottom left. This matrix corrects for that. But that only
// needs to be done once, we don't do it when layering.
- fInitialTransform.setTranslate(0, pageSize.fHeight);
- fInitialTransform.preScale(1, -1);
+ fInitialTransform.setTranslate(0, SkIntToScalar(pageSize.fHeight));
+ fInitialTransform.preScale(SK_Scalar1, -SK_Scalar1);
fInitialTransform.preConcat(initialTransform);
SkIRect existingClip = SkIRect::MakeWH(this->width(), this->height());
@@ -522,6 +524,7 @@
this->init();
}
+// TODO(vandebo) change layerSize to SkSize.
SkPDFDevice::SkPDFDevice(const SkISize& layerSize,
const SkClipStack& existingClipStack,
const SkRegion& existingClipRegion)
@@ -1092,7 +1095,8 @@
// right thing to pass here.
GraphicStackState gsState(fExistingClipStack, fExistingClipRegion, data);
while (entry != NULL) {
- SkIPoint translation = this->getOrigin();
+ SkPoint translation;
+ translation.iset(this->getOrigin());
translation.negate();
gsState.updateClip(entry->fState.fClipStack, entry->fState.fClipRegion,
translation);
@@ -1501,8 +1505,8 @@
const SkPaint& paint) {
SkMatrix scaled;
// Adjust for origin flip.
- scaled.setScale(1, -1);
- scaled.postTranslate(0, 1);
+ scaled.setScale(SK_Scalar1, -SK_Scalar1);
+ scaled.postTranslate(0, SK_Scalar1);
// Scale the image up from 1x1 to WxH.
SkIRect subset = SkIRect::MakeWH(bitmap.width(), bitmap.height());
scaled.postScale(SkIntToScalar(subset.width()),
diff --git a/src/pdf/SkPDFGraphicState.cpp b/src/pdf/SkPDFGraphicState.cpp
index d128630..ad3f57b 100644
--- a/src/pdf/SkPDFGraphicState.cpp
+++ b/src/pdf/SkPDFGraphicState.cpp
@@ -200,7 +200,7 @@
insertName("Type", "ExtGState");
SkRefPtr<SkPDFScalar> alpha =
- new SkPDFScalar(fPaint.getAlpha() * SkScalarInvert(0xFF));
+ new SkPDFScalar(SkScalarDiv(fPaint.getAlpha(), 0xFF));
alpha->unref(); // SkRefPtr and new both took a reference.
insert("CA", alpha.get());
insert("ca", alpha.get());
diff --git a/src/pdf/SkPDFShader.cpp b/src/pdf/SkPDFShader.cpp
index 84c5576..b6e0939 100644
--- a/src/pdf/SkPDFShader.cpp
+++ b/src/pdf/SkPDFShader.cpp
@@ -525,7 +525,7 @@
SkMatrix unflip;
unflip.setTranslate(0, SkScalarRound(surfaceBBox.height()));
- unflip.preScale(1, -1);
+ unflip.preScale(SK_Scalar1, -SK_Scalar1);
SkISize size = SkISize::Make(SkScalarRound(surfaceBBox.width()),
SkScalarRound(surfaceBBox.height()));
SkPDFDevice pattern(size, size, unflip);
@@ -554,7 +554,7 @@
}
if (tileModes[1] == SkShader::kMirror_TileMode) {
SkMatrix yMirror;
- yMirror.setScale(1, -1);
+ yMirror.setScale(SK_Scalar1, -SK_Scalar1);
yMirror.postTranslate(0, 2 * height);
canvas.drawBitmapMatrix(*image, yMirror);
patternBBox.fBottom += height;
@@ -616,7 +616,7 @@
canvas.drawBitmapMatrix(left, leftMatrix);
if (tileModes[1] == SkShader::kMirror_TileMode) {
- leftMatrix.postScale(1, -1);
+ leftMatrix.postScale(SK_Scalar1, -SK_Scalar1);
leftMatrix.postTranslate(0, 2 * height);
canvas.drawBitmapMatrix(left, leftMatrix);
}
@@ -634,7 +634,7 @@
canvas.drawBitmapMatrix(right, rightMatrix);
if (tileModes[1] == SkShader::kMirror_TileMode) {
- rightMatrix.postScale(1, -1);
+ rightMatrix.postScale(SK_Scalar1, -SK_Scalar1);
rightMatrix.postTranslate(0, 2 * height);
canvas.drawBitmapMatrix(right, rightMatrix);
}
@@ -649,7 +649,7 @@
SkAssertResult(image->extractSubset(&top, subset));
SkMatrix topMatrix;
- topMatrix.setScale(1, -surfaceBBox.fTop);
+ topMatrix.setScale(SK_Scalar1, -surfaceBBox.fTop);
topMatrix.postTranslate(0, surfaceBBox.fTop);
canvas.drawBitmapMatrix(top, topMatrix);
@@ -667,7 +667,7 @@
SkAssertResult(image->extractSubset(&bottom, subset));
SkMatrix bottomMatrix;
- bottomMatrix.setScale(1, surfaceBBox.fBottom - height);
+ bottomMatrix.setScale(SK_Scalar1, surfaceBBox.fBottom - height);
bottomMatrix.postTranslate(0, height);
canvas.drawBitmapMatrix(bottom, bottomMatrix);