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.
34 #if USE(ACCELERATED_COMPOSITING)
35 #include "LayerRendererChromium.h"
37 #include "Canvas2DLayerChromium.h"
38 #include "Extensions3DChromium.h"
39 #include "FloatQuad.h"
40 #include "GeometryBinding.h"
41 #include "GraphicsContext3D.h"
42 #include "LayerChromium.h"
43 #include "LayerPainterChromium.h"
44 #include "ManagedTexture.h"
45 #include "LayerTextureUpdaterCanvas.h"
46 #include "NonCompositedContentHost.h"
47 #include "NotImplemented.h"
48 #include "PlatformColor.h"
49 #include "RenderSurfaceChromium.h"
50 #include "TextStream.h"
51 #include "TextureManager.h"
52 #include "TreeSynchronizer.h"
53 #include "TraceEvent.h"
54 #include "WebGLLayerChromium.h"
55 #include "cc/CCLayerImpl.h"
56 #include "cc/CCLayerTreeHostCommon.h"
57 #include "cc/CCMainThreadTask.h"
59 #include "Extensions3D.h"
60 #include "GrContext.h"
61 #include "NativeImageSkia.h"
62 #include "PlatformContextSkia.h"
64 #include <CoreGraphics/CGBitmapContext.h>
66 #include <wtf/CurrentTime.h>
67 #include <wtf/MainThread.h>
75 static TransformationMatrix orthoMatrix(float left, float right, float bottom, float top)
77 float deltaX = right - left;
78 float deltaY = top - bottom;
79 TransformationMatrix ortho;
80 if (!deltaX || !deltaY)
82 ortho.setM11(2.0f / deltaX);
83 ortho.setM41(-(right + left) / deltaX);
84 ortho.setM22(2.0f / deltaY);
85 ortho.setM42(-(top + bottom) / deltaY);
87 // Z component of vertices is always set to zero as we don't use the depth buffer
94 static TransformationMatrix screenMatrix(int x, int y, int width, int height)
96 TransformationMatrix screen;
99 screen.translate3d(x, y, 0);
100 screen.scale3d(width, height, 0);
102 // Map x, y and z to unit square.
103 screen.translate3d(0.5, 0.5, 0.5);
104 screen.scale3d(0.5, 0.5, 0.5);
110 bool contextSupportsAcceleratedPainting(GraphicsContext3D* context)
112 WebCore::Extensions3D* extensions = context->getExtensions();
113 if (extensions->supports("GL_EXT_texture_format_BGRA8888"))
114 extensions->ensureEnabled("GL_EXT_texture_format_BGRA8888");
118 if (extensions->supports("GL_EXT_read_format_bgra"))
119 extensions->ensureEnabled("GL_EXT_read_format_bgra");
123 if (!context->grContext())
130 } // anonymous namespace
132 PassOwnPtr<LayerRendererChromium> LayerRendererChromium::create(CCLayerTreeHostImpl* owner, PassRefPtr<GraphicsContext3D> context)
135 if (owner->settings().acceleratePainting && !contextSupportsAcceleratedPainting(context.get()))
138 OwnPtr<LayerRendererChromium> layerRenderer(adoptPtr(new LayerRendererChromium(owner, context)));
139 if (!layerRenderer->initialize())
142 return layerRenderer.release();
145 LayerRendererChromium::LayerRendererChromium(CCLayerTreeHostImpl* owner,
146 PassRefPtr<GraphicsContext3D> context)
148 , m_currentRenderSurface(0)
149 , m_offscreenFramebufferId(0)
150 , m_zoomAnimatorScale(1)
152 , m_defaultRenderSurface(0)
153 , m_sharedGeometryQuad(FloatRect(-0.5f, -0.5f, 1.0f, 1.0f))
157 bool LayerRendererChromium::initialize()
159 m_context->makeContextCurrent();
160 if (settings().acceleratePainting) {
161 m_capabilities.usingAcceleratedPainting = true;
164 WebCore::Extensions3D* extensions = m_context->getExtensions();
165 m_capabilities.usingMapSub = extensions->supports("GL_CHROMIUM_map_sub");
166 if (m_capabilities.usingMapSub)
167 extensions->ensureEnabled("GL_CHROMIUM_map_sub");
169 GLC(m_context.get(), m_context->getIntegerv(GraphicsContext3D::MAX_TEXTURE_SIZE, &m_capabilities.maxTextureSize));
170 m_capabilities.bestTextureFormat = PlatformColor::bestTextureFormat(m_context.get());
172 if (!initializeSharedObjects())
175 m_headsUpDisplay = CCHeadsUpDisplay::create(this);
177 // Make sure the viewport and context gets initialized, even if it is to zero.
182 LayerRendererChromium::~LayerRendererChromium()
184 m_headsUpDisplay.clear(); // Explicitly destroy the HUD before the TextureManager dies.
185 cleanupSharedObjects();
188 void LayerRendererChromium::clearRenderSurfacesOnCCLayerImplRecursive(CCLayerImpl* layer)
190 for (size_t i = 0; i < layer->children().size(); ++i)
191 clearRenderSurfacesOnCCLayerImplRecursive(layer->children()[i].get());
192 layer->clearRenderSurface();
195 void LayerRendererChromium::close()
198 clearRenderSurfacesOnCCLayerImplRecursive(rootLayer());
201 GraphicsContext3D* LayerRendererChromium::context()
203 return m_context.get();
206 void LayerRendererChromium::debugGLCall(GraphicsContext3D* context, const char* command, const char* file, int line)
208 unsigned long error = context->getError();
209 if (error != GraphicsContext3D::NO_ERROR)
210 LOG_ERROR("GL command failed: File: %s\n\tLine %d\n\tcommand: %s, error %x\n", file, line, command, static_cast<int>(error));
213 void LayerRendererChromium::releaseRenderSurfaceTextures()
215 m_renderSurfaceTextureManager->evictAndDeleteAllTextures(m_context.get());
218 void LayerRendererChromium::viewportChanged()
221 m_context->reshape(std::max(1, viewportWidth()), std::max(1, viewportHeight()));
223 // Reset the current render surface to force an update of the viewport and
224 // projection matrix next time useRenderSurface is called.
225 m_currentRenderSurface = 0;
228 void LayerRendererChromium::drawLayers()
230 // FIXME: use the frame begin time from the overall compositor scheduler.
231 // This value is currently inaccessible because it is up in Chromium's
233 m_headsUpDisplay->onFrameBegin(currentTime());
238 m_renderSurfaceTextureManager->setMemoryLimitBytes(TextureManager::highLimitBytes() - m_contentsTextureMemoryUseBytes);
239 drawLayersInternal();
241 if (TextureManager::reclaimLimitBytes() > m_contentsTextureMemoryUseBytes)
242 m_renderSurfaceTextureManager->reduceMemoryToLimit(TextureManager::reclaimLimitBytes() - m_contentsTextureMemoryUseBytes);
244 m_renderSurfaceTextureManager->reduceMemoryToLimit(0);
245 m_renderSurfaceTextureManager->deleteEvictedTextures(m_context.get());
247 if (settings().compositeOffscreen)
248 copyOffscreenTextureToDisplay();
251 void LayerRendererChromium::drawLayersInternal()
253 if (viewportSize().isEmpty() || !rootLayer())
256 TRACE_EVENT("LayerRendererChromium::drawLayers", this, 0);
257 CCLayerImpl* rootDrawLayer = rootLayer();
258 makeContextCurrent();
260 if (!rootDrawLayer->renderSurface())
261 rootDrawLayer->createRenderSurface();
262 rootDrawLayer->renderSurface()->setContentRect(IntRect(IntPoint(), viewportSize()));
264 rootDrawLayer->setScissorRect(IntRect(IntPoint(), viewportSize()));
266 CCLayerList renderSurfaceLayerList;
267 renderSurfaceLayerList.append(rootDrawLayer);
269 TransformationMatrix zoomMatrix;
270 zoomMatrix.scale3d(m_zoomAnimatorScale, m_zoomAnimatorScale, 1);
271 m_defaultRenderSurface = rootDrawLayer->renderSurface();
272 m_defaultRenderSurface->clearLayerList();
275 TRACE_EVENT("LayerRendererChromium::drawLayersInternal::calcDrawEtc", this, 0);
276 CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(rootDrawLayer, rootDrawLayer, zoomMatrix, zoomMatrix, renderSurfaceLayerList, m_defaultRenderSurface->layerList(), &m_layerSorter, m_capabilities.maxTextureSize);
279 // The GL viewport covers the entire visible area, including the scrollbars.
280 GLC(m_context.get(), m_context->viewport(0, 0, viewportWidth(), viewportHeight()));
281 m_windowMatrix = screenMatrix(0, 0, viewportWidth(), viewportHeight());
283 // Bind the common vertex attributes used for drawing all the layers.
284 m_sharedGeometry->prepareForDraw();
286 GLC(m_context.get(), m_context->disable(GraphicsContext3D::SCISSOR_TEST));
287 GLC(m_context.get(), m_context->disable(GraphicsContext3D::DEPTH_TEST));
288 GLC(m_context.get(), m_context->disable(GraphicsContext3D::CULL_FACE));
290 useRenderSurface(m_defaultRenderSurface);
292 // Clear to blue to make it easier to spot unrendered regions.
293 m_context->clearColor(0, 0, 1, 1);
294 m_context->colorMask(true, true, true, true);
295 m_context->clear(GraphicsContext3D::COLOR_BUFFER_BIT);
297 GLC(m_context.get(), m_context->enable(GraphicsContext3D::BLEND));
298 GLC(m_context.get(), m_context->blendFunc(GraphicsContext3D::ONE, GraphicsContext3D::ONE_MINUS_SRC_ALPHA));
299 GLC(m_context.get(), m_context->enable(GraphicsContext3D::SCISSOR_TEST));
301 // Update the contents of the render surfaces. We traverse the array from
302 // back to front to guarantee that nested render surfaces get rendered in the
304 for (int surfaceIndex = renderSurfaceLayerList.size() - 1; surfaceIndex >= 0 ; --surfaceIndex) {
305 CCLayerImpl* renderSurfaceLayer = renderSurfaceLayerList[surfaceIndex].get();
306 CCRenderSurface* renderSurface = renderSurfaceLayer->renderSurface();
307 ASSERT(renderSurface);
309 renderSurface->setSkipsDraw(true);
311 // Render surfaces whose drawable area has zero width or height
312 // will have no layers associated with them and should be skipped.
313 if (!renderSurface->layerList().size())
316 // Skip completely transparent render surfaces.
317 if (!renderSurface->drawOpacity())
320 if (useRenderSurface(renderSurface)) {
321 renderSurface->setSkipsDraw(false);
323 if (renderSurfaceLayer != rootDrawLayer) {
324 GLC(m_context.get(), m_context->disable(GraphicsContext3D::SCISSOR_TEST));
325 GLC(m_context.get(), m_context->clearColor(0, 0, 0, 0));
326 GLC(m_context.get(), m_context->clear(GraphicsContext3D::COLOR_BUFFER_BIT));
327 GLC(m_context.get(), m_context->enable(GraphicsContext3D::SCISSOR_TEST));
330 const CCLayerList& layerList = renderSurface->layerList();
331 for (unsigned layerIndex = 0; layerIndex < layerList.size(); ++layerIndex)
332 drawLayer(layerList[layerIndex].get(), renderSurface);
336 if (m_headsUpDisplay->enabled()) {
337 GLC(m_context.get(), m_context->enable(GraphicsContext3D::BLEND));
338 GLC(m_context.get(), m_context->blendFunc(GraphicsContext3D::ONE, GraphicsContext3D::ONE_MINUS_SRC_ALPHA));
339 GLC(m_context.get(), m_context->disable(GraphicsContext3D::SCISSOR_TEST));
340 useRenderSurface(m_defaultRenderSurface);
341 m_headsUpDisplay->draw();
344 GLC(m_context.get(), m_context->disable(GraphicsContext3D::SCISSOR_TEST));
345 GLC(m_context.get(), m_context->disable(GraphicsContext3D::BLEND));
348 void LayerRendererChromium::finish()
350 TRACE_EVENT("LayerRendererChromium::finish", this, 0);
354 void LayerRendererChromium::present()
356 TRACE_EVENT("LayerRendererChromium::present", this, 0);
357 // We're done! Time to swapbuffers!
359 // Note that currently this has the same effect as swapBuffers; we should
360 // consider exposing a different entry point on GraphicsContext3D.
361 m_context->prepareTexture();
363 m_headsUpDisplay->onPresent();
366 void LayerRendererChromium::getFramebufferPixels(void *pixels, const IntRect& rect)
368 ASSERT(rect.maxX() <= viewportWidth() && rect.maxY() <= viewportHeight());
373 makeContextCurrent();
375 GLC(m_context.get(), m_context->readPixels(rect.x(), rect.y(), rect.width(), rect.height(),
376 GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE, pixels));
379 // FIXME: This method should eventually be replaced by a proper texture manager.
380 unsigned LayerRendererChromium::createLayerTexture()
382 unsigned textureId = 0;
383 GLC(m_context.get(), textureId = m_context->createTexture());
384 GLC(m_context.get(), m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, textureId));
385 // Do basic linear filtering on resize.
386 GLC(m_context.get(), m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::LINEAR));
387 GLC(m_context.get(), m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MAG_FILTER, GraphicsContext3D::LINEAR));
388 // NPOT textures in GL ES only work when the wrap mode is set to GraphicsContext3D::CLAMP_TO_EDGE.
389 GLC(m_context.get(), m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE));
390 GLC(m_context.get(), m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE));
394 void LayerRendererChromium::deleteLayerTexture(unsigned textureId)
399 GLC(m_context.get(), m_context->deleteTexture(textureId));
402 // Returns true if any part of the layer falls within the visibleRect
403 bool LayerRendererChromium::isLayerVisible(LayerChromium* layer, const TransformationMatrix& matrix, const IntRect& visibleRect)
405 // Form the matrix used by the shader to map the corners of the layer's
406 // bounds into clip space.
407 TransformationMatrix renderMatrix = matrix;
408 renderMatrix.scale3d(layer->bounds().width(), layer->bounds().height(), 1);
409 renderMatrix = m_projectionMatrix * renderMatrix;
411 FloatRect layerRect(-0.5, -0.5, 1, 1);
412 FloatRect mappedRect = renderMatrix.mapRect(layerRect);
414 // The layer is visible if it intersects any part of a rectangle whose origin
415 // is at (-1, -1) and size is 2x2.
416 return mappedRect.intersects(FloatRect(-1, -1, 2, 2));
419 ManagedTexture* LayerRendererChromium::getOffscreenLayerTexture()
421 return settings().compositeOffscreen && rootLayer() ? rootLayer()->renderSurface()->contentsTexture() : 0;
424 void LayerRendererChromium::copyOffscreenTextureToDisplay()
426 if (settings().compositeOffscreen) {
427 makeContextCurrent();
430 TransformationMatrix drawTransform;
431 drawTransform.translate3d(0.5 * m_defaultRenderSurface->contentRect().width(), 0.5 * m_defaultRenderSurface->contentRect().height(), 0);
432 m_defaultRenderSurface->setDrawTransform(drawTransform);
433 m_defaultRenderSurface->setDrawOpacity(1);
434 m_defaultRenderSurface->draw(this, m_defaultRenderSurface->contentRect());
438 bool LayerRendererChromium::useRenderSurface(CCRenderSurface* renderSurface)
440 if (m_currentRenderSurface == renderSurface)
443 m_currentRenderSurface = renderSurface;
445 if ((renderSurface == m_defaultRenderSurface && !settings().compositeOffscreen) || (!renderSurface && settings().compositeOffscreen)) {
446 GLC(m_context.get(), m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, 0));
448 setDrawViewportRect(renderSurface->contentRect(), true);
450 setDrawViewportRect(m_defaultRenderSurface->contentRect(), true);
454 GLC(m_context.get(), m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_offscreenFramebufferId));
456 if (!renderSurface->prepareContentsTexture(this))
459 renderSurface->contentsTexture()->framebufferTexture2D(m_context.get());
461 #if !defined ( NDEBUG )
462 if (m_context->checkFramebufferStatus(GraphicsContext3D::FRAMEBUFFER) != GraphicsContext3D::FRAMEBUFFER_COMPLETE) {
463 ASSERT_NOT_REACHED();
468 setDrawViewportRect(renderSurface->contentRect(), false);
472 void LayerRendererChromium::drawLayer(CCLayerImpl* layer, CCRenderSurface* targetSurface)
474 if (layer->renderSurface() && layer->renderSurface() != targetSurface) {
475 layer->renderSurface()->draw(this, layer->getDrawRect());
476 layer->renderSurface()->releaseContentsTexture();
480 if (!layer->drawsContent())
483 if (!layer->opacity())
486 if (layer->bounds().isEmpty())
489 IntRect targetSurfaceRect = layer->targetRenderSurface() ? layer->targetRenderSurface()->contentRect() : m_defaultRenderSurface->contentRect();
490 if (layer->usesLayerScissor()) {
491 IntRect scissorRect = layer->scissorRect();
492 targetSurfaceRect.intersect(scissorRect);
493 if (targetSurfaceRect.isEmpty())
495 setScissorToRect(scissorRect);
497 GLC(m_context.get(), m_context->disable(GraphicsContext3D::SCISSOR_TEST));
499 // The layer should not be drawn if (1) it is not double-sided and (2) the back of the layer is facing the screen.
500 // This second condition is checked by computing the transformed normal of the layer.
501 if (!layer->doubleSided()) {
502 FloatRect layerRect(FloatPoint(0, 0), FloatSize(layer->bounds()));
503 FloatQuad mappedLayer = layer->screenSpaceTransform().mapQuad(FloatQuad(layerRect));
504 FloatSize horizontalDir = mappedLayer.p2() - mappedLayer.p1();
505 FloatSize verticalDir = mappedLayer.p4() - mappedLayer.p1();
506 FloatPoint3D xAxis(horizontalDir.width(), horizontalDir.height(), 0);
507 FloatPoint3D yAxis(verticalDir.width(), verticalDir.height(), 0);
508 FloatPoint3D zAxis = xAxis.cross(yAxis);
515 // Draw the debug border if there is one.
516 layer->drawDebugBorder(this);
519 // Sets the scissor region to the given rectangle. The coordinate system for the
520 // scissorRect has its origin at the top left corner of the current visible rect.
521 void LayerRendererChromium::setScissorToRect(const IntRect& scissorRect)
523 IntRect contentRect = (m_currentRenderSurface ? m_currentRenderSurface->contentRect() : m_defaultRenderSurface->contentRect());
525 GLC(m_context.get(), m_context->enable(GraphicsContext3D::SCISSOR_TEST));
527 // The scissor coordinates must be supplied in viewport space so we need to offset
528 // by the relative position of the top left corner of the current render surface.
529 int scissorX = scissorRect.x() - contentRect.x();
530 // When rendering to the default render surface we're rendering upside down so the top
531 // of the GL scissor is the bottom of our layer.
532 // But, if rendering to offscreen texture, we reverse our sense of 'upside down'.
534 if (m_currentRenderSurface == m_defaultRenderSurface && !settings().compositeOffscreen)
535 scissorY = m_currentRenderSurface->contentRect().height() - (scissorRect.maxY() - m_currentRenderSurface->contentRect().y());
537 scissorY = scissorRect.y() - contentRect.y();
538 GLC(m_context.get(), m_context->scissor(scissorX, scissorY, scissorRect.width(), scissorRect.height()));
541 bool LayerRendererChromium::makeContextCurrent()
543 m_context->makeContextCurrent();
547 // Sets the coordinate range of content that ends being drawn onto the target render surface.
548 // The target render surface is assumed to have an origin at 0, 0 and the width and height of
550 void LayerRendererChromium::setDrawViewportRect(const IntRect& drawRect, bool flipY)
553 m_projectionMatrix = orthoMatrix(drawRect.x(), drawRect.maxX(), drawRect.maxY(), drawRect.y());
555 m_projectionMatrix = orthoMatrix(drawRect.x(), drawRect.maxX(), drawRect.y(), drawRect.maxY());
556 GLC(m_context.get(), m_context->viewport(0, 0, drawRect.width(), drawRect.height()));
557 m_windowMatrix = screenMatrix(0, 0, drawRect.width(), drawRect.height());
561 bool LayerRendererChromium::initializeSharedObjects()
563 TRACE_EVENT("LayerRendererChromium::initializeSharedObjects", this, 0);
564 makeContextCurrent();
566 // Create an FBO for doing offscreen rendering.
567 GLC(m_context.get(), m_offscreenFramebufferId = m_context->createFramebuffer());
569 // We will always need these programs to render, so create the programs eagerly so that the shader compilation can
570 // start while we do other work. Other programs are created lazily on first access.
571 m_sharedGeometry = adoptPtr(new GeometryBinding(m_context.get()));
572 m_renderSurfaceProgram = adoptPtr(new CCRenderSurface::Program(m_context.get()));
573 m_tilerProgram = adoptPtr(new CCTiledLayerImpl::Program(m_context.get()));
575 GLC(m_context.get(), m_context->flush());
577 m_renderSurfaceTextureManager = TextureManager::create(TextureManager::highLimitBytes(), m_capabilities.maxTextureSize);
581 const LayerChromium::BorderProgram* LayerRendererChromium::borderProgram()
583 if (!m_borderProgram)
584 m_borderProgram = adoptPtr(new LayerChromium::BorderProgram(m_context.get()));
585 if (!m_borderProgram->initialized()) {
586 TRACE_EVENT("LayerRendererChromium::borderProgram::initialize", this, 0);
587 m_borderProgram->initialize(m_context.get());
589 return m_borderProgram.get();
592 const CCHeadsUpDisplay::Program* LayerRendererChromium::headsUpDisplayProgram()
594 if (!m_headsUpDisplayProgram)
595 m_headsUpDisplayProgram = adoptPtr(new CCHeadsUpDisplay::Program(m_context.get()));
596 if (!m_headsUpDisplayProgram->initialized()) {
597 TRACE_EVENT("LayerRendererChromium::headsUpDisplayProgram::initialize", this, 0);
598 m_headsUpDisplayProgram->initialize(m_context.get());
600 return m_headsUpDisplayProgram.get();
603 const CCRenderSurface::Program* LayerRendererChromium::renderSurfaceProgram()
605 ASSERT(m_renderSurfaceProgram);
606 if (!m_renderSurfaceProgram->initialized()) {
607 TRACE_EVENT("LayerRendererChromium::renderSurfaceProgram::initialize", this, 0);
608 m_renderSurfaceProgram->initialize(m_context.get());
610 return m_renderSurfaceProgram.get();
613 const CCRenderSurface::ProgramAA* LayerRendererChromium::renderSurfaceProgramAA()
615 if (!m_renderSurfaceProgramAA)
616 m_renderSurfaceProgramAA = adoptPtr(new CCRenderSurface::ProgramAA(m_context.get()));
617 if (!m_renderSurfaceProgramAA->initialized()) {
618 TRACE_EVENT("LayerRendererChromium::renderSurfaceProgramAA::initialize", this, 0);
619 m_renderSurfaceProgramAA->initialize(m_context.get());
621 return m_renderSurfaceProgramAA.get();
624 const CCRenderSurface::MaskProgram* LayerRendererChromium::renderSurfaceMaskProgram()
626 if (!m_renderSurfaceMaskProgram)
627 m_renderSurfaceMaskProgram = adoptPtr(new CCRenderSurface::MaskProgram(m_context.get()));
628 if (!m_renderSurfaceMaskProgram->initialized()) {
629 TRACE_EVENT("LayerRendererChromium::renderSurfaceMaskProgram::initialize", this, 0);
630 m_renderSurfaceMaskProgram->initialize(m_context.get());
632 return m_renderSurfaceMaskProgram.get();
635 const CCRenderSurface::MaskProgramAA* LayerRendererChromium::renderSurfaceMaskProgramAA()
637 if (!m_renderSurfaceMaskProgramAA)
638 m_renderSurfaceMaskProgramAA = adoptPtr(new CCRenderSurface::MaskProgramAA(m_context.get()));
639 if (!m_renderSurfaceMaskProgramAA->initialized()) {
640 TRACE_EVENT("LayerRendererChromium::renderSurfaceMaskProgramAA::initialize", this, 0);
641 m_renderSurfaceMaskProgramAA->initialize(m_context.get());
643 return m_renderSurfaceMaskProgramAA.get();
646 const CCTiledLayerImpl::Program* LayerRendererChromium::tilerProgram()
648 ASSERT(m_tilerProgram);
649 if (!m_tilerProgram->initialized()) {
650 TRACE_EVENT("LayerRendererChromium::tilerProgram::initialize", this, 0);
651 m_tilerProgram->initialize(m_context.get());
653 return m_tilerProgram.get();
656 const CCTiledLayerImpl::ProgramAA* LayerRendererChromium::tilerProgramAA()
658 if (!m_tilerProgramAA)
659 m_tilerProgramAA = adoptPtr(new CCTiledLayerImpl::ProgramAA(m_context.get()));
660 if (!m_tilerProgramAA->initialized()) {
661 TRACE_EVENT("LayerRendererChromium::tilerProgramAA::initialize", this, 0);
662 m_tilerProgramAA->initialize(m_context.get());
664 return m_tilerProgramAA.get();
667 const CCTiledLayerImpl::ProgramSwizzle* LayerRendererChromium::tilerProgramSwizzle()
669 if (!m_tilerProgramSwizzle)
670 m_tilerProgramSwizzle = adoptPtr(new CCTiledLayerImpl::ProgramSwizzle(m_context.get()));
671 if (!m_tilerProgramSwizzle->initialized()) {
672 TRACE_EVENT("LayerRendererChromium::tilerProgramSwizzle::initialize", this, 0);
673 m_tilerProgramSwizzle->initialize(m_context.get());
675 return m_tilerProgramSwizzle.get();
678 const CCTiledLayerImpl::ProgramSwizzleAA* LayerRendererChromium::tilerProgramSwizzleAA()
680 if (!m_tilerProgramSwizzleAA)
681 m_tilerProgramSwizzleAA = adoptPtr(new CCTiledLayerImpl::ProgramSwizzleAA(m_context.get()));
682 if (!m_tilerProgramSwizzleAA->initialized()) {
683 TRACE_EVENT("LayerRendererChromium::tilerProgramSwizzleAA::initialize", this, 0);
684 m_tilerProgramSwizzleAA->initialize(m_context.get());
686 return m_tilerProgramSwizzleAA.get();
689 const CCCanvasLayerImpl::Program* LayerRendererChromium::canvasLayerProgram()
691 if (!m_canvasLayerProgram)
692 m_canvasLayerProgram = adoptPtr(new CCCanvasLayerImpl::Program(m_context.get()));
693 if (!m_canvasLayerProgram->initialized()) {
694 TRACE_EVENT("LayerRendererChromium::canvasLayerProgram::initialize", this, 0);
695 m_canvasLayerProgram->initialize(m_context.get());
697 return m_canvasLayerProgram.get();
700 const CCPluginLayerImpl::Program* LayerRendererChromium::pluginLayerProgram()
702 if (!m_pluginLayerProgram)
703 m_pluginLayerProgram = adoptPtr(new CCPluginLayerImpl::Program(m_context.get()));
704 if (!m_pluginLayerProgram->initialized()) {
705 TRACE_EVENT("LayerRendererChromium::pluginLayerProgram::initialize", this, 0);
706 m_pluginLayerProgram->initialize(m_context.get());
708 return m_pluginLayerProgram.get();
711 const CCVideoLayerImpl::RGBAProgram* LayerRendererChromium::videoLayerRGBAProgram()
713 if (!m_videoLayerRGBAProgram)
714 m_videoLayerRGBAProgram = adoptPtr(new CCVideoLayerImpl::RGBAProgram(m_context.get()));
715 if (!m_videoLayerRGBAProgram->initialized()) {
716 TRACE_EVENT("LayerRendererChromium::videoLayerRGBAProgram::initialize", this, 0);
717 m_videoLayerRGBAProgram->initialize(m_context.get());
719 return m_videoLayerRGBAProgram.get();
722 const CCVideoLayerImpl::YUVProgram* LayerRendererChromium::videoLayerYUVProgram()
724 if (!m_videoLayerYUVProgram)
725 m_videoLayerYUVProgram = adoptPtr(new CCVideoLayerImpl::YUVProgram(m_context.get()));
726 if (!m_videoLayerYUVProgram->initialized()) {
727 TRACE_EVENT("LayerRendererChromium::videoLayerYUVProgram::initialize", this, 0);
728 m_videoLayerYUVProgram->initialize(m_context.get());
730 return m_videoLayerYUVProgram.get();
734 void LayerRendererChromium::cleanupSharedObjects()
736 makeContextCurrent();
738 m_sharedGeometry.clear();
741 m_borderProgram->cleanup(m_context.get());
742 if (m_headsUpDisplayProgram)
743 m_headsUpDisplayProgram->cleanup(m_context.get());
745 m_tilerProgram->cleanup(m_context.get());
746 if (m_tilerProgramAA)
747 m_tilerProgramAA->cleanup(m_context.get());
748 if (m_tilerProgramSwizzle)
749 m_tilerProgramSwizzle->cleanup(m_context.get());
750 if (m_tilerProgramSwizzleAA)
751 m_tilerProgramSwizzleAA->cleanup(m_context.get());
752 if (m_canvasLayerProgram)
753 m_canvasLayerProgram->cleanup(m_context.get());
754 if (m_pluginLayerProgram)
755 m_pluginLayerProgram->cleanup(m_context.get());
756 if (m_renderSurfaceMaskProgram)
757 m_renderSurfaceMaskProgram->cleanup(m_context.get());
758 if (m_renderSurfaceMaskProgramAA)
759 m_renderSurfaceMaskProgramAA->cleanup(m_context.get());
760 if (m_renderSurfaceProgram)
761 m_renderSurfaceProgram->cleanup(m_context.get());
762 if (m_renderSurfaceProgramAA)
763 m_renderSurfaceProgramAA->cleanup(m_context.get());
764 if (m_videoLayerRGBAProgram)
765 m_videoLayerRGBAProgram->cleanup(m_context.get());
766 if (m_videoLayerYUVProgram)
767 m_videoLayerYUVProgram->cleanup(m_context.get());
769 m_borderProgram.clear();
770 m_headsUpDisplayProgram.clear();
771 m_tilerProgram.clear();
772 m_tilerProgramAA.clear();
773 m_tilerProgramSwizzle.clear();
774 m_tilerProgramSwizzleAA.clear();
775 m_canvasLayerProgram.clear();
776 m_pluginLayerProgram.clear();
777 m_renderSurfaceMaskProgram.clear();
778 m_renderSurfaceMaskProgramAA.clear();
779 m_renderSurfaceProgram.clear();
780 m_renderSurfaceProgramAA.clear();
781 m_videoLayerRGBAProgram.clear();
782 m_videoLayerYUVProgram.clear();
783 if (m_offscreenFramebufferId)
784 GLC(m_context.get(), m_context->deleteFramebuffer(m_offscreenFramebufferId));
786 ASSERT(!m_contentsTextureMemoryUseBytes);
787 releaseRenderSurfaceTextures();
790 String LayerRendererChromium::layerTreeAsText() const
794 ts << rootLayer()->layerTreeAsText();
795 ts << "RenderSurfaces:\n";
796 dumpRenderSurfaces(ts, 1, rootLayer());
801 void LayerRendererChromium::dumpRenderSurfaces(TextStream& ts, int indent, const CCLayerImpl* layer) const
803 if (layer->renderSurface())
804 layer->renderSurface()->dumpSurface(ts, indent);
806 for (size_t i = 0; i < layer->children().size(); ++i)
807 dumpRenderSurfaces(ts, indent, layer->children()[i].get());
810 bool LayerRendererChromium::isContextLost()
812 return (m_context.get()->getExtensions()->getGraphicsResetStatusARB() != GraphicsContext3D::NO_ERROR);
815 } // namespace WebCore
817 #endif // USE(ACCELERATED_COMPOSITING)