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

Unified Diff: ui/cc/TrackingTextureAllocator.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/TrackingTextureAllocator.h ('k') | ui/cc/TreeSynchronizer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/cc/TrackingTextureAllocator.cpp
diff --git a/ui/cc/TrackingTextureAllocator.cpp b/ui/cc/TrackingTextureAllocator.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..427966763a6ee45be4696f90c235a2cd12d39be2
--- /dev/null
+++ b/ui/cc/TrackingTextureAllocator.cpp
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2011, 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 "TrackingTextureAllocator.h"
+
+#include "Extensions3DChromium.h"
+#include "GraphicsContext3D.h"
+#include "IntRect.h"
+#include "LayerRendererChromium.h" // For the GLC() macro
+
+namespace WebCore {
+
+TrackingTextureAllocator::TrackingTextureAllocator(WebKit::WebGraphicsContext3D* context)
+ : m_context(context)
+ , m_currentMemoryUseBytes(0)
+ , m_textureUsageHint(Any)
+ , m_useTextureStorageExt(false)
+{
+ ASSERT(m_context);
+}
+
+TrackingTextureAllocator::~TrackingTextureAllocator()
+{
+ ASSERT(!m_currentMemoryUseBytes);
+}
+
+static GC3Denum textureToStorageFormat(GC3Denum textureFormat)
+{
+ GC3Denum storageFormat = GL_RGBA8_OES;
+ switch (textureFormat) {
+ case GL_RGBA:
+ break;
+ case GL_BGRA_EXT:
+ storageFormat = GL_BGRA8_EXT;
+ break;
+ default:
+ ASSERT_NOT_REACHED();
+ break;
+ }
+
+ return storageFormat;
+}
+
+static bool isTextureFormatSupportedForStorage(GC3Denum format)
+{
+ return (format == GL_RGBA || format == GL_BGRA_EXT);
+}
+
+unsigned TrackingTextureAllocator::createTexture(const IntSize& size, GC3Denum format)
+{
+ m_currentMemoryUseBytes += TextureManager::memoryUseBytes(size, format);
+
+ unsigned textureId = 0;
+ GLC(m_context, textureId = m_context->createTexture());
+ GLC(m_context, m_context->bindTexture(GL_TEXTURE_2D, textureId));
+ // Do basic linear filtering on resize.
+ GLC(m_context, m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
+ GLC(m_context, m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
+ // NPOT textures in GL ES only work when the wrap mode is set to GL_CLAMP_TO_EDGE.
+ GLC(m_context, m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
+ GLC(m_context, m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
+
+ if (m_textureUsageHint == FramebufferAttachment)
+ GLC(m_context, m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_USAGE_ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE));
+ if (m_useTextureStorageExt && isTextureFormatSupportedForStorage(format)) {
+ GC3Denum storageFormat = textureToStorageFormat(format);
+ m_context->texStorage2DEXT(GL_TEXTURE_2D, 1, storageFormat, size.width(), size.height());
+ } else
+ GLC(m_context, m_context->texImage2D(GL_TEXTURE_2D, 0, format, size.width(), size.height(), 0, format, GL_UNSIGNED_BYTE, 0));
+ m_allocatedTextureIds.add(textureId);
+ return textureId;
+}
+
+void TrackingTextureAllocator::deleteTexture(unsigned textureId, const IntSize& size, GC3Denum format)
+{
+ m_currentMemoryUseBytes -= TextureManager::memoryUseBytes(size, format);
+ GLC(m_context, m_context->deleteTexture(textureId));
+ GLC(m_context, m_context->deleteTexture(textureId));
+ ASSERT(m_allocatedTextureIds.contains(textureId));
+ m_allocatedTextureIds.remove(textureId);
+}
+
+void TrackingTextureAllocator::deleteAllTextures()
+{
+ for (HashSet<unsigned>::const_iterator it = m_allocatedTextureIds.begin(); it != m_allocatedTextureIds.end(); ++it)
+ GLC(m_context, m_context->deleteTexture(*it));
+ m_currentMemoryUseBytes = 0;
+ m_allocatedTextureIds.clear();
+}
+
+}
+
« no previous file with comments | « ui/cc/TrackingTextureAllocator.h ('k') | ui/cc/TreeSynchronizer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698