Remove extra line from unit_tests.isolate
[chromium-blink-merge.git] / cc / TextureCopier.cpp
blobb0db144ad0686f1a0d12e37d8a41837346fad0ce
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 #include "TextureCopier.h"
9 #include "CCRendererGL.h" // For the GLC() macro.
10 #include "GraphicsContext3D.h"
11 #include "TraceEvent.h"
12 #include <public/WebGraphicsContext3D.h>
14 namespace cc {
16 #if USE(ACCELERATED_COMPOSITING)
17 AcceleratedTextureCopier::AcceleratedTextureCopier(WebKit::WebGraphicsContext3D* context, bool usingBindUniforms)
18 : m_context(context)
19 , m_usingBindUniforms(usingBindUniforms)
21 ASSERT(m_context);
22 GLC(m_context, m_fbo = m_context->createFramebuffer());
23 GLC(m_context, m_positionBuffer = m_context->createBuffer());
25 static const float kPositions[4][4] = {
26 {-1, -1, 0, 1},
27 { 1, -1, 0, 1},
28 { 1, 1, 0, 1},
29 {-1, 1, 0, 1}
32 GLC(m_context, m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, m_positionBuffer));
33 GLC(m_context, m_context->bufferData(GraphicsContext3D::ARRAY_BUFFER, sizeof(kPositions), kPositions, GraphicsContext3D::STATIC_DRAW));
34 GLC(m_context, m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, 0));
36 m_blitProgram = adoptPtr(new BlitProgram(m_context));
39 AcceleratedTextureCopier::~AcceleratedTextureCopier()
41 if (m_blitProgram)
42 m_blitProgram->cleanup(m_context);
43 if (m_positionBuffer)
44 GLC(m_context, m_context->deleteBuffer(m_positionBuffer));
45 if (m_fbo)
46 GLC(m_context, m_context->deleteFramebuffer(m_fbo));
49 void AcceleratedTextureCopier::copyTexture(Parameters parameters)
51 TRACE_EVENT0("cc", "TextureCopier::copyTexture");
53 // Note: this code does not restore the viewport, bound program, 2D texture, framebuffer, buffer or blend enable.
54 GLC(m_context, m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo));
55 GLC(m_context, m_context->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::COLOR_ATTACHMENT0, GraphicsContext3D::TEXTURE_2D, parameters.destTexture, 0));
57 #if OS(ANDROID)
58 // Clear destination to improve performance on tiling GPUs.
59 // TODO: Use EXT_discard_framebuffer or skip clearing if it isn't available.
60 GLC(m_context, m_context->clear(GraphicsContext3D::COLOR_BUFFER_BIT));
61 #endif
63 GLC(m_context, m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, parameters.sourceTexture));
64 GLC(m_context, m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::NEAREST));
65 GLC(m_context, m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MAG_FILTER, GraphicsContext3D::NEAREST));
67 if (!m_blitProgram->initialized())
68 m_blitProgram->initialize(m_context, m_usingBindUniforms);
70 // TODO: Use EXT_framebuffer_blit if available.
71 GLC(m_context, m_context->useProgram(m_blitProgram->program()));
73 const int kPositionAttribute = 0;
74 GLC(m_context, m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, m_positionBuffer));
75 GLC(m_context, m_context->vertexAttribPointer(kPositionAttribute, 4, GraphicsContext3D::FLOAT, false, 0, 0));
76 GLC(m_context, m_context->enableVertexAttribArray(kPositionAttribute));
77 GLC(m_context, m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, 0));
79 GLC(m_context, m_context->viewport(0, 0, parameters.size.width(), parameters.size.height()));
80 GLC(m_context, m_context->disable(GraphicsContext3D::BLEND));
81 GLC(m_context, m_context->drawArrays(GraphicsContext3D::TRIANGLE_FAN, 0, 4));
83 GLC(m_context, m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::LINEAR));
84 GLC(m_context, m_context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MAG_FILTER, GraphicsContext3D::LINEAR));
85 GLC(m_context, m_context->disableVertexAttribArray(kPositionAttribute));
87 GLC(m_context, m_context->useProgram(0));
89 GLC(m_context, m_context->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::COLOR_ATTACHMENT0, GraphicsContext3D::TEXTURE_2D, 0, 0));
90 GLC(m_context, m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, 0));
91 GLC(m_context, m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, 0));
94 void AcceleratedTextureCopier::flush()
96 GLC(m_context, m_context->flush());
101 #endif // USE(ACCELERATED_COMPOSITING)