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

Side by Side 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, 5 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/cc/TrackingTextureAllocator.h ('k') | ui/cc/TreeSynchronizer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2011, 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 "TrackingTextureAllocator.h"
28
29 #include "Extensions3DChromium.h"
30 #include "GraphicsContext3D.h"
31 #include "IntRect.h"
32 #include "LayerRendererChromium.h" // For the GLC() macro
33
34 namespace WebCore {
35
36 TrackingTextureAllocator::TrackingTextureAllocator(WebKit::WebGraphicsContext3D* context)
37 : m_context(context)
38 , m_currentMemoryUseBytes(0)
39 , m_textureUsageHint(Any)
40 , m_useTextureStorageExt(false)
41 {
42 ASSERT(m_context);
43 }
44
45 TrackingTextureAllocator::~TrackingTextureAllocator()
46 {
47 ASSERT(!m_currentMemoryUseBytes);
48 }
49
50 static GC3Denum textureToStorageFormat(GC3Denum textureFormat)
51 {
52 GC3Denum storageFormat = GL_RGBA8_OES;
53 switch (textureFormat) {
54 case GL_RGBA:
55 break;
56 case GL_BGRA_EXT:
57 storageFormat = GL_BGRA8_EXT;
58 break;
59 default:
60 ASSERT_NOT_REACHED();
61 break;
62 }
63
64 return storageFormat;
65 }
66
67 static bool isTextureFormatSupportedForStorage(GC3Denum format)
68 {
69 return (format == GL_RGBA || format == GL_BGRA_EXT);
70 }
71
72 unsigned TrackingTextureAllocator::createTexture(const IntSize& size, GC3Denum f ormat)
73 {
74 m_currentMemoryUseBytes += TextureManager::memoryUseBytes(size, format);
75
76 unsigned textureId = 0;
77 GLC(m_context, textureId = m_context->createTexture());
78 GLC(m_context, m_context->bindTexture(GL_TEXTURE_2D, textureId));
79 // Do basic linear filtering on resize.
80 GLC(m_context, m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER , GL_LINEAR));
81 GLC(m_context, m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER , GL_LINEAR));
82 // NPOT textures in GL ES only work when the wrap mode is set to GL_CLAMP_TO _EDGE.
83 GLC(m_context, m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL _CLAMP_TO_EDGE));
84 GLC(m_context, m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL _CLAMP_TO_EDGE));
85
86 if (m_textureUsageHint == FramebufferAttachment)
87 GLC(m_context, m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_USAGE_ ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE));
88 if (m_useTextureStorageExt && isTextureFormatSupportedForStorage(format)) {
89 GC3Denum storageFormat = textureToStorageFormat(format);
90 m_context->texStorage2DEXT(GL_TEXTURE_2D, 1, storageFormat, size.width() , size.height());
91 } else
92 GLC(m_context, m_context->texImage2D(GL_TEXTURE_2D, 0, format, size.widt h(), size.height(), 0, format, GL_UNSIGNED_BYTE, 0));
93 m_allocatedTextureIds.add(textureId);
94 return textureId;
95 }
96
97 void TrackingTextureAllocator::deleteTexture(unsigned textureId, const IntSize& size, GC3Denum format)
98 {
99 m_currentMemoryUseBytes -= TextureManager::memoryUseBytes(size, format);
100 GLC(m_context, m_context->deleteTexture(textureId));
101 GLC(m_context, m_context->deleteTexture(textureId));
102 ASSERT(m_allocatedTextureIds.contains(textureId));
103 m_allocatedTextureIds.remove(textureId);
104 }
105
106 void TrackingTextureAllocator::deleteAllTextures()
107 {
108 for (HashSet<unsigned>::const_iterator it = m_allocatedTextureIds.begin(); i t != m_allocatedTextureIds.end(); ++it)
109 GLC(m_context, m_context->deleteTexture(*it));
110 m_currentMemoryUseBytes = 0;
111 m_allocatedTextureIds.clear();
112 }
113
114 }
115
OLDNEW
« 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