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 // Temporary forwarding header |
6 #define CCPrioritizedTexture_h | 6 #include "cc/prioritized_texture.h" |
7 | |
8 #include "base/basictypes.h" | |
9 #include "base/memory/scoped_ptr.h" | |
10 #include "CCPriorityCalculator.h" | |
11 #include "CCResourceProvider.h" | |
12 #include "CCTexture.h" | |
13 #include "GraphicsContext3D.h" | |
14 #include "IntRect.h" | |
15 #include "IntSize.h" | |
16 | |
17 namespace cc { | |
18 | |
19 class CCPrioritizedTextureManager; | |
20 | |
21 class CCPrioritizedTexture { | |
22 public: | |
23 static scoped_ptr<CCPrioritizedTexture> create(CCPrioritizedTextureManager*
manager, IntSize size, GC3Denum format) | |
24 { | |
25 return make_scoped_ptr(new CCPrioritizedTexture(manager, size, format)); | |
26 } | |
27 static scoped_ptr<CCPrioritizedTexture> create(CCPrioritizedTextureManager*
manager) | |
28 { | |
29 return make_scoped_ptr(new CCPrioritizedTexture(manager, IntSize(), 0)); | |
30 } | |
31 ~CCPrioritizedTexture(); | |
32 | |
33 // Texture properties. Changing these causes the backing texture to be lost. | |
34 // Setting these to the same value is a no-op. | |
35 void setTextureManager(CCPrioritizedTextureManager*); | |
36 CCPrioritizedTextureManager* textureManager() { return m_manager; } | |
37 void setDimensions(IntSize, GC3Denum format); | |
38 GC3Denum format() const { return m_format; } | |
39 IntSize size() const { return m_size; } | |
40 size_t bytes() const { return m_bytes; } | |
41 | |
42 // Set priority for the requested texture. | |
43 void setRequestPriority(int priority) { m_priority = priority; } | |
44 int requestPriority() const { return m_priority; } | |
45 | |
46 // After CCPrioritizedTexture::prioritizeTextures() is called, this returns | |
47 // if the the request succeeded and this texture can be acquired for use. | |
48 bool canAcquireBackingTexture() const { return m_isAbovePriorityCutoff; } | |
49 | |
50 // This returns whether we still have a backing texture. This can continue | |
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 | |
53 // taken away "soon". | |
54 bool haveBackingTexture() const { return !!backing(); } | |
55 | |
56 bool backingResourceWasEvicted() const; | |
57 | |
58 // If canAcquireBackingTexture() is true acquireBackingTexture() will acquir
e | |
59 // a backing texture for use. Call this whenever the texture is actually nee
ded. | |
60 void acquireBackingTexture(CCResourceProvider*); | |
61 | |
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 | |
64 // by not painting occluded textures. In this case the manager | |
65 // refuses all visible textures and requestLate() will enable | |
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 | |
68 // regress OOMs situations. | |
69 bool requestLate(); | |
70 | |
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); | |
73 | |
74 CCResourceProvider::ResourceId resourceId() const; | |
75 | |
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 | |
78 // externally. canAcquireBackingTexture() indicates if the texture would hav
e | |
79 // been allowed given its priority. | |
80 void setIsSelfManaged(bool isSelfManaged) { m_isSelfManaged = isSelfManaged;
} | |
81 bool isSelfManaged() { return m_isSelfManaged; } | |
82 void setToSelfManagedMemoryPlaceholder(size_t bytes); | |
83 | |
84 private: | |
85 friend class CCPrioritizedTextureManager; | |
86 friend class CCPrioritizedTextureTest; | |
87 | |
88 class Backing : public CCTexture { | |
89 public: | |
90 Backing(unsigned id, CCResourceProvider*, IntSize, GC3Denum format); | |
91 ~Backing(); | |
92 void updatePriority(); | |
93 | |
94 CCPrioritizedTexture* owner() { return m_owner; } | |
95 bool hadOwnerAtLastPriorityUpdate() const { return m_ownerExistedAtLastP
riorityUpdate; } | |
96 int requestPriorityAtLastPriorityUpdate() const { return m_priorityAtLas
tPriorityUpdate; } | |
97 bool wasAbovePriorityCutoffAtLastPriorityUpdate() const { return m_wasAb
ovePriorityCutoffAtLastPriorityUpdate; } | |
98 | |
99 void deleteResource(CCResourceProvider*); | |
100 bool resourceHasBeenDeleted() const; | |
101 | |
102 private: | |
103 friend class CCPrioritizedTexture; | |
104 CCPrioritizedTexture* m_owner; | |
105 int m_priorityAtLastPriorityUpdate; | |
106 bool m_ownerExistedAtLastPriorityUpdate; | |
107 bool m_wasAbovePriorityCutoffAtLastPriorityUpdate; | |
108 bool m_resourceHasBeenDeleted; | |
109 #ifndef NDEBUG | |
110 CCResourceProvider* m_resourceProvider; | |
111 #endif | |
112 | |
113 DISALLOW_COPY_AND_ASSIGN(Backing); | |
114 }; | |
115 | |
116 CCPrioritizedTexture(CCPrioritizedTextureManager*, IntSize, GC3Denum format)
; | |
117 | |
118 bool isAbovePriorityCutoff() { return m_isAbovePriorityCutoff; } | |
119 void setAbovePriorityCutoff(bool isAbovePriorityCutoff) { m_isAbovePriorityC
utoff = isAbovePriorityCutoff; } | |
120 void setManagerInternal(CCPrioritizedTextureManager* manager) { m_manager =
manager; } | |
121 | |
122 Backing* backing() const { return m_backing; } | |
123 void link(Backing*); | |
124 void unlink(); | |
125 | |
126 IntSize m_size; | |
127 GC3Denum m_format; | |
128 size_t m_bytes; | |
129 | |
130 int m_priority; | |
131 bool m_isAbovePriorityCutoff; | |
132 bool m_isSelfManaged; | |
133 | |
134 Backing* m_backing; | |
135 CCPrioritizedTextureManager* m_manager; | |
136 | |
137 DISALLOW_COPY_AND_ASSIGN(CCPrioritizedTexture); | |
138 }; | |
139 | |
140 } // namespace cc | |
141 | |
142 #endif | |
OLD | NEW |