Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/layers/RootLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ bool RootLayer::drawLayer(const DrawArgs& args, Canvas* canvas, float alpha, Ble
auto color = _backgroundColor;
color.alpha = color.alpha * alpha;
canvas->drawColor(color, blendMode);
if (args.blurBackground) {
args.blurBackground->getCanvas()->drawColor(color, blendMode);
}
return Layer::drawLayer(args, canvas, alpha, blendMode, transform3D);
}

Expand Down
1 change: 1 addition & 0 deletions test/baseline/version.json
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@
"PassThoughAndNormal": "43cd416",
"PassThrough_Test": "7fa7fcb8",
"Preserve3DNestedLayers": "0b31d462",
"RootLayerBackgroundColorWithBlurBackground": "d15a4d35",
"ShapeStyleWithMatrix": "0cfb8996",
"StrokeOnTop_Off": "80c523ee",
"StrokeOnTop_On": "80c523ee",
Expand Down
45 changes: 45 additions & 0 deletions test/src/LayerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "layers/OpaqueContext.h"
#include "layers/DrawArgs.h"
#include "layers/RootLayer.h"
#include "layers/BackgroundContext.h"
#include "layers/SubtreeCache.h"
#include "layers/TileCache.h"
#include "layers/compositing3d/Layer3DContext.h"
Expand Down Expand Up @@ -3137,4 +3138,48 @@ TGFX_TEST(LayerTest, Contour3DWithDropShadow) {
EXPECT_TRUE(Baseline::Compare(surface, "LayerTest/Contour3DWithDropShadow"));
}

TGFX_TEST(LayerTest, RootLayerBackgroundColorWithBlurBackground) {
ContextScope scope;
auto context = scope.getContext();
EXPECT_TRUE(context != nullptr);

auto surface = Surface::Make(context, 200, 200);
auto displayList = std::make_unique<DisplayList>();

// Set background color on display list (which sets it on root layer)
auto backgroundColor = Color::FromRGBA(255, 0, 0, 128); // Semi-transparent red
displayList->setBackgroundColor(backgroundColor);
EXPECT_EQ(displayList->backgroundColor(), backgroundColor);

// Add a bottom layer to provide content that will be blurred
auto bottomLayer = ShapeLayer::Make();
Path bottomPath = {};
bottomPath.addRect(Rect::MakeXYWH(60.0f, 60.0f, 80.0f, 80.0f));
bottomLayer->setPath(bottomPath);
bottomLayer->setFillStyle(ShapeStyle::Make(Color::FromRGBA(0, 0, 255, 255))); // Blue background content
displayList->root()->addChild(bottomLayer);

// Add a shape layer with background blur to trigger the blurBackground code path
// Position it so part covers bottomLayer and part covers pure background
auto shapeLayer = ShapeLayer::Make();
Path path = {};
path.addRect(Rect::MakeXYWH(40.0f, 40.0f, 80.0f, 80.0f));
shapeLayer->setPath(path);
shapeLayer->setFillStyle(ShapeStyle::Make(Color::FromRGBA(255, 255, 255, 128))); // Semi-transparent white

// Add background blur style to trigger the blur background rendering
auto backgroundBlur = BackgroundBlurStyle::Make(10.0f, 10.0f);
shapeLayer->setLayerStyles({backgroundBlur});

displayList->root()->addChild(shapeLayer);

// Render the display list - this will internally create BackgroundContext and call
// RootLayer::drawLayer with args.blurBackground set, testing our new code path
displayList->render(surface.get());

// Compare with baseline to verify the background color is correctly drawn
// to both the main canvas and blur background canvas
EXPECT_TRUE(Baseline::Compare(surface, "LayerTest/RootLayerBackgroundColorWithBlurBackground"));
}

} // namespace tgfx