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

Side by Side Diff: ui/cc/TextureManager.h

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/TextureLayerChromium.cpp ('k') | ui/cc/TextureManager.cpp » ('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) 2010, 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 #ifndef TextureManager_h
26 #define TextureManager_h
27
28 #include "GraphicsContext3D.h"
29 #include "IntRect.h"
30 #include "IntSize.h"
31 #include <wtf/FastAllocBase.h>
32 #include <wtf/HashMap.h>
33 #include <wtf/HashSet.h>
34 #include <wtf/ListHashSet.h>
35 #include <wtf/Vector.h>
36
37 namespace WebCore {
38
39 class ManagedTexture;
40 typedef int TextureToken;
41
42 class TextureAllocator {
43 public:
44 virtual unsigned createTexture(const IntSize&, GC3Denum format) = 0;
45 virtual void deleteTexture(unsigned texture, const IntSize&, GC3Denum) = 0;
46 virtual void deleteAllTextures() = 0;
47
48 protected:
49 virtual ~TextureAllocator() { }
50 };
51
52 class TextureManager {
53 WTF_MAKE_NONCOPYABLE(TextureManager);
54 public:
55 static PassOwnPtr<TextureManager> create(size_t maxMemoryLimitBytes, size_t preferredMemoryLimitBytes, int maxTextureSize)
56 {
57 return adoptPtr(new TextureManager(maxMemoryLimitBytes, preferredMemoryL imitBytes, maxTextureSize));
58 }
59 ~TextureManager();
60
61 // Absolute maximum limit for texture allocations for this instance.
62 static size_t highLimitBytes(const IntSize& viewportSize);
63 // Preferred texture size limit given the viewport size.
64 static size_t reclaimLimitBytes(const IntSize& viewportSize);
65
66 static size_t memoryUseBytes(const IntSize&, GC3Denum format);
67
68 void setMemoryAllocationLimitBytes(size_t);
69 void setMaxMemoryLimitBytes(size_t);
70 size_t maxMemoryLimitBytes() { return m_maxMemoryLimitBytes; }
71 void setPreferredMemoryLimitBytes(size_t);
72 size_t preferredMemoryLimitBytes() { return m_preferredMemoryLimitBytes; }
73
74 void registerTexture(ManagedTexture*);
75 void unregisterTexture(ManagedTexture*);
76
77 TextureToken getToken();
78 void releaseToken(TextureToken);
79 bool hasTexture(TextureToken);
80
81 bool requestTexture(TextureToken, IntSize, GC3Denum textureFormat);
82
83 void protectTexture(TextureToken);
84 void unprotectTexture(TextureToken);
85 void unprotectAllTextures();
86 bool isProtected(TextureToken);
87
88 unsigned allocateTexture(TextureAllocator*, TextureToken);
89 void deleteEvictedTextures(TextureAllocator*);
90
91 void evictAndRemoveAllDeletedTextures();
92 void evictAndDeleteAllTextures(TextureAllocator*);
93
94 void reduceMemoryToLimit(size_t);
95 size_t currentMemoryUseBytes() const { return m_memoryUseBytes; }
96
97 private:
98 TextureManager(size_t maxMemoryLimitBytes, size_t preferredMemoryLimitBytes, int maxTextureSize);
99
100 struct TextureInfo {
101 IntSize size;
102 GC3Denum format;
103 unsigned textureId;
104 bool isProtected;
105 #ifndef NDEBUG
106 TextureAllocator* allocator;
107 #endif
108 };
109
110 void addTexture(TextureToken, TextureInfo);
111 void removeTexture(TextureToken, TextureInfo);
112 void evictTexture(TextureToken, TextureInfo);
113
114 HashSet<ManagedTexture*> m_registeredTextures;
115
116 typedef HashMap<TextureToken, TextureInfo> TextureMap;
117 TextureMap m_textures;
118 ListHashSet<TextureToken> m_textureLRUSet;
119
120 size_t m_maxMemoryLimitBytes;
121 size_t m_preferredMemoryLimitBytes;
122 size_t m_memoryUseBytes;
123 int m_maxTextureSize;
124 TextureToken m_nextToken;
125
126 struct EvictionEntry {
127 unsigned textureId;
128 IntSize size;
129 GC3Denum format;
130 #ifndef NDEBUG
131 TextureAllocator* allocator;
132 #endif
133 };
134
135 Vector<EvictionEntry> m_evictedTextures;
136 };
137
138 }
139
140 #endif
OLDNEW
« no previous file with comments | « ui/cc/TextureLayerChromium.cpp ('k') | ui/cc/TextureManager.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698