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 #if USE(ACCELERATED_COMPOSITING)
9 #include "TextureLayerChromium.h"
11 #include "CCLayerTreeHost.h"
12 #include "CCTextureLayerImpl.h"
13 #include "GraphicsContext3D.h"
14 #include "TextureLayerChromiumClient.h"
15 #include <public/WebGraphicsContext3D.h>
19 scoped_refptr
<TextureLayerChromium
> TextureLayerChromium::create(TextureLayerChromiumClient
* client
)
21 return scoped_refptr
<TextureLayerChromium
>(new TextureLayerChromium(client
));
24 TextureLayerChromium::TextureLayerChromium(TextureLayerChromiumClient
* client
)
28 , m_uvRect(0, 0, 1, 1)
29 , m_premultipliedAlpha(true)
30 , m_rateLimitContext(false)
31 , m_contextLost(false)
36 TextureLayerChromium::~TextureLayerChromium()
38 if (layerTreeHost()) {
40 layerTreeHost()->acquireLayerTextures();
41 if (m_rateLimitContext
&& m_client
)
42 layerTreeHost()->stopRateLimiter(m_client
->context());
46 PassOwnPtr
<CCLayerImpl
> TextureLayerChromium::createCCLayerImpl()
48 return CCTextureLayerImpl::create(m_layerId
);
51 void TextureLayerChromium::setFlipped(bool flipped
)
57 void TextureLayerChromium::setUVRect(const FloatRect
& rect
)
63 void TextureLayerChromium::setPremultipliedAlpha(bool premultipliedAlpha
)
65 m_premultipliedAlpha
= premultipliedAlpha
;
69 void TextureLayerChromium::setRateLimitContext(bool rateLimit
)
71 if (!rateLimit
&& m_rateLimitContext
&& m_client
&& layerTreeHost())
72 layerTreeHost()->stopRateLimiter(m_client
->context());
74 m_rateLimitContext
= rateLimit
;
77 void TextureLayerChromium::setTextureId(unsigned id
)
79 if (m_textureId
== id
)
81 if (m_textureId
&& layerTreeHost())
82 layerTreeHost()->acquireLayerTextures();
87 void TextureLayerChromium::willModifyTexture()
90 layerTreeHost()->acquireLayerTextures();
93 void TextureLayerChromium::setNeedsDisplayRect(const FloatRect
& dirtyRect
)
95 LayerChromium::setNeedsDisplayRect(dirtyRect
);
97 if (m_rateLimitContext
&& m_client
&& layerTreeHost())
98 layerTreeHost()->startRateLimiter(m_client
->context());
101 void TextureLayerChromium::setLayerTreeHost(CCLayerTreeHost
* host
)
103 if (m_textureId
&& layerTreeHost() && host
!= layerTreeHost())
104 layerTreeHost()->acquireLayerTextures();
105 LayerChromium::setLayerTreeHost(host
);
108 bool TextureLayerChromium::drawsContent() const
110 return (m_client
|| m_textureId
) && !m_contextLost
&& LayerChromium::drawsContent();
113 void TextureLayerChromium::update(CCTextureUpdateQueue
& queue
, const CCOcclusionTracker
*, CCRenderingStats
&)
116 m_textureId
= m_client
->prepareTexture(queue
);
117 m_contextLost
= m_client
->context()->getGraphicsResetStatusARB() != GraphicsContext3D::NO_ERROR
;
120 m_needsDisplay
= false;
123 void TextureLayerChromium::pushPropertiesTo(CCLayerImpl
* layer
)
125 LayerChromium::pushPropertiesTo(layer
);
127 CCTextureLayerImpl
* textureLayer
= static_cast<CCTextureLayerImpl
*>(layer
);
128 textureLayer
->setFlipped(m_flipped
);
129 textureLayer
->setUVRect(m_uvRect
);
130 textureLayer
->setPremultipliedAlpha(m_premultipliedAlpha
);
131 textureLayer
->setTextureId(m_textureId
);
135 #endif // USE(ACCELERATED_COMPOSITING)