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

Unified Diff: src/pdf/SkPDFDevice.cpp

Issue 1159763004: SkPDF: with opaque draws, treat SRC mode as SRC_OVER (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-05-26 (Tuesday) 12:06:19 EDT Created 5 years, 7 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 | tests/skpdf_opaquesrcmodetosrcover.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pdf/SkPDFDevice.cpp
diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp
index 3b0d6f72ae5a1fdeaf51e41f7e2c536486c61084..d4cee9f464f33b3d44ec078a8a2b97dd2f78008e 100644
--- a/src/pdf/SkPDFDevice.cpp
+++ b/src/pdf/SkPDFDevice.cpp
@@ -37,6 +37,19 @@
// Utility functions
+static void fix_paint_xfermode(SkPaint* paint) {
reed1 2015/05/26 16:28:23 "fix" is not very descriptive, if I'm trying to un
hal.canary 2015/05/26 18:24:19 Done.
+ SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode;
+ if (paint->getXfermode() && paint->getXfermode()->asMode(&mode)) {
+ if (mode == SkXfermode::kSrc_Mode &&
+ paint->getAlpha() == SK_AlphaOPAQUE && !paint->getColorFilter() &&
+ !paint->getPathEffect() && !paint->getMaskFilter() &&
+ !paint->getRasterizer() && !paint->getImageFilter() &&
+ !paint->getLooper()) {
+ paint->setXfermodeMode(SkXfermode::kSrcOver_Mode);
+ }
+ }
+}
+
static void emit_pdf_color(SkColor color, SkWStream* result) {
SkASSERT(SkColorGetA(color) == 0xFF); // We handle alpha elsewhere.
SkScalar colorScale = SkScalarInvert(0xFF);
@@ -756,6 +769,8 @@ void SkPDFDevice::cleanUp(bool clearFontUsage) {
void SkPDFDevice::drawPaint(const SkDraw& d, const SkPaint& paint) {
SkPaint newPaint = paint;
+ fix_paint_xfermode(&newPaint);
+
newPaint.setStyle(SkPaint::kFill_Style);
ScopedContentEntry content(this, d, newPaint);
internalDrawPaint(newPaint, content.entry());
@@ -779,9 +794,14 @@ void SkPDFDevice::internalDrawPaint(const SkPaint& paint,
&contentEntry->fContent);
}
-void SkPDFDevice::drawPoints(const SkDraw& d, SkCanvas::PointMode mode,
- size_t count, const SkPoint* points,
- const SkPaint& passedPaint) {
+void SkPDFDevice::drawPoints(const SkDraw& d,
+ SkCanvas::PointMode mode,
+ size_t count,
+ const SkPoint* points,
+ const SkPaint& srcPaint) {
+ SkPaint passedPaint = srcPaint;
+ fix_paint_xfermode(&passedPaint);
+
if (count == 0) {
return;
}
@@ -866,8 +886,11 @@ void SkPDFDevice::drawPoints(const SkDraw& d, SkCanvas::PointMode mode,
}
}
-void SkPDFDevice::drawRect(const SkDraw& d, const SkRect& rect,
- const SkPaint& paint) {
+void SkPDFDevice::drawRect(const SkDraw& d,
+ const SkRect& rect,
+ const SkPaint& srcPaint) {
+ SkPaint paint = srcPaint;
+ fix_paint_xfermode(&paint);
SkRect r = rect;
r.sort();
@@ -894,21 +917,33 @@ void SkPDFDevice::drawRect(const SkDraw& d, const SkRect& rect,
&content.entry()->fContent);
}
-void SkPDFDevice::drawRRect(const SkDraw& draw, const SkRRect& rrect, const SkPaint& paint) {
+void SkPDFDevice::drawRRect(const SkDraw& draw,
+ const SkRRect& rrect,
+ const SkPaint& srcPaint) {
+ SkPaint paint = srcPaint;
+ fix_paint_xfermode(&paint);
SkPath path;
path.addRRect(rrect);
this->drawPath(draw, path, paint, NULL, true);
}
-void SkPDFDevice::drawOval(const SkDraw& draw, const SkRect& oval, const SkPaint& paint) {
+void SkPDFDevice::drawOval(const SkDraw& draw,
+ const SkRect& oval,
+ const SkPaint& srcPaint) {
+ SkPaint paint = srcPaint;
+ fix_paint_xfermode(&paint);
SkPath path;
path.addOval(oval);
this->drawPath(draw, path, paint, NULL, true);
}
-void SkPDFDevice::drawPath(const SkDraw& d, const SkPath& origPath,
- const SkPaint& paint, const SkMatrix* prePathMatrix,
+void SkPDFDevice::drawPath(const SkDraw& d,
+ const SkPath& origPath,
+ const SkPaint& srcPaint,
+ const SkMatrix* prePathMatrix,
bool pathIsMutable) {
+ SkPaint paint = srcPaint;
+ fix_paint_xfermode(&paint);
SkPath modifiedPath;
SkPath* pathPtr = const_cast<SkPath*>(&origPath);
@@ -967,8 +1002,13 @@ void SkPDFDevice::drawPath(const SkDraw& d, const SkPath& origPath,
void SkPDFDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap,
const SkRect* src, const SkRect& dst,
- const SkPaint& paint,
+ const SkPaint& srcPaint,
SkCanvas::DrawBitmapRectFlags flags) {
+ SkPaint paint = srcPaint;
+ if (bitmap.isOpaque()) {
+ fix_paint_xfermode(&paint);
+ }
+
// TODO: this code path must be updated to respect the flags parameter
SkMatrix matrix;
SkRect bitmapBounds, tmpSrc, tmpDst;
@@ -1023,7 +1063,12 @@ void SkPDFDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap,
}
void SkPDFDevice::drawBitmap(const SkDraw& d, const SkBitmap& bitmap,
- const SkMatrix& matrix, const SkPaint& paint) {
+ const SkMatrix& matrix, const SkPaint& srcPaint) {
+ SkPaint paint = srcPaint;
+ if (bitmap.isOpaque()) {
+ fix_paint_xfermode(&paint);
+ }
+
if (d.fClip->isEmpty()) {
return;
}
@@ -1035,7 +1080,12 @@ void SkPDFDevice::drawBitmap(const SkDraw& d, const SkBitmap& bitmap,
}
void SkPDFDevice::drawSprite(const SkDraw& d, const SkBitmap& bitmap,
- int x, int y, const SkPaint& paint) {
+ int x, int y, const SkPaint& srcPaint) {
+ SkPaint paint = srcPaint;
+ if (bitmap.isOpaque()) {
+ fix_paint_xfermode(&paint);
+ }
+
if (d.fClip->isEmpty()) {
return;
}
@@ -1082,7 +1132,10 @@ static SkString format_wide_string(const uint16_t* input,
}
void SkPDFDevice::drawText(const SkDraw& d, const void* text, size_t len,
- SkScalar x, SkScalar y, const SkPaint& paint) {
+ SkScalar x, SkScalar y, const SkPaint& srcPaint) {
+ SkPaint paint = srcPaint;
+ fix_paint_xfermode(&paint);
+
NOT_IMPLEMENTED(paint.getMaskFilter() != NULL, false);
if (paint.getMaskFilter() != NULL) {
// Don't pretend we support drawing MaskFilters, it makes for artifacts
@@ -1131,7 +1184,10 @@ void SkPDFDevice::drawText(const SkDraw& d, const void* text, size_t len,
void SkPDFDevice::drawPosText(const SkDraw& d, const void* text, size_t len,
const SkScalar pos[], int scalarsPerPos,
- const SkPoint& offset, const SkPaint& paint) {
+ const SkPoint& offset, const SkPaint& srcPaint) {
+ SkPaint paint = srcPaint;
+ fix_paint_xfermode(&paint);
+
NOT_IMPLEMENTED(paint.getMaskFilter() != NULL, false);
if (paint.getMaskFilter() != NULL) {
// Don't pretend we support drawing MaskFilters, it makes for artifacts
« no previous file with comments | « no previous file | tests/skpdf_opaquesrcmodetosrcover.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698