Skip to content

Commit

Permalink
Consider background-color opacity for TextureLayer opaque region.
Browse files Browse the repository at this point in the history
TextureLayer draws both - texture and background-color.
So take background-color opacity into account when calculating
opaque region.

BUG=236982

Review URL: https://chromiumcodereview.appspot.com/21084005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@214682 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
alokp@chromium.org committed Jul 31, 2013
1 parent a24b35b commit 1c10e23
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 1 deletion.
10 changes: 10 additions & 0 deletions cc/layers/texture_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,16 @@ void TextureLayer::PushPropertiesTo(LayerImpl* layer) {
content_committed_ = DrawsContent();
}

Region TextureLayer::VisibleContentOpaqueRegion() const {
if (contents_opaque())
return visible_content_rect();

if (blend_background_color_ && (SkColorGetA(background_color()) == 0xFF))
return visible_content_rect();

return Region();
}

bool TextureLayer::BlocksPendingCommit() const {
// Double-buffered texture layers need to be blocked until they can be made
// triple-buffered. Single-buffered layers already prevent draws, so
Expand Down
1 change: 1 addition & 0 deletions cc/layers/texture_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class CC_EXPORT TextureLayer : public Layer {
virtual bool Update(ResourceUpdateQueue* queue,
const OcclusionTracker* occlusion) OVERRIDE;
virtual void PushPropertiesTo(LayerImpl* layer) OVERRIDE;
virtual Region VisibleContentOpaqueRegion() const OVERRIDE;
virtual bool BlocksPendingCommit() const OVERRIDE;

virtual bool CanClipSelf() const OVERRIDE;
Expand Down
10 changes: 10 additions & 0 deletions cc/layers/texture_layer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,16 @@ void TextureLayerImpl::DidDraw(ResourceProvider* resource_provider) {
external_texture_resource_ = 0;
}

Region TextureLayerImpl::VisibleContentOpaqueRegion() const {
if (contents_opaque())
return visible_content_rect();

if (blend_background_color_ && (SkColorGetA(background_color()) == 0xFF))
return visible_content_rect();

return Region();
}

void TextureLayerImpl::DidLoseOutputSurface() {
if (external_texture_resource_ && !uses_mailbox_) {
ResourceProvider* resource_provider =
Expand Down
2 changes: 1 addition & 1 deletion cc/layers/texture_layer_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class CC_EXPORT TextureLayerImpl : public LayerImpl {
virtual void AppendQuads(QuadSink* quad_sink,
AppendQuadsData* append_quads_data) OVERRIDE;
virtual void DidDraw(ResourceProvider* resource_provider) OVERRIDE;

virtual Region VisibleContentOpaqueRegion() const OVERRIDE;
virtual void DidLoseOutputSurface() OVERRIDE;

unsigned texture_id() const { return texture_id_; }
Expand Down
27 changes: 27 additions & 0 deletions cc/layers/texture_layer_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,33 @@ TEST_F(TextureLayerTest, CheckPropertyChangeCausesCorrectBehavior) {
EXPECT_CALL(*layer_tree_host_, AcquireLayerTextures()).Times(AnyNumber());
}

TEST_F(TextureLayerTest, VisibleContentOpaqueRegion) {
const gfx::Size layer_bounds(100, 100);
const gfx::Rect layer_rect(layer_bounds);
const Region layer_region(layer_rect);

scoped_refptr<TextureLayer> layer = TextureLayer::Create(NULL);
layer->SetBounds(layer_bounds);
layer->draw_properties().visible_content_rect = layer_rect;
layer->SetBlendBackgroundColor(true);

// Verify initial conditions.
EXPECT_FALSE(layer->contents_opaque());
EXPECT_EQ(0u, layer->background_color());
EXPECT_EQ(Region().ToString(),
layer->VisibleContentOpaqueRegion().ToString());

// Opaque background.
layer->SetBackgroundColor(SK_ColorWHITE);
EXPECT_EQ(layer_region.ToString(),
layer->VisibleContentOpaqueRegion().ToString());

// Transparent background.
layer->SetBackgroundColor(SkColorSetARGB(100, 255, 255, 255));
EXPECT_EQ(Region().ToString(),
layer->VisibleContentOpaqueRegion().ToString());
}

class FakeTextureLayerClient : public TextureLayerClient {
public:
FakeTextureLayerClient() : context_(TestWebGraphicsContext3D::Create()) {}
Expand Down

0 comments on commit 1c10e23

Please sign in to comment.