Skip to content

Commit 6669e57

Browse files
authored
Add background color rendering support for blur background in RootLayer. (#1230)
1 parent d15a4d3 commit 6669e57

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

src/layers/RootLayer.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ bool RootLayer::drawLayer(const DrawArgs& args, Canvas* canvas, float alpha, Ble
120120
auto color = _backgroundColor;
121121
color.alpha = color.alpha * alpha;
122122
canvas->drawColor(color, blendMode);
123+
if (args.blurBackground) {
124+
args.blurBackground->getCanvas()->drawColor(color, blendMode);
125+
}
123126
return Layer::drawLayer(args, canvas, alpha, blendMode, transform3D);
124127
}
125128

test/baseline/version.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@
244244
"PassThoughAndNormal": "43cd416",
245245
"PassThrough_Test": "7fa7fcb8",
246246
"Preserve3DNestedLayers": "0b31d462",
247+
"RootLayerBackgroundColorWithBlurBackground": "d15a4d35",
247248
"ShapeStyleWithMatrix": "0cfb8996",
248249
"StrokeOnTop_Off": "80c523ee",
249250
"StrokeOnTop_On": "80c523ee",

test/src/LayerTest.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "layers/OpaqueContext.h"
2727
#include "layers/DrawArgs.h"
2828
#include "layers/RootLayer.h"
29+
#include "layers/BackgroundContext.h"
2930
#include "layers/SubtreeCache.h"
3031
#include "layers/TileCache.h"
3132
#include "layers/compositing3d/Layer3DContext.h"
@@ -3137,4 +3138,48 @@ TGFX_TEST(LayerTest, Contour3DWithDropShadow) {
31373138
EXPECT_TRUE(Baseline::Compare(surface, "LayerTest/Contour3DWithDropShadow"));
31383139
}
31393140

3141+
TGFX_TEST(LayerTest, RootLayerBackgroundColorWithBlurBackground) {
3142+
ContextScope scope;
3143+
auto context = scope.getContext();
3144+
EXPECT_TRUE(context != nullptr);
3145+
3146+
auto surface = Surface::Make(context, 200, 200);
3147+
auto displayList = std::make_unique<DisplayList>();
3148+
3149+
// Set background color on display list (which sets it on root layer)
3150+
auto backgroundColor = Color::FromRGBA(255, 0, 0, 128); // Semi-transparent red
3151+
displayList->setBackgroundColor(backgroundColor);
3152+
EXPECT_EQ(displayList->backgroundColor(), backgroundColor);
3153+
3154+
// Add a bottom layer to provide content that will be blurred
3155+
auto bottomLayer = ShapeLayer::Make();
3156+
Path bottomPath = {};
3157+
bottomPath.addRect(Rect::MakeXYWH(60.0f, 60.0f, 80.0f, 80.0f));
3158+
bottomLayer->setPath(bottomPath);
3159+
bottomLayer->setFillStyle(ShapeStyle::Make(Color::FromRGBA(0, 0, 255, 255))); // Blue background content
3160+
displayList->root()->addChild(bottomLayer);
3161+
3162+
// Add a shape layer with background blur to trigger the blurBackground code path
3163+
// Position it so part covers bottomLayer and part covers pure background
3164+
auto shapeLayer = ShapeLayer::Make();
3165+
Path path = {};
3166+
path.addRect(Rect::MakeXYWH(40.0f, 40.0f, 80.0f, 80.0f));
3167+
shapeLayer->setPath(path);
3168+
shapeLayer->setFillStyle(ShapeStyle::Make(Color::FromRGBA(255, 255, 255, 128))); // Semi-transparent white
3169+
3170+
// Add background blur style to trigger the blur background rendering
3171+
auto backgroundBlur = BackgroundBlurStyle::Make(10.0f, 10.0f);
3172+
shapeLayer->setLayerStyles({backgroundBlur});
3173+
3174+
displayList->root()->addChild(shapeLayer);
3175+
3176+
// Render the display list - this will internally create BackgroundContext and call
3177+
// RootLayer::drawLayer with args.blurBackground set, testing our new code path
3178+
displayList->render(surface.get());
3179+
3180+
// Compare with baseline to verify the background color is correctly drawn
3181+
// to both the main canvas and blur background canvas
3182+
EXPECT_TRUE(Baseline::Compare(surface, "LayerTest/RootLayerBackgroundColorWithBlurBackground"));
3183+
}
3184+
31403185
} // namespace tgfx

0 commit comments

Comments
 (0)