[chromium] Use TextureLayerChromium for WebGL content instead of a dedicated layer...
[WebKit.git] / Source / WebCore / platform / graphics / chromium / TextureLayerChromium.cpp
1 /*
2  * Copyright (C) 2010 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * 1.  Redistributions of source code must retain the above copyright
9  *     notice, this list of conditions and the following disclaimer.
10  * 2.  Redistributions in binary form must reproduce the above copyright
11  *     notice, this list of conditions and the following disclaimer in the
12  *     documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
15  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #include "config.h"
27
28 #if USE(ACCELERATED_COMPOSITING)
29
30 #include "TextureLayerChromium.h"
31
32 #include "Extensions3D.h"
33 #include "cc/CCLayerTreeHost.h"
34 #include "cc/CCTextureLayerImpl.h"
35
36 namespace WebCore {
37
38 PassRefPtr<TextureLayerChromium> TextureLayerChromium::create(TextureLayerChromiumClient* client)
39 {
40     return adoptRef(new TextureLayerChromium(client));
41 }
42
43 TextureLayerChromium::TextureLayerChromium(TextureLayerChromiumClient* client)
44     : LayerChromium()
45     , m_client(client)
46     , m_flipped(true)
47     , m_uvRect(0, 0, 1, 1)
48     , m_premultipliedAlpha(true)
49     , m_rateLimitContext(false)
50     , m_contextLost(false)
51     , m_textureId(0)
52     , m_ioSurfaceId(0)
53 {
54 }
55
56 TextureLayerChromium::~TextureLayerChromium()
57 {
58     if (m_rateLimitContext && m_client && layerTreeHost())
59         layerTreeHost()->stopRateLimiter(m_client->context());
60 }
61
62 PassOwnPtr<CCLayerImpl> TextureLayerChromium::createCCLayerImpl()
63 {
64     return CCTextureLayerImpl::create(m_layerId);
65 }
66
67 void TextureLayerChromium::setFlipped(bool flipped)
68 {
69     m_flipped = flipped;
70     setNeedsCommit();
71 }
72
73 void TextureLayerChromium::setUVRect(const FloatRect& rect)
74 {
75     m_uvRect = rect;
76     setNeedsCommit();
77 }
78
79 void TextureLayerChromium::setPremultipliedAlpha(bool premultipliedAlpha)
80 {
81     m_premultipliedAlpha = premultipliedAlpha;
82     setNeedsCommit();
83 }
84
85 void TextureLayerChromium::setRateLimitContext(bool rateLimit)
86 {
87     if (!rateLimit && m_rateLimitContext && m_client && layerTreeHost())
88         layerTreeHost()->stopRateLimiter(m_client->context());
89
90     m_rateLimitContext = rateLimit;
91 }
92
93 void TextureLayerChromium::setTextureId(unsigned id)
94 {
95     m_textureId = id;
96     setNeedsCommit();
97 }
98
99 void TextureLayerChromium::setIOSurfaceProperties(int width, int height, uint32_t ioSurfaceId)
100 {
101     m_ioSurfaceSize = IntSize(width, height);
102     m_ioSurfaceId = ioSurfaceId;
103     setNeedsCommit();
104 }
105
106 void TextureLayerChromium::setNeedsDisplayRect(const FloatRect& dirtyRect)
107 {
108     LayerChromium::setNeedsDisplayRect(dirtyRect);
109
110     if (m_rateLimitContext && m_client && layerTreeHost())
111         layerTreeHost()->startRateLimiter(m_client->context());
112 }
113
114 bool TextureLayerChromium::drawsContent() const
115 {
116     return (m_client || m_textureId || m_ioSurfaceId) && !m_contextLost && LayerChromium::drawsContent();
117 }
118
119 void TextureLayerChromium::update(CCTextureUpdater& updater, const CCOcclusionTracker*)
120 {
121     if (m_client) {
122         m_textureId = m_client->prepareTexture(updater);
123         m_contextLost = m_client->context()->getExtensions()->getGraphicsResetStatusARB() != GraphicsContext3D::NO_ERROR;
124     }
125
126     m_needsDisplay = false;
127 }
128
129 void TextureLayerChromium::pushPropertiesTo(CCLayerImpl* layer)
130 {
131     LayerChromium::pushPropertiesTo(layer);
132
133     CCTextureLayerImpl* textureLayer = static_cast<CCTextureLayerImpl*>(layer);
134     textureLayer->setFlipped(m_flipped);
135     textureLayer->setUVRect(m_uvRect);
136     textureLayer->setPremultipliedAlpha(m_premultipliedAlpha);
137     textureLayer->setTextureId(m_textureId);
138     textureLayer->setIOSurfaceProperties(m_ioSurfaceSize, m_ioSurfaceId);
139 }
140
141 }
142 #endif // USE(ACCELERATED_COMPOSITING)