Skip to content

Commit

Permalink
Remove concatAlpha() and concatBlendMode() from Canvas.
Browse files Browse the repository at this point in the history
  • Loading branch information
domchen committed Feb 13, 2022
1 parent 5393b79 commit 19547a3
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 13 deletions.
7 changes: 5 additions & 2 deletions src/rendering/graphics/Modifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,11 @@ bool BlendModifier::hitTest(RenderCache*, float, float) const {
void BlendModifier::applyToGraphic(Canvas* canvas, RenderCache* cache,
std::shared_ptr<Graphic> graphic) const {
canvas->save();
canvas->concatAlpha(alpha);
canvas->concatBlendMode(ToBlend(blendMode));
auto newAlpha = OpacityConcat(canvas->getAlpha(), alpha);
canvas->setAlpha(newAlpha);
if (blendMode != BlendMode::Normal) {
canvas->setBlendMode(ToBlend(blendMode));
}
graphic->draw(canvas, cache);
canvas->restore();
}
Expand Down
18 changes: 14 additions & 4 deletions tgfx/include/gpu/Canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,24 @@ class Canvas {
void concat(const Matrix& matrix);

/**
* Replaces the global alpha with specified alpha premultiplied with existing alpha.
* Returns the current global alpha.
*/
void concatAlpha(Opacity alpha);
Opacity getAlpha() const;

/**
* Replaces the global blend mode with specified blend mode if it is not BlendMode::Normal.
* Replaces the global alpha with specified newAlpha.
*/
void concatBlendMode(Blend blendMode);
void setAlpha(Opacity newAlpha);

/**
* Returns the current global blend mode.
*/
Blend getBlendMode() const;

/**
* Replaces the global blend mode with specified new blend mode.
*/
void setBlendMode(Blend blendMode);

/**
* Returns the current total clip.
Expand Down
17 changes: 11 additions & 6 deletions tgfx/src/gpu/Canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,19 @@ void Canvas::concat(const Matrix& matrix) {
onSetMatrix(globalPaint.matrix);
}

void Canvas::concatAlpha(Opacity alpha) {
globalPaint.alpha = OpacityConcat(globalPaint.alpha, alpha);
Opacity Canvas::getAlpha() const {
return globalPaint.alpha;
}

void Canvas::concatBlendMode(Blend blendMode) {
if (blendMode == Blend::SrcOver) {
return;
}
void Canvas::setAlpha(Opacity newAlpha) {
globalPaint.alpha = newAlpha;
}

Blend Canvas::getBlendMode() const {
return globalPaint.blendMode;
}

void Canvas::setBlendMode(Blend blendMode) {
globalPaint.blendMode = blendMode;
}

Expand Down
2 changes: 1 addition & 1 deletion tgfx/src/gpu/opengl/GLCanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ void GLCanvas::drawColorGlyphs(const GlyphID glyphIDs[], const Point positions[]
glyphMatrix.postTranslate(position.x, position.y);
save();
concat(glyphMatrix);
concatAlpha(paint.getAlpha());
globalPaint.alpha = OpacityConcat(globalPaint.alpha, paint.getAlpha());
auto texture = glyphBuffer->makeTexture(getContext());
drawTexture(texture.get(), nullptr, false);
restore();
Expand Down

0 comments on commit 19547a3

Please sign in to comment.