1 // Copyright 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 #include "cc/texture_layer.h"
9 #include "third_party/khronos/GLES2/gl2.h"
10 #include "cc/layer_tree_host.h"
11 #include "cc/texture_layer_client.h"
12 #include "cc/texture_layer_impl.h"
16 scoped_refptr
<TextureLayer
> TextureLayer::create(TextureLayerClient
* client
)
18 return scoped_refptr
<TextureLayer
>(new TextureLayer(client
));
21 TextureLayer::TextureLayer(TextureLayerClient
* client
)
25 , m_uvRect(0, 0, 1, 1)
26 , m_premultipliedAlpha(true)
27 , m_rateLimitContext(false)
28 , m_contextLost(false)
30 , m_contentCommitted(false)
34 TextureLayer::~TextureLayer()
36 if (layerTreeHost()) {
38 layerTreeHost()->acquireLayerTextures();
39 if (m_rateLimitContext
&& m_client
)
40 layerTreeHost()->stopRateLimiter(m_client
->context());
44 scoped_ptr
<LayerImpl
> TextureLayer::createLayerImpl()
46 return TextureLayerImpl::create(m_layerId
).PassAs
<LayerImpl
>();
49 void TextureLayer::setFlipped(bool flipped
)
55 void TextureLayer::setUVRect(const gfx::RectF
& rect
)
61 void TextureLayer::setPremultipliedAlpha(bool premultipliedAlpha
)
63 m_premultipliedAlpha
= premultipliedAlpha
;
67 void TextureLayer::setRateLimitContext(bool rateLimit
)
69 if (!rateLimit
&& m_rateLimitContext
&& m_client
&& layerTreeHost())
70 layerTreeHost()->stopRateLimiter(m_client
->context());
72 m_rateLimitContext
= rateLimit
;
75 void TextureLayer::setTextureId(unsigned id
)
77 if (m_textureId
== id
)
79 if (m_textureId
&& layerTreeHost())
80 layerTreeHost()->acquireLayerTextures();
85 void TextureLayer::willModifyTexture()
87 if (layerTreeHost() && (drawsContent() || m_contentCommitted
)) {
88 layerTreeHost()->acquireLayerTextures();
89 m_contentCommitted
= false;
93 void TextureLayer::setNeedsDisplayRect(const gfx::RectF
& dirtyRect
)
95 Layer::setNeedsDisplayRect(dirtyRect
);
97 if (m_rateLimitContext
&& m_client
&& layerTreeHost() && drawsContent())
98 layerTreeHost()->startRateLimiter(m_client
->context());
101 void TextureLayer::setLayerTreeHost(LayerTreeHost
* host
)
103 if (m_textureId
&& layerTreeHost() && host
!= layerTreeHost())
104 layerTreeHost()->acquireLayerTextures();
105 Layer::setLayerTreeHost(host
);
108 bool TextureLayer::drawsContent() const
110 return (m_client
|| m_textureId
) && !m_contextLost
&& Layer::drawsContent();
113 void TextureLayer::update(ResourceUpdateQueue
& queue
, const OcclusionTracker
*, RenderingStats
&)
116 m_textureId
= m_client
->prepareTexture(queue
);
117 m_contextLost
= m_client
->context()->getGraphicsResetStatusARB() != GL_NO_ERROR
;
120 m_needsDisplay
= false;
123 void TextureLayer::pushPropertiesTo(LayerImpl
* layer
)
125 Layer::pushPropertiesTo(layer
);
127 TextureLayerImpl
* textureLayer
= static_cast<TextureLayerImpl
*>(layer
);
128 textureLayer
->setFlipped(m_flipped
);
129 textureLayer
->setUVRect(m_uvRect
);
130 textureLayer
->setPremultipliedAlpha(m_premultipliedAlpha
);
131 textureLayer
->setTextureId(m_textureId
);
132 m_contentCommitted
= drawsContent();