OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "skia/ext/alpha_proxy_canvas.h" | |
6 | |
7 namespace skia { | |
8 | |
9 AlphaProxyCanvas::AlphaProxyCanvas(SkCanvas* target, | |
10 float opacity, | |
11 bool allow_filter) | |
12 : SkProxyCanvas(target), opacity_(opacity), allow_filter_(allow_filter) {} | |
13 | |
14 AlphaProxyCanvas::~AlphaProxyCanvas() {} | |
15 | |
16 int AlphaProxyCanvas::saveLayer(const SkRect* bounds, | |
17 const SkPaint* paint, | |
18 SkCanvas::SaveFlags flags) { | |
19 SkPaint new_paint = AlphaPaint(paint); | |
20 return INHERITED::saveLayer(bounds, &new_paint, flags); | |
21 } | |
22 | |
23 void AlphaProxyCanvas::drawPaint(const SkPaint& paint) { | |
24 INHERITED::drawPaint(AlphaPaint(&paint)); | |
25 } | |
26 | |
27 void AlphaProxyCanvas::drawPoints(SkCanvas::PointMode mode, | |
28 size_t count, | |
29 const SkPoint pts[], | |
30 const SkPaint& paint) { | |
31 INHERITED::drawPoints(mode, count, pts, AlphaPaint(&paint)); | |
32 } | |
33 | |
34 void AlphaProxyCanvas::drawRect(const SkRect& rect, const SkPaint& paint) { | |
35 INHERITED::drawRect(rect, AlphaPaint(&paint)); | |
36 } | |
37 | |
38 void AlphaProxyCanvas::drawOval(const SkRect& oval, const SkPaint& paint) { | |
39 INHERITED::drawOval(oval, AlphaPaint(&paint)); | |
40 } | |
41 | |
42 void AlphaProxyCanvas::drawRRect(const SkRRect& rrect, const SkPaint& paint) { | |
43 INHERITED::drawRRect(rrect, AlphaPaint(&paint)); | |
44 } | |
45 | |
46 void AlphaProxyCanvas::drawPath(const SkPath& path, const SkPaint& paint) { | |
47 INHERITED::drawPath(path, AlphaPaint(&paint)); | |
48 } | |
49 | |
50 void AlphaProxyCanvas::drawBitmap(const SkBitmap& bitmap, | |
51 SkScalar left, | |
52 SkScalar top, | |
53 const SkPaint* paint) { | |
54 SkPaint new_paint = AlphaPaint(paint); | |
55 INHERITED::drawBitmap(bitmap, left, top, &new_paint); | |
56 } | |
57 | |
58 void AlphaProxyCanvas::drawBitmapRectToRect(const SkBitmap& bitmap, | |
59 const SkRect* src, | |
60 const SkRect& dst, | |
61 const SkPaint* paint) { | |
62 SkPaint new_paint = AlphaPaint(paint); | |
63 INHERITED::drawBitmapRectToRect(bitmap, src, dst, &new_paint); | |
64 } | |
65 | |
66 void AlphaProxyCanvas::drawBitmapMatrix(const SkBitmap& bitmap, | |
67 const SkMatrix& m, | |
68 const SkPaint* paint) { | |
69 SkPaint new_paint = AlphaPaint(paint); | |
70 INHERITED::drawBitmapMatrix(bitmap, m, &new_paint); | |
71 } | |
72 | |
73 void AlphaProxyCanvas::drawBitmapNine(const SkBitmap& bitmap, | |
74 const SkIRect& center, | |
75 const SkRect& dst, | |
76 const SkPaint* paint) { | |
77 SkPaint new_paint = AlphaPaint(paint); | |
78 INHERITED::drawBitmapNine(bitmap, center, dst, &new_paint); | |
79 } | |
80 | |
81 void AlphaProxyCanvas::drawSprite(const SkBitmap& bitmap, | |
82 int left, | |
83 int top, | |
84 const SkPaint* paint) { | |
85 SkPaint new_paint = AlphaPaint(paint); | |
86 INHERITED::drawSprite(bitmap, left, top, &new_paint); | |
87 } | |
88 | |
89 void AlphaProxyCanvas::drawText(const void* text, | |
90 size_t byteLength, | |
91 SkScalar x, | |
92 SkScalar y, | |
93 const SkPaint& paint) { | |
94 INHERITED::drawText(text, byteLength, x, y, AlphaPaint(&paint)); | |
95 } | |
96 | |
97 void AlphaProxyCanvas::drawPosText(const void* text, | |
98 size_t byteLength, | |
99 const SkPoint pos[], | |
100 const SkPaint& paint) { | |
101 INHERITED::drawPosText(text, byteLength, pos, AlphaPaint(&paint)); | |
102 } | |
103 | |
104 void AlphaProxyCanvas::drawPosTextH(const void* text, | |
105 size_t byteLength, | |
106 const SkScalar xpos[], | |
107 SkScalar constY, | |
108 const SkPaint& paint) { | |
109 INHERITED::drawPosTextH(text, byteLength, xpos, constY, AlphaPaint(&paint)); | |
110 } | |
111 | |
112 void AlphaProxyCanvas::drawTextOnPath(const void* text, | |
113 size_t byteLength, | |
114 const SkPath& path, | |
115 const SkMatrix* matrix, | |
116 const SkPaint& paint) { | |
117 INHERITED::drawTextOnPath(text, byteLength, path, matrix, AlphaPaint(&paint)); | |
118 } | |
119 | |
120 void AlphaProxyCanvas::drawVertices(SkCanvas::VertexMode vmode, | |
121 int vertexCount, | |
122 const SkPoint vertices[], | |
123 const SkPoint texs[], | |
124 const SkColor colors[], | |
125 SkXfermode* xmode, | |
126 const uint16_t indices[], | |
127 int indexCount, | |
128 const SkPaint& paint) { | |
129 INHERITED::drawVertices(vmode, | |
130 vertexCount, | |
131 vertices, | |
132 texs, | |
133 colors, | |
134 xmode, | |
135 indices, | |
136 indexCount, | |
137 AlphaPaint(&paint)); | |
138 } | |
139 | |
140 SkPaint AlphaProxyCanvas::AlphaPaint(const SkPaint* paint) const { | |
141 SkPaint alpha_paint; | |
142 if (paint) | |
143 alpha_paint = *paint; | |
144 if (opacity_ != 1.f) { | |
145 alpha_paint.setAlpha(alpha_paint.getAlpha() * opacity_); | |
146 alpha_paint.setXfermodeMode(SkXfermode::kSrcOver_Mode); | |
enne (OOO)
2013/08/27 00:25:52
I am most skeptical about this particular line. H
aelias_OOO_until_Jul13
2013/08/27 07:02:28
We can't. I added a DCHECK the mode is already Sr
| |
147 } | |
148 if (!allow_filter_) | |
149 alpha_paint.setFilterBitmap(false); | |
150 return alpha_paint; | |
151 } | |
152 | |
153 } // namespace skia | |
OLD | NEW |