|
26 | 26 | #include "layers/OpaqueContext.h" |
27 | 27 | #include "layers/DrawArgs.h" |
28 | 28 | #include "layers/RootLayer.h" |
| 29 | +#include "layers/BackgroundContext.h" |
29 | 30 | #include "layers/SubtreeCache.h" |
30 | 31 | #include "layers/TileCache.h" |
31 | 32 | #include "layers/compositing3d/Layer3DContext.h" |
@@ -3137,4 +3138,48 @@ TGFX_TEST(LayerTest, Contour3DWithDropShadow) { |
3137 | 3138 | EXPECT_TRUE(Baseline::Compare(surface, "LayerTest/Contour3DWithDropShadow")); |
3138 | 3139 | } |
3139 | 3140 |
|
| 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 | + |
3140 | 3185 | } // namespace tgfx |
0 commit comments