Index: skia/ext/alpha_proxy_canvas.cc |
diff --git a/skia/ext/alpha_proxy_canvas.cc b/skia/ext/alpha_proxy_canvas.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..27e76ebfa2f20c81674fd9918ddeead3c9aab7c3 |
--- /dev/null |
+++ b/skia/ext/alpha_proxy_canvas.cc |
@@ -0,0 +1,159 @@ |
+// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "skia/ext/alpha_proxy_canvas.h" |
+ |
+#include "base/logging.h" |
+ |
+namespace skia { |
+ |
+AlphaProxyCanvas::AlphaProxyCanvas(SkCanvas* target, |
+ float opacity, |
+ bool allow_filter) |
+ : SkProxyCanvas(target), opacity_(opacity), allow_filter_(allow_filter) {} |
+ |
+AlphaProxyCanvas::~AlphaProxyCanvas() {} |
+ |
+int AlphaProxyCanvas::saveLayer(const SkRect* bounds, |
+ const SkPaint* paint, |
+ SkCanvas::SaveFlags flags) { |
+ SkPaint new_paint = AlphaPaint(paint); |
enne (OOO)
2013/08/27 18:53:30
Shouldn't new_paint only be AlphaPaint for the top
aelias_OOO_until_Jul13
2013/08/28 02:38:40
Correct, and with the SkDrawFilter approach, this
|
+ return INHERITED::saveLayer(bounds, &new_paint, flags); |
+} |
+ |
+void AlphaProxyCanvas::drawPaint(const SkPaint& paint) { |
+ INHERITED::drawPaint(AlphaPaint(&paint)); |
+} |
+ |
+void AlphaProxyCanvas::drawPoints(SkCanvas::PointMode mode, |
+ size_t count, |
+ const SkPoint pts[], |
+ const SkPaint& paint) { |
+ INHERITED::drawPoints(mode, count, pts, AlphaPaint(&paint)); |
+} |
+ |
+void AlphaProxyCanvas::drawRect(const SkRect& rect, const SkPaint& paint) { |
+ INHERITED::drawRect(rect, AlphaPaint(&paint)); |
+} |
+ |
+void AlphaProxyCanvas::drawOval(const SkRect& oval, const SkPaint& paint) { |
+ INHERITED::drawOval(oval, AlphaPaint(&paint)); |
+} |
+ |
+void AlphaProxyCanvas::drawRRect(const SkRRect& rrect, const SkPaint& paint) { |
+ INHERITED::drawRRect(rrect, AlphaPaint(&paint)); |
+} |
+ |
+void AlphaProxyCanvas::drawPath(const SkPath& path, const SkPaint& paint) { |
+ INHERITED::drawPath(path, AlphaPaint(&paint)); |
+} |
+ |
+void AlphaProxyCanvas::drawBitmap(const SkBitmap& bitmap, |
+ SkScalar left, |
+ SkScalar top, |
+ const SkPaint* paint) { |
+ SkPaint new_paint = AlphaPaint(paint); |
+ INHERITED::drawBitmap(bitmap, left, top, &new_paint); |
+} |
+ |
+void AlphaProxyCanvas::drawBitmapRectToRect(const SkBitmap& bitmap, |
+ const SkRect* src, |
+ const SkRect& dst, |
+ const SkPaint* paint, |
+ DrawBitmapRectFlags flags) { |
+ SkPaint new_paint = AlphaPaint(paint); |
+ INHERITED::drawBitmapRectToRect(bitmap, src, dst, &new_paint, flags); |
+} |
+ |
+void AlphaProxyCanvas::drawBitmapMatrix(const SkBitmap& bitmap, |
+ const SkMatrix& m, |
+ const SkPaint* paint) { |
+ SkPaint new_paint = AlphaPaint(paint); |
+ INHERITED::drawBitmapMatrix(bitmap, m, &new_paint); |
+} |
+ |
+void AlphaProxyCanvas::drawBitmapNine(const SkBitmap& bitmap, |
+ const SkIRect& center, |
+ const SkRect& dst, |
+ const SkPaint* paint) { |
+ SkPaint new_paint = AlphaPaint(paint); |
+ INHERITED::drawBitmapNine(bitmap, center, dst, &new_paint); |
+} |
+ |
+void AlphaProxyCanvas::drawSprite(const SkBitmap& bitmap, |
+ int left, |
+ int top, |
+ const SkPaint* paint) { |
+ SkPaint new_paint = AlphaPaint(paint); |
+ INHERITED::drawSprite(bitmap, left, top, &new_paint); |
+} |
+ |
+void AlphaProxyCanvas::drawText(const void* text, |
+ size_t byteLength, |
+ SkScalar x, |
+ SkScalar y, |
+ const SkPaint& paint) { |
+ INHERITED::drawText(text, byteLength, x, y, AlphaPaint(&paint)); |
+} |
+ |
+void AlphaProxyCanvas::drawPosText(const void* text, |
+ size_t byteLength, |
+ const SkPoint pos[], |
+ const SkPaint& paint) { |
+ INHERITED::drawPosText(text, byteLength, pos, AlphaPaint(&paint)); |
+} |
+ |
+void AlphaProxyCanvas::drawPosTextH(const void* text, |
+ size_t byteLength, |
+ const SkScalar xpos[], |
+ SkScalar constY, |
+ const SkPaint& paint) { |
+ INHERITED::drawPosTextH(text, byteLength, xpos, constY, AlphaPaint(&paint)); |
+} |
+ |
+void AlphaProxyCanvas::drawTextOnPath(const void* text, |
+ size_t byteLength, |
+ const SkPath& path, |
+ const SkMatrix* matrix, |
+ const SkPaint& paint) { |
+ INHERITED::drawTextOnPath(text, byteLength, path, matrix, AlphaPaint(&paint)); |
+} |
+ |
+void AlphaProxyCanvas::drawVertices(SkCanvas::VertexMode vmode, |
+ int vertexCount, |
+ const SkPoint vertices[], |
+ const SkPoint texs[], |
+ const SkColor colors[], |
+ SkXfermode* xmode, |
+ const uint16_t indices[], |
+ int indexCount, |
+ const SkPaint& paint) { |
+ INHERITED::drawVertices(vmode, |
+ vertexCount, |
+ vertices, |
+ texs, |
+ colors, |
+ xmode, |
+ indices, |
+ indexCount, |
+ AlphaPaint(&paint)); |
+} |
+ |
+SkPaint AlphaProxyCanvas::AlphaPaint(const SkPaint* paint) const { |
+ SkPaint alpha_paint; |
+ if (paint) |
+ alpha_paint = *paint; |
+ if (opacity_ != 1.f) { |
+ DCHECK(!paint || |
+ SkXfermode::IsMode(paint->getXfermode(), SkXfermode::kSrc_Mode) || |
+ SkXfermode::IsMode(paint->getXfermode(), SkXfermode::kSrcOver_Mode)); |
enne (OOO)
2013/08/27 18:53:30
Unless I'm missing something, I am not sure that a
aelias_OOO_until_Jul13
2013/08/28 02:38:40
With further experimentation, it was unnecessary t
|
+ alpha_paint.setAlpha(alpha_paint.getAlpha() * opacity_); |
+ alpha_paint.setXfermodeMode(SkXfermode::kSrcOver_Mode); |
+ } |
+ if (!allow_filter_) |
+ alpha_paint.setFilterBitmap(false); |
+ return alpha_paint; |
+} |
+ |
+} // namespace skia |