blob: c1f561eeb82a6176a3ab22981a4b9468db137b95 [file] [log] [blame]
[email protected]94f206c12012-08-25 00:09:141// 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.
4
5#include "config.h"
6
7#if USE(ACCELERATED_COMPOSITING)
8
9#include "TextureLayerChromium.h"
10
11#include "CCLayerTreeHost.h"
12#include "CCTextureLayerImpl.h"
[email protected]be3aa6f2012-08-31 23:55:4013#include "TextureLayerChromiumClient.h"
[email protected]94f206c12012-08-25 00:09:1414#include <public/WebGraphicsContext3D.h>
15
[email protected]9c88e562012-09-14 22:21:3016namespace cc {
[email protected]94f206c12012-08-25 00:09:1417
18PassRefPtr<TextureLayerChromium> TextureLayerChromium::create(TextureLayerChromiumClient* client)
19{
20 return adoptRef(new TextureLayerChromium(client));
21}
22
23TextureLayerChromium::TextureLayerChromium(TextureLayerChromiumClient* client)
24 : LayerChromium()
25 , m_client(client)
26 , m_flipped(true)
27 , m_uvRect(0, 0, 1, 1)
28 , m_premultipliedAlpha(true)
29 , m_rateLimitContext(false)
30 , m_contextLost(false)
31 , m_textureId(0)
32{
33}
34
35TextureLayerChromium::~TextureLayerChromium()
36{
37 if (layerTreeHost()) {
38 if (m_textureId)
39 layerTreeHost()->acquireLayerTextures();
40 if (m_rateLimitContext && m_client)
41 layerTreeHost()->stopRateLimiter(m_client->context());
42 }
43}
44
45PassOwnPtr<CCLayerImpl> TextureLayerChromium::createCCLayerImpl()
46{
47 return CCTextureLayerImpl::create(m_layerId);
48}
49
50void TextureLayerChromium::setFlipped(bool flipped)
51{
52 m_flipped = flipped;
53 setNeedsCommit();
54}
55
56void TextureLayerChromium::setUVRect(const FloatRect& rect)
57{
58 m_uvRect = rect;
59 setNeedsCommit();
60}
61
62void TextureLayerChromium::setPremultipliedAlpha(bool premultipliedAlpha)
63{
64 m_premultipliedAlpha = premultipliedAlpha;
65 setNeedsCommit();
66}
67
68void TextureLayerChromium::setRateLimitContext(bool rateLimit)
69{
70 if (!rateLimit && m_rateLimitContext && m_client && layerTreeHost())
71 layerTreeHost()->stopRateLimiter(m_client->context());
72
73 m_rateLimitContext = rateLimit;
74}
75
76void TextureLayerChromium::setTextureId(unsigned id)
77{
78 if (m_textureId == id)
79 return;
80 if (m_textureId && layerTreeHost())
81 layerTreeHost()->acquireLayerTextures();
82 m_textureId = id;
83 setNeedsCommit();
84}
85
86void TextureLayerChromium::willModifyTexture()
87{
88 if (layerTreeHost())
89 layerTreeHost()->acquireLayerTextures();
90}
91
92void TextureLayerChromium::setNeedsDisplayRect(const FloatRect& dirtyRect)
93{
94 LayerChromium::setNeedsDisplayRect(dirtyRect);
95
96 if (m_rateLimitContext && m_client && layerTreeHost())
97 layerTreeHost()->startRateLimiter(m_client->context());
98}
99
100void TextureLayerChromium::setLayerTreeHost(CCLayerTreeHost* host)
101{
102 if (m_textureId && layerTreeHost() && host != layerTreeHost())
103 layerTreeHost()->acquireLayerTextures();
104 LayerChromium::setLayerTreeHost(host);
105}
106
107bool TextureLayerChromium::drawsContent() const
108{
109 return (m_client || m_textureId) && !m_contextLost && LayerChromium::drawsContent();
110}
111
112void TextureLayerChromium::update(CCTextureUpdateQueue& queue, const CCOcclusionTracker*, CCRenderingStats&)
113{
114 if (m_client) {
115 m_textureId = m_client->prepareTexture(queue);
116 m_contextLost = m_client->context()->getGraphicsResetStatusARB() != GraphicsContext3D::NO_ERROR;
117 }
118
119 m_needsDisplay = false;
120}
121
122void TextureLayerChromium::pushPropertiesTo(CCLayerImpl* layer)
123{
124 LayerChromium::pushPropertiesTo(layer);
125
126 CCTextureLayerImpl* textureLayer = static_cast<CCTextureLayerImpl*>(layer);
127 textureLayer->setFlipped(m_flipped);
128 textureLayer->setUVRect(m_uvRect);
129 textureLayer->setPremultipliedAlpha(m_premultipliedAlpha);
130 textureLayer->setTextureId(m_textureId);
131}
132
133}
134#endif // USE(ACCELERATED_COMPOSITING)