Skip to content

Commit 9518578

Browse files
committed
Remove concatAlpha() and concatBlendMode() from Canvas.
1 parent 621aef1 commit 9518578

File tree

4 files changed

+31
-13
lines changed

4 files changed

+31
-13
lines changed

Diff for: src/rendering/graphics/Modifier.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,11 @@ bool BlendModifier::hitTest(RenderCache*, float, float) const {
200200
void BlendModifier::applyToGraphic(Canvas* canvas, RenderCache* cache,
201201
std::shared_ptr<Graphic> graphic) const {
202202
canvas->save();
203-
canvas->concatAlpha(alpha);
204-
canvas->concatBlendMode(ToBlend(blendMode));
203+
auto newAlpha = OpacityConcat(canvas->getAlpha(), alpha);
204+
canvas->setAlpha(newAlpha);
205+
if (blendMode != BlendMode::Normal) {
206+
canvas->setBlendMode(ToBlend(blendMode));
207+
}
205208
graphic->draw(canvas, cache);
206209
canvas->restore();
207210
}

Diff for: tgfx/include/gpu/Canvas.h

+14-4
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,24 @@ class Canvas {
9595
void concat(const Matrix& matrix);
9696

9797
/**
98-
* Replaces the global alpha with specified alpha premultiplied with existing alpha.
98+
* Returns the current global alpha.
9999
*/
100-
void concatAlpha(Opacity alpha);
100+
Opacity getAlpha() const;
101101

102102
/**
103-
* Replaces the global blend mode with specified blend mode if it is not BlendMode::Normal.
103+
* Replaces the global alpha with specified newAlpha.
104104
*/
105-
void concatBlendMode(Blend blendMode);
105+
void setAlpha(Opacity newAlpha);
106+
107+
/**
108+
* Returns the current global blend mode.
109+
*/
110+
Blend getBlendMode() const;
111+
112+
/**
113+
* Replaces the global blend mode with specified new blend mode.
114+
*/
115+
void setBlendMode(Blend blendMode);
106116

107117
/**
108118
* Returns the current total clip.

Diff for: tgfx/src/gpu/Canvas.cpp

+11-6
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,19 @@ void Canvas::concat(const Matrix& matrix) {
6161
onSetMatrix(globalPaint.matrix);
6262
}
6363

64-
void Canvas::concatAlpha(Opacity alpha) {
65-
globalPaint.alpha = OpacityConcat(globalPaint.alpha, alpha);
64+
Opacity Canvas::getAlpha() const {
65+
return globalPaint.alpha;
6666
}
6767

68-
void Canvas::concatBlendMode(Blend blendMode) {
69-
if (blendMode == Blend::SrcOver) {
70-
return;
71-
}
68+
void Canvas::setAlpha(Opacity newAlpha) {
69+
globalPaint.alpha = newAlpha;
70+
}
71+
72+
Blend Canvas::getBlendMode() const {
73+
return globalPaint.blendMode;
74+
}
75+
76+
void Canvas::setBlendMode(Blend blendMode) {
7277
globalPaint.blendMode = blendMode;
7378
}
7479

Diff for: tgfx/src/gpu/opengl/GLCanvas.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ void GLCanvas::drawColorGlyphs(const GlyphID glyphIDs[], const Point positions[]
260260
glyphMatrix.postTranslate(position.x, position.y);
261261
save();
262262
concat(glyphMatrix);
263-
concatAlpha(paint.getAlpha());
263+
globalPaint.alpha = OpacityConcat(globalPaint.alpha, paint.getAlpha());
264264
auto texture = glyphBuffer->makeTexture(getContext());
265265
drawTexture(texture.get(), nullptr, false);
266266
restore();

0 commit comments

Comments
 (0)