[chromium] Separate IOSurface layer type from texture layers
[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 {
53 }
54
55 TextureLayerChromium::~TextureLayerChromium()
56 {
57     if (m_rateLimitContext && m_client && layerTreeHost())
58         layerTreeHost()->stopRateLimiter(m_client->context());
59 }
60
61 PassOwnPtr<CCLayerImpl> TextureLayerChromium::createCCLayerImpl()
62 {
63     return CCTextureLayerImpl::create(m_layerId);
64 }
65
66 void TextureLayerChromium::setFlipped(bool flipped)
67 {
68     m_flipped = flipped;
69     setNeedsCommit();
70 }
71
72 void TextureLayerChromium::setUVRect(const FloatRect& rect)
73 {
74     m_uvRect = rect;
75     setNeedsCommit();
76 }
77
78 void TextureLayerChromium::setPremultipliedAlpha(bool premultipliedAlpha)
79 {
80     m_premultipliedAlpha = premultipliedAlpha;
81     setNeedsCommit();
82 }
83
84 void TextureLayerChromium::setRateLimitContext(bool rateLimit)
85 {
86     if (!rateLimit && m_rateLimitContext && m_client && layerTreeHost())
87         layerTreeHost()->stopRateLimiter(m_client->context());
88
89     m_rateLimitContext = rateLimit;
90 }
91
92 void TextureLayerChromium::setTextureId(unsigned id)
93 {
94     m_textureId = id;
95     setNeedsCommit();
96 }
97
98 void TextureLayerChromium::setNeedsDisplayRect(const FloatRect& dirtyRect)
99 {
100     LayerChromium::setNeedsDisplayRect(dirtyRect);
101
102     if (m_rateLimitContext && m_client && layerTreeHost())
103         layerTreeHost()->startRateLimiter(m_client->context());
104 }
105
106 bool TextureLayerChromium::drawsContent() const
107 {
108     return (m_client || m_textureId) && !m_contextLost && LayerChromium::drawsContent();
109 }
110
111 void TextureLayerChromium::update(CCTextureUpdater& updater, const CCOcclusionTracker*)
112 {
113     if (m_client) {
114         m_textureId = m_client->prepareTexture(updater);
115         m_contextLost = m_client->context()->getExtensions()->getGraphicsResetStatusARB() != GraphicsContext3D::NO_ERROR;
116     }
117
118     m_needsDisplay = false;
119 }
120
121 void TextureLayerChromium::pushPropertiesTo(CCLayerImpl* layer)
122 {
123     LayerChromium::pushPropertiesTo(layer);
124
125     CCTextureLayerImpl* textureLayer = static_cast<CCTextureLayerImpl*>(layer);
126     textureLayer->setFlipped(m_flipped);
127     textureLayer->setUVRect(m_uvRect);
128     textureLayer->setPremultipliedAlpha(m_premultipliedAlpha);
129     textureLayer->setTextureId(m_textureId);
130 }
131
132 }
133 #endif // USE(ACCELERATED_COMPOSITING)