Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(809)

Unified Diff: ui/cc/TextureCopier.cpp

Issue 10701016: Initial import attempt, just to play with. Many things disabled/removed (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/cc/TextureCopier.h ('k') | ui/cc/TextureLayerChromium.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/cc/TextureCopier.cpp
diff --git a/ui/cc/TextureCopier.cpp b/ui/cc/TextureCopier.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..f2e2cb0c1e1e326e01294f540c7cd7caa8ee0178
--- /dev/null
+++ b/ui/cc/TextureCopier.cpp
@@ -0,0 +1,121 @@
+/*
+ * Copyright (C) 2012, Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#include "TextureCopier.h"
+
+#include "GraphicsContext3D.h"
+#include "LayerRendererChromium.h" // For the GLC() macro
+#include "TraceEvent.h"
+#include <public/WebGraphicsContext3D.h>
+
+namespace WebCore {
+
+#if USE(ACCELERATED_COMPOSITING)
+AcceleratedTextureCopier::AcceleratedTextureCopier(WebKit::WebGraphicsContext3D* context)
+ : m_context(context)
+{
+ ASSERT(m_context);
+ GLC(m_context, m_fbo = m_context->createFramebuffer());
+ GLC(m_context, m_positionBuffer = m_context->createBuffer());
+
+ static const float kPositions[4][4] = {
+ {-1, -1, 0, 1},
+ { 1, -1, 0, 1},
+ { 1, 1, 0, 1},
+ {-1, 1, 0, 1}
+ };
+
+ GLC(m_context, m_context->bindBuffer(GL_ARRAY_BUFFER, m_positionBuffer));
+ GLC(m_context, m_context->bufferData(GL_ARRAY_BUFFER, sizeof(kPositions), kPositions, GL_STATIC_DRAW));
+ GLC(m_context, m_context->bindBuffer(GL_ARRAY_BUFFER, 0));
+
+ m_blitProgram = adoptPtr(new BlitProgram(m_context));
+}
+
+AcceleratedTextureCopier::~AcceleratedTextureCopier()
+{
+ if (m_blitProgram)
+ m_blitProgram->cleanup(m_context);
+ if (m_positionBuffer)
+ GLC(m_context, m_context->deleteBuffer(m_positionBuffer));
+ if (m_fbo)
+ GLC(m_context, m_context->deleteFramebuffer(m_fbo));
+}
+
+void AcceleratedTextureCopier::copyTexture(CCGraphicsContext* ccContext, unsigned sourceTextureId, unsigned destTextureId, const IntSize& size)
+{
+ TRACE_EVENT0("cc", "TextureCopier::copyTexture");
+
+ WebKit::WebGraphicsContext3D* context = ccContext->context3D();
+ if (!context) {
+ // FIXME: Implement this path for software compositing.
+ return;
+ }
+
+ // Note: this code does not restore the viewport, bound program, 2D texture, framebuffer, buffer or blend enable.
+ GLC(context, context->bindFramebuffer(GL_FRAMEBUFFER, m_fbo));
+ GLC(context, context->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, destTextureId, 0));
+
+#if OS(ANDROID)
+ // Clear destination to improve performance on tiling GPUs.
+ // TODO: Use EXT_discard_framebuffer or skip clearing if it isn't available.
+ GLC(context, context->clear(GL_COLOR_BUFFER_BIT));
+#endif
+
+ GLC(context, context->bindTexture(GL_TEXTURE_2D, sourceTextureId));
+ GLC(context, context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
+ GLC(context, context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
+
+ if (!m_blitProgram->initialized())
+ m_blitProgram->initialize(context);
+
+ // TODO: Use EXT_framebuffer_blit if available.
+ GLC(context, context->useProgram(m_blitProgram->program()));
+
+ const int kPositionAttribute = 0;
+ GLC(context, context->bindBuffer(GL_ARRAY_BUFFER, m_positionBuffer));
+ GLC(context, context->vertexAttribPointer(kPositionAttribute, 4, GL_FLOAT, false, 0, 0));
+ GLC(context, context->enableVertexAttribArray(kPositionAttribute));
+ GLC(context, context->bindBuffer(GL_ARRAY_BUFFER, 0));
+
+ GLC(context, context->viewport(0, 0, size.width(), size.height()));
+ GLC(context, context->disable(GL_BLEND));
+ GLC(context, context->drawArrays(GL_TRIANGLE_FAN, 0, 4));
+
+ GLC(context, context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
+ GLC(context, context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
+ GLC(context, context->disableVertexAttribArray(kPositionAttribute));
+
+ GLC(context, context->useProgram(0));
+
+ GLC(context, context->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0));
+ GLC(context, context->bindFramebuffer(GL_FRAMEBUFFER, 0));
+ GLC(context, context->bindTexture(GL_TEXTURE_2D, 0));
+}
+
+}
+
+#endif // USE(ACCELERATED_COMPOSITING)
« no previous file with comments | « ui/cc/TextureCopier.h ('k') | ui/cc/TextureLayerChromium.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698