2 * Copyright (C) 2010 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #if USE(ACCELERATED_COMPOSITING)
35 #include "WebGLLayerChromium.h"
37 #include "DrawingBuffer.h"
38 #include "Extensions3DChromium.h"
39 #include "GraphicsContext3D.h"
40 #include "TextureCopier.h"
41 #include "TraceEvent.h"
42 #include "cc/CCLayerTreeHost.h"
43 #include "cc/CCTextureLayerImpl.h"
44 #include "cc/CCTextureUpdater.h"
48 PassRefPtr<WebGLLayerChromium> WebGLLayerChromium::create()
50 return adoptRef(new WebGLLayerChromium());
53 WebGLLayerChromium::WebGLLayerChromium()
54 : CanvasLayerChromium()
56 , m_premultipliedAlpha(true)
57 , m_contextLost(false)
63 WebGLLayerChromium::~WebGLLayerChromium()
65 if (context() && layerTreeHost())
66 layerTreeHost()->stopRateLimiter(context());
69 bool WebGLLayerChromium::drawsContent() const
71 return LayerChromium::drawsContent() && !m_contextLost;
74 void WebGLLayerChromium::update(CCTextureUpdater& updater, const CCOcclusionTracker*)
76 if (!drawsContent() || !m_needsDisplay || !m_drawingBuffer)
79 m_drawingBuffer->prepareBackBuffer();
82 context()->markLayerComposited();
83 m_needsDisplay = false;
84 m_contextLost = context()->getExtensions()->getGraphicsResetStatusARB() != GraphicsContext3D::NO_ERROR;
86 m_textureId = m_drawingBuffer->frontColorBuffer();
87 if (m_drawingBuffer->requiresCopyFromBackToFrontBuffer())
88 updater.appendCopy(m_drawingBuffer->colorBuffer(), m_textureId, bounds());
90 m_drawingBuffer->restoreFramebufferBinding();
93 void WebGLLayerChromium::pushPropertiesTo(CCLayerImpl* layer)
95 CanvasLayerChromium::pushPropertiesTo(layer);
97 CCTextureLayerImpl* textureLayer = static_cast<CCTextureLayerImpl*>(layer);
98 textureLayer->setTextureId(m_textureId);
99 textureLayer->setHasAlpha(m_hasAlpha);
100 textureLayer->setPremultipliedAlpha(m_premultipliedAlpha);
103 void WebGLLayerChromium::setNeedsDisplayRect(const FloatRect& dirtyRect)
105 LayerChromium::setNeedsDisplayRect(dirtyRect);
107 // If WebGL commands are issued outside of a the animation callbacks, then use
108 // call rateLimitOffscreenContextCHROMIUM() to keep the context from getting too far ahead.
110 layerTreeHost()->startRateLimiter(context());
113 void WebGLLayerChromium::setDrawingBuffer(DrawingBuffer* drawingBuffer)
115 bool drawingBufferChanged = (m_drawingBuffer != drawingBuffer);
117 // The GraphicsContext3D used by the layer is the context associated with
118 // the drawing buffer. If the drawing buffer is changing, make sure
119 // to stop the rate limiter on the old context, not the new context from the
120 // new drawing buffer.
121 GraphicsContext3D* context3D = context();
122 if (layerTreeHost() && drawingBufferChanged && context3D)
123 layerTreeHost()->stopRateLimiter(context3D);
125 m_drawingBuffer = drawingBuffer;
126 if (!m_drawingBuffer)
129 GraphicsContext3D::Attributes attributes = context()->getContextAttributes();
130 m_hasAlpha = attributes.alpha;
131 m_premultipliedAlpha = attributes.premultipliedAlpha;
132 m_contextLost = context()->getExtensions()->getGraphicsResetStatusARB() != GraphicsContext3D::NO_ERROR;
135 GraphicsContext3D* WebGLLayerChromium::context() const
138 return drawingBuffer()->graphicsContext3D().get();
145 #endif // USE(ACCELERATED_COMPOSITING)