cc: The SolidColorLayer should report contentsOpaque() true when its color is opaque
This is required for the layer to occlude other things. Currently the layer never occludes anything. Tests: cc_unittests:SolidColorLayerImplTest.verifyOpaqueRect BUG=159745 R=jamesr Review URL: https://codereview.chromium.org/11360145 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@166690 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
@ -74,7 +74,7 @@ public:
|
||||
void setAnchorPointZ(float);
|
||||
float anchorPointZ() const { return m_anchorPointZ; }
|
||||
|
||||
void setBackgroundColor(SkColor);
|
||||
virtual void setBackgroundColor(SkColor);
|
||||
SkColor backgroundColor() const { return m_backgroundColor; }
|
||||
|
||||
// A layer's bounds are in logical, non-page-scaled pixels (however, the
|
||||
|
@ -29,4 +29,10 @@ SolidColorLayer::~SolidColorLayer()
|
||||
{
|
||||
}
|
||||
|
||||
void SolidColorLayer::setBackgroundColor(SkColor color)
|
||||
{
|
||||
setContentsOpaque(SkColorGetA(color) == 255);
|
||||
Layer::setBackgroundColor(color);
|
||||
}
|
||||
|
||||
} // namespace cc
|
||||
|
@ -19,6 +19,8 @@ public:
|
||||
|
||||
virtual scoped_ptr<LayerImpl> createLayerImpl() OVERRIDE;
|
||||
|
||||
virtual void setBackgroundColor(SkColor) OVERRIDE;
|
||||
|
||||
protected:
|
||||
SolidColorLayer();
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "cc/append_quads_data.h"
|
||||
#include "cc/single_thread_proxy.h"
|
||||
#include "cc/solid_color_draw_quad.h"
|
||||
#include "cc/solid_color_layer.h"
|
||||
#include "cc/test/layer_test_common.h"
|
||||
#include "cc/test/mock_quad_culler.h"
|
||||
#include "testing/gmock/include/gmock/gmock.h"
|
||||
@ -84,4 +85,60 @@ TEST(SolidColorLayerImplTest, verifyCorrectOpacityInQuad)
|
||||
EXPECT_EQ(opacity, SolidColorDrawQuad::materialCast(quadCuller.quadList()[0])->opacity());
|
||||
}
|
||||
|
||||
TEST(SolidColorLayerImplTest, verifyOpaqueRect)
|
||||
{
|
||||
scoped_refptr<SolidColorLayer> layer = SolidColorLayer::create();
|
||||
gfx::Size layerSize = gfx::Size(100, 100);
|
||||
gfx::Rect visibleContentRect = gfx::Rect(gfx::Point(), layerSize);
|
||||
|
||||
layer->setVisibleContentRect(visibleContentRect);
|
||||
layer->setBounds(layerSize);
|
||||
layer->createRenderSurface();
|
||||
layer->setRenderTarget(layer.get());
|
||||
|
||||
EXPECT_FALSE(layer->contentsOpaque());
|
||||
layer->setBackgroundColor(SkColorSetARGBInline(255, 10, 20, 30));
|
||||
EXPECT_TRUE(layer->contentsOpaque());
|
||||
|
||||
{
|
||||
scoped_ptr<SolidColorLayerImpl> layerImpl = SolidColorLayerImpl::create(layer->id());
|
||||
layer->pushPropertiesTo(layerImpl.get());
|
||||
|
||||
// The impl layer should call itself opaque as well.
|
||||
EXPECT_TRUE(layerImpl->contentsOpaque());
|
||||
|
||||
// Impl layer has 1 opacity, and the color is opaque, so the opaqueRect should be the full tile.
|
||||
layerImpl->setDrawOpacity(1);
|
||||
|
||||
MockQuadCuller quadCuller;
|
||||
AppendQuadsData data;
|
||||
layerImpl->appendQuads(quadCuller, data);
|
||||
|
||||
ASSERT_EQ(quadCuller.quadList().size(), 1U);
|
||||
EXPECT_EQ(visibleContentRect.ToString(), quadCuller.quadList()[0]->opaqueRect().ToString());
|
||||
}
|
||||
|
||||
EXPECT_TRUE(layer->contentsOpaque());
|
||||
layer->setBackgroundColor(SkColorSetARGBInline(254, 10, 20, 30));
|
||||
EXPECT_FALSE(layer->contentsOpaque());
|
||||
|
||||
{
|
||||
scoped_ptr<SolidColorLayerImpl> layerImpl = SolidColorLayerImpl::create(layer->id());
|
||||
layer->pushPropertiesTo(layerImpl.get());
|
||||
|
||||
// The impl layer should callnot itself opaque anymore.
|
||||
EXPECT_FALSE(layerImpl->contentsOpaque());
|
||||
|
||||
// Impl layer has 1 opacity, but the color is not opaque, so the opaqueRect should be empty.
|
||||
layerImpl->setDrawOpacity(1);
|
||||
|
||||
MockQuadCuller quadCuller;
|
||||
AppendQuadsData data;
|
||||
layerImpl->appendQuads(quadCuller, data);
|
||||
|
||||
ASSERT_EQ(quadCuller.quadList().size(), 1U);
|
||||
EXPECT_EQ(gfx::Rect().ToString(), quadCuller.quadList()[0]->opaqueRect().ToString());
|
||||
}
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
Reference in New Issue
Block a user