[content shell] implement testRunner.overridePreference
[chromium-blink-merge.git] / cc / io_surface_layer_impl.cc
blob944443b6486faf1147e4ca3ce152d07f4da7e1ea
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 "cc/io_surface_layer_impl.h"
7 #include "base/stringprintf.h"
8 #include "cc/gl_renderer.h" // For the GLC() macro.
9 #include "cc/io_surface_draw_quad.h"
10 #include "cc/layer_tree_impl.h"
11 #include "cc/output_surface.h"
12 #include "cc/quad_sink.h"
13 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3D.h"
14 #include "third_party/khronos/GLES2/gl2.h"
15 #include "third_party/khronos/GLES2/gl2ext.h"
17 namespace cc {
19 IOSurfaceLayerImpl::IOSurfaceLayerImpl(LayerTreeImpl* treeImpl, int id)
20 : LayerImpl(treeImpl, id)
21 , m_ioSurfaceId(0)
22 , m_ioSurfaceChanged(false)
23 , m_ioSurfaceTextureId(0)
27 IOSurfaceLayerImpl::~IOSurfaceLayerImpl()
29 if (!m_ioSurfaceTextureId)
30 return;
32 OutputSurface* outputSurface = layerTreeImpl()->output_surface();
33 // FIXME: Implement this path for software compositing.
34 WebKit::WebGraphicsContext3D* context3d = outputSurface->Context3D();
35 if (context3d)
36 context3d->deleteTexture(m_ioSurfaceTextureId);
39 void IOSurfaceLayerImpl::willDraw(ResourceProvider* resourceProvider)
41 LayerImpl::willDraw(resourceProvider);
43 if (m_ioSurfaceChanged) {
44 WebKit::WebGraphicsContext3D* context3d = resourceProvider->graphicsContext3D();
45 if (!context3d) {
46 // FIXME: Implement this path for software compositing.
47 return;
50 // FIXME: Do this in a way that we can track memory usage.
51 if (!m_ioSurfaceTextureId)
52 m_ioSurfaceTextureId = context3d->createTexture();
54 GLC(context3d, context3d->activeTexture(GL_TEXTURE0));
55 GLC(context3d, context3d->bindTexture(GL_TEXTURE_RECTANGLE_ARB, m_ioSurfaceTextureId));
56 GLC(context3d, context3d->texParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
57 GLC(context3d, context3d->texParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
58 GLC(context3d, context3d->texParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
59 GLC(context3d, context3d->texParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
60 context3d->texImageIOSurface2DCHROMIUM(GL_TEXTURE_RECTANGLE_ARB,
61 m_ioSurfaceSize.width(),
62 m_ioSurfaceSize.height(),
63 m_ioSurfaceId,
64 0);
65 // Do not check for error conditions. texImageIOSurface2DCHROMIUM is supposed to hold on to
66 // the last good IOSurface if the new one is already closed. This is only a possibility
67 // during live resizing of plugins. However, it seems that this is not sufficient to
68 // completely guard against garbage being drawn. If this is found to be a significant issue,
69 // it may be necessary to explicitly tell the embedder when to free the surfaces it has
70 // allocated.
71 m_ioSurfaceChanged = false;
75 void IOSurfaceLayerImpl::appendQuads(QuadSink& quadSink, AppendQuadsData& appendQuadsData)
77 SharedQuadState* sharedQuadState = quadSink.useSharedQuadState(createSharedQuadState());
78 appendDebugBorderQuad(quadSink, sharedQuadState, appendQuadsData);
80 gfx::Rect quadRect(gfx::Point(), contentBounds());
81 gfx::Rect opaqueRect(contentsOpaque() ? quadRect : gfx::Rect());
82 scoped_ptr<IOSurfaceDrawQuad> quad = IOSurfaceDrawQuad::Create();
83 quad->SetNew(sharedQuadState, quadRect, opaqueRect, m_ioSurfaceSize, m_ioSurfaceTextureId, IOSurfaceDrawQuad::FLIPPED);
84 quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData);
87 void IOSurfaceLayerImpl::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 LayerImpl::dumpLayerProperties(str, indent);
94 void IOSurfaceLayerImpl::didLoseOutputSurface()
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 IOSurfaceLayerImpl::setIOSurfaceProperties(unsigned ioSurfaceId, const gfx::Size& size)
104 if (m_ioSurfaceId != ioSurfaceId)
105 m_ioSurfaceChanged = true;
107 m_ioSurfaceId = ioSurfaceId;
108 m_ioSurfaceSize = size;
111 const char* IOSurfaceLayerImpl::layerTypeAsString() const
113 return "IOSurfaceLayer";
116 } // namespace cc