WebKit merge 128969:128981
[chromium-blink-merge.git] / cc / CCIOSurfaceLayerImpl.cpp
blobcae6809bba06a0b869f5697b58d7938a6f216011
1 // Copyright 2012 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.
5 #include "config.h"
7 #if USE(ACCELERATED_COMPOSITING)
9 #include "CCIOSurfaceLayerImpl.h"
11 #include "base/stringprintf.h"
12 #include "CCGraphicsContext.h"
13 #include "CCIOSurfaceDrawQuad.h"
14 #include "CCLayerTreeHostImpl.h"
15 #include "CCQuadSink.h"
16 #include "CCRendererGL.h" // For the GLC() macro.
17 #include "Extensions3D.h"
18 #include <public/WebGraphicsContext3D.h>
20 namespace cc {
22 CCIOSurfaceLayerImpl::CCIOSurfaceLayerImpl(int id)
23 : CCLayerImpl(id)
24 , m_ioSurfaceId(0)
25 , m_ioSurfaceChanged(false)
26 , m_ioSurfaceTextureId(0)
30 CCIOSurfaceLayerImpl::~CCIOSurfaceLayerImpl()
32 if (!m_ioSurfaceTextureId)
33 return;
35 CCGraphicsContext* context = layerTreeHostImpl()->context();
36 // FIXME: Implement this path for software compositing.
37 WebKit::WebGraphicsContext3D* context3d = context->context3D();
38 if (context3d)
39 context3d->deleteTexture(m_ioSurfaceTextureId);
42 void CCIOSurfaceLayerImpl::willDraw(CCResourceProvider* resourceProvider)
44 CCLayerImpl::willDraw(resourceProvider);
46 if (m_ioSurfaceChanged) {
47 WebKit::WebGraphicsContext3D* context3d = resourceProvider->graphicsContext3D();
48 if (!context3d) {
49 // FIXME: Implement this path for software compositing.
50 return;
53 // FIXME: Do this in a way that we can track memory usage.
54 if (!m_ioSurfaceTextureId)
55 m_ioSurfaceTextureId = context3d->createTexture();
57 GLC(context3d, context3d->activeTexture(GraphicsContext3D::TEXTURE0));
58 GLC(context3d, context3d->bindTexture(Extensions3D::TEXTURE_RECTANGLE_ARB, m_ioSurfaceTextureId));
59 GLC(context3d, context3d->texParameteri(Extensions3D::TEXTURE_RECTANGLE_ARB, GraphicsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::LINEAR));
60 GLC(context3d, context3d->texParameteri(Extensions3D::TEXTURE_RECTANGLE_ARB, GraphicsContext3D::TEXTURE_MAG_FILTER, GraphicsContext3D::LINEAR));
61 GLC(context3d, context3d->texParameteri(Extensions3D::TEXTURE_RECTANGLE_ARB, GraphicsContext3D::TEXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE));
62 GLC(context3d, context3d->texParameteri(Extensions3D::TEXTURE_RECTANGLE_ARB, GraphicsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE));
63 context3d->texImageIOSurface2DCHROMIUM(Extensions3D::TEXTURE_RECTANGLE_ARB,
64 m_ioSurfaceSize.width(),
65 m_ioSurfaceSize.height(),
66 m_ioSurfaceId,
67 0);
68 // Do not check for error conditions. texImageIOSurface2DCHROMIUM is supposed to hold on to
69 // the last good IOSurface if the new one is already closed. This is only a possibility
70 // during live resizing of plugins. However, it seems that this is not sufficient to
71 // completely guard against garbage being drawn. If this is found to be a significant issue,
72 // it may be necessary to explicitly tell the embedder when to free the surfaces it has
73 // allocated.
74 m_ioSurfaceChanged = false;
78 void CCIOSurfaceLayerImpl::appendQuads(CCQuadSink& quadSink, CCAppendQuadsData& appendQuadsData)
80 CCSharedQuadState* sharedQuadState = quadSink.useSharedQuadState(createSharedQuadState());
81 appendDebugBorderQuad(quadSink, sharedQuadState, appendQuadsData);
83 IntRect quadRect(IntPoint(), contentBounds());
84 quadSink.append(CCIOSurfaceDrawQuad::create(sharedQuadState, quadRect, m_ioSurfaceSize, m_ioSurfaceTextureId, CCIOSurfaceDrawQuad::Flipped), appendQuadsData);
87 void CCIOSurfaceLayerImpl::dumpLayerProperties(std::string* str, int indent) const
89 str->append(indentString(indent));
90 base::StringAppendF(str, "iosurface id: %u texture id: %u\n", m_ioSurfaceId, m_ioSurfaceTextureId);
91 CCLayerImpl::dumpLayerProperties(str, indent);
94 void CCIOSurfaceLayerImpl::didLoseContext()
96 // We don't have a valid texture ID in the new context; however,
97 // the IOSurface is still valid.
98 m_ioSurfaceTextureId = 0;
99 m_ioSurfaceChanged = true;
102 void CCIOSurfaceLayerImpl::setIOSurfaceProperties(unsigned ioSurfaceId, const IntSize& size)
104 if (m_ioSurfaceId != ioSurfaceId)
105 m_ioSurfaceChanged = true;
107 m_ioSurfaceId = ioSurfaceId;
108 m_ioSurfaceSize = size;
112 #endif // USE(ACCELERATED_COMPOSITING)