OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CC_PRIORITIZED_TEXTURE_H_ | 5 #ifndef CC_PRIORITIZED_RESOURCE_H_ |
6 #define CC_PRIORITIZED_TEXTURE_H_ | 6 #define CC_PRIORITIZED_RESOURCE_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "cc/cc_export.h" | 11 #include "cc/cc_export.h" |
12 #include "cc/priority_calculator.h" | 12 #include "cc/priority_calculator.h" |
13 #include "cc/resource_provider.h" | 13 #include "cc/resource_provider.h" |
14 #include "cc/texture.h" | 14 #include "cc/texture.h" |
15 #include "ui/gfx/rect.h" | 15 #include "ui/gfx/rect.h" |
16 #include "ui/gfx/size.h" | 16 #include "ui/gfx/size.h" |
17 #include "ui/gfx/vector2d.h" | 17 #include "ui/gfx/vector2d.h" |
18 #include "third_party/khronos/GLES2/gl2.h" | 18 #include "third_party/khronos/GLES2/gl2.h" |
19 | 19 |
20 namespace cc { | 20 namespace cc { |
21 | 21 |
22 class PrioritizedTextureManager; | 22 class PrioritizedResourceManager; |
23 | 23 |
24 class CC_EXPORT PrioritizedTexture { | 24 class CC_EXPORT PrioritizedResource { |
25 public: | 25 public: |
26 static scoped_ptr<PrioritizedTexture> create(PrioritizedTextureManager* mana
ger, gfx::Size size, GLenum format) | 26 static scoped_ptr<PrioritizedResource> create(PrioritizedResourceManager* ma
nager, gfx::Size size, GLenum format) |
27 { | 27 { |
28 return make_scoped_ptr(new PrioritizedTexture(manager, size, format)); | 28 return make_scoped_ptr(new PrioritizedResource(manager, size, format)); |
29 } | 29 } |
30 static scoped_ptr<PrioritizedTexture> create(PrioritizedTextureManager* mana
ger) | 30 static scoped_ptr<PrioritizedResource> create(PrioritizedResourceManager* ma
nager) |
31 { | 31 { |
32 return make_scoped_ptr(new PrioritizedTexture(manager, gfx::Size(), 0)); | 32 return make_scoped_ptr(new PrioritizedResource(manager, gfx::Size(), 0))
; |
33 } | 33 } |
34 ~PrioritizedTexture(); | 34 ~PrioritizedResource(); |
35 | 35 |
36 // Texture properties. Changing these causes the backing texture to be lost. | 36 // Texture properties. Changing these causes the backing texture to be lost. |
37 // Setting these to the same value is a no-op. | 37 // Setting these to the same value is a no-op. |
38 void setTextureManager(PrioritizedTextureManager*); | 38 void setTextureManager(PrioritizedResourceManager*); |
39 PrioritizedTextureManager* textureManager() { return m_manager; } | 39 PrioritizedResourceManager* resourceManager() { return m_manager; } |
40 void setDimensions(gfx::Size, GLenum format); | 40 void setDimensions(gfx::Size, GLenum format); |
41 GLenum format() const { return m_format; } | 41 GLenum format() const { return m_format; } |
42 gfx::Size size() const { return m_size; } | 42 gfx::Size size() const { return m_size; } |
43 size_t bytes() const { return m_bytes; } | 43 size_t bytes() const { return m_bytes; } |
44 bool contentsSwizzled() const { return m_contentsSwizzled; } | 44 bool contentsSwizzled() const { return m_contentsSwizzled; } |
45 | 45 |
46 // Set priority for the requested texture. | 46 // Set priority for the requested texture. |
47 void setRequestPriority(int priority) { m_priority = priority; } | 47 void setRequestPriority(int priority) { m_priority = priority; } |
48 int requestPriority() const { return m_priority; } | 48 int requestPriority() const { return m_priority; } |
49 | 49 |
50 // After PrioritizedTexture::prioritizeTextures() is called, this returns | 50 // After PrioritizedResource::prioritizeTextures() is called, this returns |
51 // if the the request succeeded and this texture can be acquired for use. | 51 // if the the request succeeded and this texture can be acquired for use. |
52 bool canAcquireBackingTexture() const { return m_isAbovePriorityCutoff; } | 52 bool canAcquireBackingTexture() const { return m_isAbovePriorityCutoff; } |
53 | 53 |
54 // This returns whether we still have a backing texture. This can continue | 54 // This returns whether we still have a backing texture. This can continue |
55 // to be true even after canAcquireBackingTexture() becomes false. In this | 55 // to be true even after canAcquireBackingTexture() becomes false. In this |
56 // case the texture can be used but shouldn't be updated since it will get | 56 // case the texture can be used but shouldn't be updated since it will get |
57 // taken away "soon". | 57 // taken away "soon". |
58 bool haveBackingTexture() const { return !!backing(); } | 58 bool haveBackingTexture() const { return !!backing(); } |
59 | 59 |
60 bool backingResourceWasEvicted() const; | 60 bool backingResourceWasEvicted() const; |
(...skipping 20 matching lines...) Expand all Loading... |
81 // but they are not allocated/recycled/deleted, so this needs to be done | 81 // but they are not allocated/recycled/deleted, so this needs to be done |
82 // externally. canAcquireBackingTexture() indicates if the texture would hav
e | 82 // externally. canAcquireBackingTexture() indicates if the texture would hav
e |
83 // been allowed given its priority. | 83 // been allowed given its priority. |
84 void setIsSelfManaged(bool isSelfManaged) { m_isSelfManaged = isSelfManaged;
} | 84 void setIsSelfManaged(bool isSelfManaged) { m_isSelfManaged = isSelfManaged;
} |
85 bool isSelfManaged() { return m_isSelfManaged; } | 85 bool isSelfManaged() { return m_isSelfManaged; } |
86 void setToSelfManagedMemoryPlaceholder(size_t bytes); | 86 void setToSelfManagedMemoryPlaceholder(size_t bytes); |
87 | 87 |
88 void returnBackingTexture(); | 88 void returnBackingTexture(); |
89 | 89 |
90 private: | 90 private: |
91 friend class PrioritizedTextureManager; | 91 friend class PrioritizedResourceManager; |
92 friend class PrioritizedTextureTest; | 92 friend class PrioritizedResourceTest; |
93 | 93 |
94 class Backing : public Texture { | 94 class Backing : public Texture { |
95 public: | 95 public: |
96 Backing(unsigned id, ResourceProvider*, gfx::Size, GLenum format); | 96 Backing(unsigned id, ResourceProvider*, gfx::Size, GLenum format); |
97 ~Backing(); | 97 ~Backing(); |
98 void updatePriority(); | 98 void updatePriority(); |
99 void updateInDrawingImplTree(); | 99 void updateInDrawingImplTree(); |
100 | 100 |
101 PrioritizedTexture* owner() { return m_owner; } | 101 PrioritizedResource* owner() { return m_owner; } |
102 bool canBeRecycled() const; | 102 bool canBeRecycled() const; |
103 int requestPriorityAtLastPriorityUpdate() const { return m_priorityAtLas
tPriorityUpdate; } | 103 int requestPriorityAtLastPriorityUpdate() const { return m_priorityAtLas
tPriorityUpdate; } |
104 bool wasAbovePriorityCutoffAtLastPriorityUpdate() const { return m_wasAb
ovePriorityCutoffAtLastPriorityUpdate; } | 104 bool wasAbovePriorityCutoffAtLastPriorityUpdate() const { return m_wasAb
ovePriorityCutoffAtLastPriorityUpdate; } |
105 bool inDrawingImplTree() const { return m_inDrawingImplTree; } | 105 bool inDrawingImplTree() const { return m_inDrawingImplTree; } |
106 | 106 |
107 void deleteResource(ResourceProvider*); | 107 void deleteResource(ResourceProvider*); |
108 bool resourceHasBeenDeleted() const; | 108 bool resourceHasBeenDeleted() const; |
109 | 109 |
110 private: | 110 private: |
111 friend class PrioritizedTexture; | 111 friend class PrioritizedResource; |
112 PrioritizedTexture* m_owner; | 112 PrioritizedResource* m_owner; |
113 int m_priorityAtLastPriorityUpdate; | 113 int m_priorityAtLastPriorityUpdate; |
114 bool m_wasAbovePriorityCutoffAtLastPriorityUpdate; | 114 bool m_wasAbovePriorityCutoffAtLastPriorityUpdate; |
115 | 115 |
116 // Set if this is currently-drawing impl tree. | 116 // Set if this is currently-drawing impl tree. |
117 bool m_inDrawingImplTree; | 117 bool m_inDrawingImplTree; |
118 | 118 |
119 bool m_resourceHasBeenDeleted; | 119 bool m_resourceHasBeenDeleted; |
120 #ifndef NDEBUG | 120 #ifndef NDEBUG |
121 ResourceProvider* m_resourceProvider; | 121 ResourceProvider* m_resourceProvider; |
122 #endif | 122 #endif |
123 | 123 |
124 DISALLOW_COPY_AND_ASSIGN(Backing); | 124 DISALLOW_COPY_AND_ASSIGN(Backing); |
125 }; | 125 }; |
126 | 126 |
127 PrioritizedTexture(PrioritizedTextureManager*, gfx::Size, GLenum format); | 127 PrioritizedResource(PrioritizedResourceManager*, gfx::Size, GLenum format); |
128 | 128 |
129 bool isAbovePriorityCutoff() { return m_isAbovePriorityCutoff; } | 129 bool isAbovePriorityCutoff() { return m_isAbovePriorityCutoff; } |
130 void setAbovePriorityCutoff(bool isAbovePriorityCutoff) { m_isAbovePriorityC
utoff = isAbovePriorityCutoff; } | 130 void setAbovePriorityCutoff(bool isAbovePriorityCutoff) { m_isAbovePriorityC
utoff = isAbovePriorityCutoff; } |
131 void setManagerInternal(PrioritizedTextureManager* manager) { m_manager = ma
nager; } | 131 void setManagerInternal(PrioritizedResourceManager* manager) { m_manager = m
anager; } |
132 | 132 |
133 Backing* backing() const { return m_backing; } | 133 Backing* backing() const { return m_backing; } |
134 void link(Backing*); | 134 void link(Backing*); |
135 void unlink(); | 135 void unlink(); |
136 | 136 |
137 gfx::Size m_size; | 137 gfx::Size m_size; |
138 GLenum m_format; | 138 GLenum m_format; |
139 size_t m_bytes; | 139 size_t m_bytes; |
140 bool m_contentsSwizzled; | 140 bool m_contentsSwizzled; |
141 | 141 |
142 int m_priority; | 142 int m_priority; |
143 bool m_isAbovePriorityCutoff; | 143 bool m_isAbovePriorityCutoff; |
144 bool m_isSelfManaged; | 144 bool m_isSelfManaged; |
145 | 145 |
146 Backing* m_backing; | 146 Backing* m_backing; |
147 PrioritizedTextureManager* m_manager; | 147 PrioritizedResourceManager* m_manager; |
148 | 148 |
149 DISALLOW_COPY_AND_ASSIGN(PrioritizedTexture); | 149 DISALLOW_COPY_AND_ASSIGN(PrioritizedResource); |
150 }; | 150 }; |
151 | 151 |
152 } // namespace cc | 152 } // namespace cc |
153 | 153 |
154 #endif // CC_PRIORITIZED_TEXTURE_H_ | 154 #endif // CC_PRIORITIZED_RESOURCE_H_ |
OLD | NEW |