OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (C) 2012, Google Inc. All rights reserved. |
| 3 * |
| 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions |
| 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the |
| 11 * documentation and/or other materials provided with the distribution. |
| 12 * |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y |
| 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N |
| 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 23 */ |
| 24 |
| 25 #include "config.h" |
| 26 |
| 27 #include "TextureCopier.h" |
| 28 |
| 29 #include "GraphicsContext3D.h" |
| 30 #include "LayerRendererChromium.h" // For the GLC() macro |
| 31 #include "TraceEvent.h" |
| 32 #include <public/WebGraphicsContext3D.h> |
| 33 |
| 34 namespace WebCore { |
| 35 |
| 36 #if USE(ACCELERATED_COMPOSITING) |
| 37 AcceleratedTextureCopier::AcceleratedTextureCopier(WebKit::WebGraphicsContext3D*
context) |
| 38 : m_context(context) |
| 39 { |
| 40 ASSERT(m_context); |
| 41 GLC(m_context, m_fbo = m_context->createFramebuffer()); |
| 42 GLC(m_context, m_positionBuffer = m_context->createBuffer()); |
| 43 |
| 44 static const float kPositions[4][4] = { |
| 45 {-1, -1, 0, 1}, |
| 46 { 1, -1, 0, 1}, |
| 47 { 1, 1, 0, 1}, |
| 48 {-1, 1, 0, 1} |
| 49 }; |
| 50 |
| 51 GLC(m_context, m_context->bindBuffer(GL_ARRAY_BUFFER, m_positionBuffer)); |
| 52 GLC(m_context, m_context->bufferData(GL_ARRAY_BUFFER, sizeof(kPositions), kP
ositions, GL_STATIC_DRAW)); |
| 53 GLC(m_context, m_context->bindBuffer(GL_ARRAY_BUFFER, 0)); |
| 54 |
| 55 m_blitProgram = adoptPtr(new BlitProgram(m_context)); |
| 56 } |
| 57 |
| 58 AcceleratedTextureCopier::~AcceleratedTextureCopier() |
| 59 { |
| 60 if (m_blitProgram) |
| 61 m_blitProgram->cleanup(m_context); |
| 62 if (m_positionBuffer) |
| 63 GLC(m_context, m_context->deleteBuffer(m_positionBuffer)); |
| 64 if (m_fbo) |
| 65 GLC(m_context, m_context->deleteFramebuffer(m_fbo)); |
| 66 } |
| 67 |
| 68 void AcceleratedTextureCopier::copyTexture(CCGraphicsContext* ccContext, unsigne
d sourceTextureId, unsigned destTextureId, const IntSize& size) |
| 69 { |
| 70 TRACE_EVENT0("cc", "TextureCopier::copyTexture"); |
| 71 |
| 72 WebKit::WebGraphicsContext3D* context = ccContext->context3D(); |
| 73 if (!context) { |
| 74 // FIXME: Implement this path for software compositing. |
| 75 return; |
| 76 } |
| 77 |
| 78 // Note: this code does not restore the viewport, bound program, 2D texture,
framebuffer, buffer or blend enable. |
| 79 GLC(context, context->bindFramebuffer(GL_FRAMEBUFFER, m_fbo)); |
| 80 GLC(context, context->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHME
NT0, GL_TEXTURE_2D, destTextureId, 0)); |
| 81 |
| 82 #if OS(ANDROID) |
| 83 // Clear destination to improve performance on tiling GPUs. |
| 84 // TODO: Use EXT_discard_framebuffer or skip clearing if it isn't available. |
| 85 GLC(context, context->clear(GL_COLOR_BUFFER_BIT)); |
| 86 #endif |
| 87 |
| 88 GLC(context, context->bindTexture(GL_TEXTURE_2D, sourceTextureId)); |
| 89 GLC(context, context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL
_NEAREST)); |
| 90 GLC(context, context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL
_NEAREST)); |
| 91 |
| 92 if (!m_blitProgram->initialized()) |
| 93 m_blitProgram->initialize(context); |
| 94 |
| 95 // TODO: Use EXT_framebuffer_blit if available. |
| 96 GLC(context, context->useProgram(m_blitProgram->program())); |
| 97 |
| 98 const int kPositionAttribute = 0; |
| 99 GLC(context, context->bindBuffer(GL_ARRAY_BUFFER, m_positionBuffer)); |
| 100 GLC(context, context->vertexAttribPointer(kPositionAttribute, 4, GL_FLOAT, f
alse, 0, 0)); |
| 101 GLC(context, context->enableVertexAttribArray(kPositionAttribute)); |
| 102 GLC(context, context->bindBuffer(GL_ARRAY_BUFFER, 0)); |
| 103 |
| 104 GLC(context, context->viewport(0, 0, size.width(), size.height())); |
| 105 GLC(context, context->disable(GL_BLEND)); |
| 106 GLC(context, context->drawArrays(GL_TRIANGLE_FAN, 0, 4)); |
| 107 |
| 108 GLC(context, context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL
_LINEAR)); |
| 109 GLC(context, context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL
_LINEAR)); |
| 110 GLC(context, context->disableVertexAttribArray(kPositionAttribute)); |
| 111 |
| 112 GLC(context, context->useProgram(0)); |
| 113 |
| 114 GLC(context, context->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHME
NT0, GL_TEXTURE_2D, 0, 0)); |
| 115 GLC(context, context->bindFramebuffer(GL_FRAMEBUFFER, 0)); |
| 116 GLC(context, context->bindTexture(GL_TEXTURE_2D, 0)); |
| 117 } |
| 118 |
| 119 } |
| 120 |
| 121 #endif // USE(ACCELERATED_COMPOSITING) |
OLD | NEW |