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 CCPrioritizedTexture_h | 5 #ifndef CCPrioritizedTexture_h |
6 #define CCPrioritizedTexture_h | 6 #define CCPrioritizedTexture_h |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "CCPriorityCalculator.h" | 10 #include "CCPriorityCalculator.h" |
11 #include "CCResourceProvider.h" | 11 #include "CCResourceProvider.h" |
12 #include "CCTexture.h" | 12 #include "CCTexture.h" |
13 #include "GraphicsContext3D.h" | 13 #include "GraphicsContext3D.h" |
14 #include "IntRect.h" | 14 #include "IntRect.h" |
15 #include "IntSize.h" | 15 #include "IntSize.h" |
16 | 16 |
17 namespace cc { | 17 namespace cc { |
18 | 18 |
19 class CCPrioritizedTextureManager; | 19 class PrioritizedTextureManager; |
20 | 20 |
21 class CCPrioritizedTexture { | 21 class PrioritizedTexture { |
22 public: | 22 public: |
23 static scoped_ptr<CCPrioritizedTexture> create(CCPrioritizedTextureManager*
manager, IntSize size, GC3Denum format) | 23 static scoped_ptr<PrioritizedTexture> create(PrioritizedTextureManager* mana
ger, IntSize size, GC3Denum format) |
24 { | 24 { |
25 return make_scoped_ptr(new CCPrioritizedTexture(manager, size, format)); | 25 return make_scoped_ptr(new PrioritizedTexture(manager, size, format)); |
26 } | 26 } |
27 static scoped_ptr<CCPrioritizedTexture> create(CCPrioritizedTextureManager*
manager) | 27 static scoped_ptr<PrioritizedTexture> create(PrioritizedTextureManager* mana
ger) |
28 { | 28 { |
29 return make_scoped_ptr(new CCPrioritizedTexture(manager, IntSize(), 0)); | 29 return make_scoped_ptr(new PrioritizedTexture(manager, IntSize(), 0)); |
30 } | 30 } |
31 ~CCPrioritizedTexture(); | 31 ~PrioritizedTexture(); |
32 | 32 |
33 // Texture properties. Changing these causes the backing texture to be lost. | 33 // Texture properties. Changing these causes the backing texture to be lost. |
34 // Setting these to the same value is a no-op. | 34 // Setting these to the same value is a no-op. |
35 void setTextureManager(CCPrioritizedTextureManager*); | 35 void setTextureManager(PrioritizedTextureManager*); |
36 CCPrioritizedTextureManager* textureManager() { return m_manager; } | 36 PrioritizedTextureManager* textureManager() { return m_manager; } |
37 void setDimensions(IntSize, GC3Denum format); | 37 void setDimensions(IntSize, GC3Denum format); |
38 GC3Denum format() const { return m_format; } | 38 GC3Denum format() const { return m_format; } |
39 IntSize size() const { return m_size; } | 39 IntSize size() const { return m_size; } |
40 size_t bytes() const { return m_bytes; } | 40 size_t bytes() const { return m_bytes; } |
41 | 41 |
42 // Set priority for the requested texture. | 42 // Set priority for the requested texture. |
43 void setRequestPriority(int priority) { m_priority = priority; } | 43 void setRequestPriority(int priority) { m_priority = priority; } |
44 int requestPriority() const { return m_priority; } | 44 int requestPriority() const { return m_priority; } |
45 | 45 |
46 // After CCPrioritizedTexture::prioritizeTextures() is called, this returns | 46 // After PrioritizedTexture::prioritizeTextures() is called, this returns |
47 // if the the request succeeded and this texture can be acquired for use. | 47 // if the the request succeeded and this texture can be acquired for use. |
48 bool canAcquireBackingTexture() const { return m_isAbovePriorityCutoff; } | 48 bool canAcquireBackingTexture() const { return m_isAbovePriorityCutoff; } |
49 | 49 |
50 // This returns whether we still have a backing texture. This can continue | 50 // This returns whether we still have a backing texture. This can continue |
51 // to be true even after canAcquireBackingTexture() becomes false. In this | 51 // to be true even after canAcquireBackingTexture() becomes false. In this |
52 // case the texture can be used but shouldn't be updated since it will get | 52 // case the texture can be used but shouldn't be updated since it will get |
53 // taken away "soon". | 53 // taken away "soon". |
54 bool haveBackingTexture() const { return !!backing(); } | 54 bool haveBackingTexture() const { return !!backing(); } |
55 | 55 |
56 bool backingResourceWasEvicted() const; | 56 bool backingResourceWasEvicted() const; |
57 | 57 |
58 // If canAcquireBackingTexture() is true acquireBackingTexture() will acquir
e | 58 // If canAcquireBackingTexture() is true acquireBackingTexture() will acquir
e |
59 // a backing texture for use. Call this whenever the texture is actually nee
ded. | 59 // a backing texture for use. Call this whenever the texture is actually nee
ded. |
60 void acquireBackingTexture(CCResourceProvider*); | 60 void acquireBackingTexture(ResourceProvider*); |
61 | 61 |
62 // FIXME: Request late is really a hack for when we are totally out of memor
y | 62 // FIXME: Request late is really a hack for when we are totally out of memor
y |
63 // (all textures are visible) but we can still squeeze into the limit | 63 // (all textures are visible) but we can still squeeze into the limit |
64 // by not painting occluded textures. In this case the manager | 64 // by not painting occluded textures. In this case the manager |
65 // refuses all visible textures and requestLate() will enable | 65 // refuses all visible textures and requestLate() will enable |
66 // canAcquireBackingTexture() on a call-order basis. We might want to | 66 // canAcquireBackingTexture() on a call-order basis. We might want to |
67 // just remove this in the future (carefully) and just make sure we d
on't | 67 // just remove this in the future (carefully) and just make sure we d
on't |
68 // regress OOMs situations. | 68 // regress OOMs situations. |
69 bool requestLate(); | 69 bool requestLate(); |
70 | 70 |
71 // Uploads pixels into the backing resource. This functions will aquire the
backing if needed. | 71 // Uploads pixels into the backing resource. This functions will aquire the
backing if needed. |
72 void upload(CCResourceProvider*, const uint8_t* image, const IntRect& imageR
ect, const IntRect& sourceRect, const IntSize& destOffset); | 72 void upload(ResourceProvider*, const uint8_t* image, const IntRect& imageRec
t, const IntRect& sourceRect, const IntSize& destOffset); |
73 | 73 |
74 CCResourceProvider::ResourceId resourceId() const; | 74 ResourceProvider::ResourceId resourceId() const; |
75 | 75 |
76 // Self-managed textures are accounted for when prioritizing other textures, | 76 // Self-managed textures are accounted for when prioritizing other textures, |
77 // but they are not allocated/recycled/deleted, so this needs to be done | 77 // but they are not allocated/recycled/deleted, so this needs to be done |
78 // externally. canAcquireBackingTexture() indicates if the texture would hav
e | 78 // externally. canAcquireBackingTexture() indicates if the texture would hav
e |
79 // been allowed given its priority. | 79 // been allowed given its priority. |
80 void setIsSelfManaged(bool isSelfManaged) { m_isSelfManaged = isSelfManaged;
} | 80 void setIsSelfManaged(bool isSelfManaged) { m_isSelfManaged = isSelfManaged;
} |
81 bool isSelfManaged() { return m_isSelfManaged; } | 81 bool isSelfManaged() { return m_isSelfManaged; } |
82 void setToSelfManagedMemoryPlaceholder(size_t bytes); | 82 void setToSelfManagedMemoryPlaceholder(size_t bytes); |
83 | 83 |
84 private: | 84 private: |
85 friend class CCPrioritizedTextureManager; | 85 friend class PrioritizedTextureManager; |
86 friend class CCPrioritizedTextureTest; | 86 friend class PrioritizedTextureTest; |
87 | 87 |
88 class Backing : public CCTexture { | 88 class Backing : public Texture { |
89 public: | 89 public: |
90 Backing(unsigned id, CCResourceProvider*, IntSize, GC3Denum format); | 90 Backing(unsigned id, ResourceProvider*, IntSize, GC3Denum format); |
91 ~Backing(); | 91 ~Backing(); |
92 void updatePriority(); | 92 void updatePriority(); |
93 void updateInDrawingImplTree(); | 93 void updateInDrawingImplTree(); |
94 | 94 |
95 CCPrioritizedTexture* owner() { return m_owner; } | 95 PrioritizedTexture* owner() { return m_owner; } |
96 bool canBeRecycled() const; | 96 bool canBeRecycled() const; |
97 int requestPriorityAtLastPriorityUpdate() const { return m_priorityAtLas
tPriorityUpdate; } | 97 int requestPriorityAtLastPriorityUpdate() const { return m_priorityAtLas
tPriorityUpdate; } |
98 bool wasAbovePriorityCutoffAtLastPriorityUpdate() const { return m_wasAb
ovePriorityCutoffAtLastPriorityUpdate; } | 98 bool wasAbovePriorityCutoffAtLastPriorityUpdate() const { return m_wasAb
ovePriorityCutoffAtLastPriorityUpdate; } |
99 bool inDrawingImplTree() const { return m_inDrawingImplTree; } | 99 bool inDrawingImplTree() const { return m_inDrawingImplTree; } |
100 | 100 |
101 void deleteResource(CCResourceProvider*); | 101 void deleteResource(ResourceProvider*); |
102 bool resourceHasBeenDeleted() const; | 102 bool resourceHasBeenDeleted() const; |
103 | 103 |
104 private: | 104 private: |
105 friend class CCPrioritizedTexture; | 105 friend class PrioritizedTexture; |
106 CCPrioritizedTexture* m_owner; | 106 PrioritizedTexture* m_owner; |
107 int m_priorityAtLastPriorityUpdate; | 107 int m_priorityAtLastPriorityUpdate; |
108 bool m_wasAbovePriorityCutoffAtLastPriorityUpdate; | 108 bool m_wasAbovePriorityCutoffAtLastPriorityUpdate; |
109 | 109 |
110 // Set if this is currently-drawing impl tree. | 110 // Set if this is currently-drawing impl tree. |
111 bool m_inDrawingImplTree; | 111 bool m_inDrawingImplTree; |
112 | 112 |
113 bool m_resourceHasBeenDeleted; | 113 bool m_resourceHasBeenDeleted; |
114 #ifndef NDEBUG | 114 #ifndef NDEBUG |
115 CCResourceProvider* m_resourceProvider; | 115 ResourceProvider* m_resourceProvider; |
116 #endif | 116 #endif |
117 | 117 |
118 DISALLOW_COPY_AND_ASSIGN(Backing); | 118 DISALLOW_COPY_AND_ASSIGN(Backing); |
119 }; | 119 }; |
120 | 120 |
121 CCPrioritizedTexture(CCPrioritizedTextureManager*, IntSize, GC3Denum format)
; | 121 PrioritizedTexture(PrioritizedTextureManager*, IntSize, GC3Denum format); |
122 | 122 |
123 bool isAbovePriorityCutoff() { return m_isAbovePriorityCutoff; } | 123 bool isAbovePriorityCutoff() { return m_isAbovePriorityCutoff; } |
124 void setAbovePriorityCutoff(bool isAbovePriorityCutoff) { m_isAbovePriorityC
utoff = isAbovePriorityCutoff; } | 124 void setAbovePriorityCutoff(bool isAbovePriorityCutoff) { m_isAbovePriorityC
utoff = isAbovePriorityCutoff; } |
125 void setManagerInternal(CCPrioritizedTextureManager* manager) { m_manager =
manager; } | 125 void setManagerInternal(PrioritizedTextureManager* manager) { m_manager = ma
nager; } |
126 | 126 |
127 Backing* backing() const { return m_backing; } | 127 Backing* backing() const { return m_backing; } |
128 void link(Backing*); | 128 void link(Backing*); |
129 void unlink(); | 129 void unlink(); |
130 | 130 |
131 IntSize m_size; | 131 IntSize m_size; |
132 GC3Denum m_format; | 132 GC3Denum m_format; |
133 size_t m_bytes; | 133 size_t m_bytes; |
134 | 134 |
135 int m_priority; | 135 int m_priority; |
136 bool m_isAbovePriorityCutoff; | 136 bool m_isAbovePriorityCutoff; |
137 bool m_isSelfManaged; | 137 bool m_isSelfManaged; |
138 | 138 |
139 Backing* m_backing; | 139 Backing* m_backing; |
140 CCPrioritizedTextureManager* m_manager; | 140 PrioritizedTextureManager* m_manager; |
141 | 141 |
142 DISALLOW_COPY_AND_ASSIGN(CCPrioritizedTexture); | 142 DISALLOW_COPY_AND_ASSIGN(PrioritizedTexture); |
143 }; | 143 }; |
144 | 144 |
145 } // namespace cc | 145 } // namespace cc |
146 | 146 |
147 #endif | 147 #endif |
OLD | NEW |