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 #include "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "CCPrioritizedTexture.h" | 7 #include "CCPrioritizedTexture.h" |
8 | 8 |
9 #include "CCPrioritizedTextureManager.h" | 9 #include "CCPrioritizedTextureManager.h" |
10 #include "CCPriorityCalculator.h" | 10 #include "CCPriorityCalculator.h" |
11 #include "CCProxy.h" | 11 #include "CCProxy.h" |
12 #include <algorithm> | 12 #include <algorithm> |
13 | 13 |
14 using namespace std; | 14 using namespace std; |
15 | 15 |
16 namespace cc { | 16 namespace cc { |
17 | 17 |
18 CCPrioritizedTexture::CCPrioritizedTexture(CCPrioritizedTextureManager* manager,
IntSize size, GC3Denum format) | 18 PrioritizedTexture::PrioritizedTexture(PrioritizedTextureManager* manager, IntSi
ze size, GC3Denum format) |
19 : m_size(size) | 19 : m_size(size) |
20 , m_format(format) | 20 , m_format(format) |
21 , m_bytes(0) | 21 , m_bytes(0) |
22 , m_priority(CCPriorityCalculator::lowestPriority()) | 22 , m_priority(PriorityCalculator::lowestPriority()) |
23 , m_isAbovePriorityCutoff(false) | 23 , m_isAbovePriorityCutoff(false) |
24 , m_isSelfManaged(false) | 24 , m_isSelfManaged(false) |
25 , m_backing(0) | 25 , m_backing(0) |
26 , m_manager(0) | 26 , m_manager(0) |
27 { | 27 { |
28 // m_manager is set in registerTexture() so validity can be checked. | 28 // m_manager is set in registerTexture() so validity can be checked. |
29 ASSERT(format || size.isEmpty()); | 29 ASSERT(format || size.isEmpty()); |
30 if (format) | 30 if (format) |
31 m_bytes = CCTexture::memorySizeBytes(size, format); | 31 m_bytes = Texture::memorySizeBytes(size, format); |
32 if (manager) | 32 if (manager) |
33 manager->registerTexture(this); | 33 manager->registerTexture(this); |
34 } | 34 } |
35 | 35 |
36 CCPrioritizedTexture::~CCPrioritizedTexture() | 36 PrioritizedTexture::~PrioritizedTexture() |
37 { | 37 { |
38 if (m_manager) | 38 if (m_manager) |
39 m_manager->unregisterTexture(this); | 39 m_manager->unregisterTexture(this); |
40 } | 40 } |
41 | 41 |
42 void CCPrioritizedTexture::setTextureManager(CCPrioritizedTextureManager* manage
r) | 42 void PrioritizedTexture::setTextureManager(PrioritizedTextureManager* manager) |
43 { | 43 { |
44 if (m_manager == manager) | 44 if (m_manager == manager) |
45 return; | 45 return; |
46 if (m_manager) | 46 if (m_manager) |
47 m_manager->unregisterTexture(this); | 47 m_manager->unregisterTexture(this); |
48 if (manager) | 48 if (manager) |
49 manager->registerTexture(this); | 49 manager->registerTexture(this); |
50 } | 50 } |
51 | 51 |
52 void CCPrioritizedTexture::setDimensions(IntSize size, GC3Denum format) | 52 void PrioritizedTexture::setDimensions(IntSize size, GC3Denum format) |
53 { | 53 { |
54 if (m_format != format || m_size != size) { | 54 if (m_format != format || m_size != size) { |
55 m_isAbovePriorityCutoff = false; | 55 m_isAbovePriorityCutoff = false; |
56 m_format = format; | 56 m_format = format; |
57 m_size = size; | 57 m_size = size; |
58 m_bytes = CCTexture::memorySizeBytes(size, format); | 58 m_bytes = Texture::memorySizeBytes(size, format); |
59 ASSERT(m_manager || !m_backing); | 59 ASSERT(m_manager || !m_backing); |
60 if (m_manager) | 60 if (m_manager) |
61 m_manager->returnBackingTexture(this); | 61 m_manager->returnBackingTexture(this); |
62 } | 62 } |
63 } | 63 } |
64 | 64 |
65 bool CCPrioritizedTexture::requestLate() | 65 bool PrioritizedTexture::requestLate() |
66 { | 66 { |
67 if (!m_manager) | 67 if (!m_manager) |
68 return false; | 68 return false; |
69 return m_manager->requestLate(this); | 69 return m_manager->requestLate(this); |
70 } | 70 } |
71 | 71 |
72 bool CCPrioritizedTexture::backingResourceWasEvicted() const | 72 bool PrioritizedTexture::backingResourceWasEvicted() const |
73 { | 73 { |
74 return m_backing ? m_backing->resourceHasBeenDeleted() : false; | 74 return m_backing ? m_backing->resourceHasBeenDeleted() : false; |
75 } | 75 } |
76 | 76 |
77 void CCPrioritizedTexture::acquireBackingTexture(CCResourceProvider* resourcePro
vider) | 77 void PrioritizedTexture::acquireBackingTexture(ResourceProvider* resourceProvide
r) |
78 { | 78 { |
79 ASSERT(m_isAbovePriorityCutoff); | 79 ASSERT(m_isAbovePriorityCutoff); |
80 if (m_isAbovePriorityCutoff) | 80 if (m_isAbovePriorityCutoff) |
81 m_manager->acquireBackingTextureIfNeeded(this, resourceProvider); | 81 m_manager->acquireBackingTextureIfNeeded(this, resourceProvider); |
82 } | 82 } |
83 | 83 |
84 CCResourceProvider::ResourceId CCPrioritizedTexture::resourceId() const | 84 ResourceProvider::ResourceId PrioritizedTexture::resourceId() const |
85 { | 85 { |
86 if (m_backing) | 86 if (m_backing) |
87 return m_backing->id(); | 87 return m_backing->id(); |
88 return 0; | 88 return 0; |
89 } | 89 } |
90 | 90 |
91 void CCPrioritizedTexture::upload(CCResourceProvider* resourceProvider, | 91 void PrioritizedTexture::upload(ResourceProvider* resourceProvider, |
92 const uint8_t* image, const IntRect& imageRect
, | 92 const uint8_t* image, const IntRect& imageRect
, |
93 const IntRect& sourceRect, const IntSize& dest
Offset) | 93 const IntRect& sourceRect, const IntSize& dest
Offset) |
94 { | 94 { |
95 ASSERT(m_isAbovePriorityCutoff); | 95 ASSERT(m_isAbovePriorityCutoff); |
96 if (m_isAbovePriorityCutoff) | 96 if (m_isAbovePriorityCutoff) |
97 acquireBackingTexture(resourceProvider); | 97 acquireBackingTexture(resourceProvider); |
98 ASSERT(m_backing); | 98 ASSERT(m_backing); |
99 resourceProvider->upload(resourceId(), image, imageRect, sourceRect, destOff
set); | 99 resourceProvider->upload(resourceId(), image, imageRect, sourceRect, destOff
set); |
100 } | 100 } |
101 | 101 |
102 void CCPrioritizedTexture::link(Backing* backing) | 102 void PrioritizedTexture::link(Backing* backing) |
103 { | 103 { |
104 ASSERT(backing); | 104 ASSERT(backing); |
105 ASSERT(!backing->m_owner); | 105 ASSERT(!backing->m_owner); |
106 ASSERT(!m_backing); | 106 ASSERT(!m_backing); |
107 | 107 |
108 m_backing = backing; | 108 m_backing = backing; |
109 m_backing->m_owner = this; | 109 m_backing->m_owner = this; |
110 } | 110 } |
111 | 111 |
112 void CCPrioritizedTexture::unlink() | 112 void PrioritizedTexture::unlink() |
113 { | 113 { |
114 ASSERT(m_backing); | 114 ASSERT(m_backing); |
115 ASSERT(m_backing->m_owner == this); | 115 ASSERT(m_backing->m_owner == this); |
116 | 116 |
117 m_backing->m_owner = 0; | 117 m_backing->m_owner = 0; |
118 m_backing = 0; | 118 m_backing = 0; |
119 } | 119 } |
120 | 120 |
121 void CCPrioritizedTexture::setToSelfManagedMemoryPlaceholder(size_t bytes) | 121 void PrioritizedTexture::setToSelfManagedMemoryPlaceholder(size_t bytes) |
122 { | 122 { |
123 setDimensions(IntSize(), GraphicsContext3D::RGBA); | 123 setDimensions(IntSize(), GraphicsContext3D::RGBA); |
124 setIsSelfManaged(true); | 124 setIsSelfManaged(true); |
125 m_bytes = bytes; | 125 m_bytes = bytes; |
126 } | 126 } |
127 | 127 |
128 CCPrioritizedTexture::Backing::Backing(unsigned id, CCResourceProvider* resource
Provider, IntSize size, GC3Denum format) | 128 PrioritizedTexture::Backing::Backing(unsigned id, ResourceProvider* resourceProv
ider, IntSize size, GC3Denum format) |
129 : CCTexture(id, size, format) | 129 : Texture(id, size, format) |
130 , m_owner(0) | 130 , m_owner(0) |
131 , m_priorityAtLastPriorityUpdate(CCPriorityCalculator::lowestPriority()) | 131 , m_priorityAtLastPriorityUpdate(PriorityCalculator::lowestPriority()) |
132 , m_wasAbovePriorityCutoffAtLastPriorityUpdate(false) | 132 , m_wasAbovePriorityCutoffAtLastPriorityUpdate(false) |
133 , m_inDrawingImplTree(false) | 133 , m_inDrawingImplTree(false) |
134 , m_resourceHasBeenDeleted(false) | 134 , m_resourceHasBeenDeleted(false) |
135 #ifndef NDEBUG | 135 #ifndef NDEBUG |
136 , m_resourceProvider(resourceProvider) | 136 , m_resourceProvider(resourceProvider) |
137 #endif | 137 #endif |
138 { | 138 { |
139 } | 139 } |
140 | 140 |
141 CCPrioritizedTexture::Backing::~Backing() | 141 PrioritizedTexture::Backing::~Backing() |
142 { | 142 { |
143 ASSERT(!m_owner); | 143 ASSERT(!m_owner); |
144 ASSERT(m_resourceHasBeenDeleted); | 144 ASSERT(m_resourceHasBeenDeleted); |
145 } | 145 } |
146 | 146 |
147 void CCPrioritizedTexture::Backing::deleteResource(CCResourceProvider* resourceP
rovider) | 147 void PrioritizedTexture::Backing::deleteResource(ResourceProvider* resourceProvi
der) |
148 { | 148 { |
149 ASSERT(CCProxy::isImplThread()); | 149 ASSERT(Proxy::isImplThread()); |
150 ASSERT(!m_resourceHasBeenDeleted); | 150 ASSERT(!m_resourceHasBeenDeleted); |
151 #ifndef NDEBUG | 151 #ifndef NDEBUG |
152 ASSERT(resourceProvider == m_resourceProvider); | 152 ASSERT(resourceProvider == m_resourceProvider); |
153 #endif | 153 #endif |
154 | 154 |
155 resourceProvider->deleteResource(id()); | 155 resourceProvider->deleteResource(id()); |
156 setId(0); | 156 setId(0); |
157 m_resourceHasBeenDeleted = true; | 157 m_resourceHasBeenDeleted = true; |
158 } | 158 } |
159 | 159 |
160 bool CCPrioritizedTexture::Backing::resourceHasBeenDeleted() const | 160 bool PrioritizedTexture::Backing::resourceHasBeenDeleted() const |
161 { | 161 { |
162 ASSERT(CCProxy::isImplThread()); | 162 ASSERT(Proxy::isImplThread()); |
163 return m_resourceHasBeenDeleted; | 163 return m_resourceHasBeenDeleted; |
164 } | 164 } |
165 | 165 |
166 bool CCPrioritizedTexture::Backing::canBeRecycled() const | 166 bool PrioritizedTexture::Backing::canBeRecycled() const |
167 { | 167 { |
168 ASSERT(CCProxy::isImplThread()); | 168 ASSERT(Proxy::isImplThread()); |
169 return !m_wasAbovePriorityCutoffAtLastPriorityUpdate && !m_inDrawingImplTree
; | 169 return !m_wasAbovePriorityCutoffAtLastPriorityUpdate && !m_inDrawingImplTree
; |
170 } | 170 } |
171 | 171 |
172 void CCPrioritizedTexture::Backing::updatePriority() | 172 void PrioritizedTexture::Backing::updatePriority() |
173 { | 173 { |
174 ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked()); | 174 ASSERT(Proxy::isImplThread() && Proxy::isMainThreadBlocked()); |
175 if (m_owner) { | 175 if (m_owner) { |
176 m_priorityAtLastPriorityUpdate = m_owner->requestPriority(); | 176 m_priorityAtLastPriorityUpdate = m_owner->requestPriority(); |
177 m_wasAbovePriorityCutoffAtLastPriorityUpdate = m_owner->isAbovePriorityC
utoff(); | 177 m_wasAbovePriorityCutoffAtLastPriorityUpdate = m_owner->isAbovePriorityC
utoff(); |
178 } else { | 178 } else { |
179 m_priorityAtLastPriorityUpdate = CCPriorityCalculator::lowestPriority(); | 179 m_priorityAtLastPriorityUpdate = PriorityCalculator::lowestPriority(); |
180 m_wasAbovePriorityCutoffAtLastPriorityUpdate = false; | 180 m_wasAbovePriorityCutoffAtLastPriorityUpdate = false; |
181 } | 181 } |
182 } | 182 } |
183 | 183 |
184 void CCPrioritizedTexture::Backing::updateInDrawingImplTree() | 184 void PrioritizedTexture::Backing::updateInDrawingImplTree() |
185 { | 185 { |
186 ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked()); | 186 ASSERT(Proxy::isImplThread() && Proxy::isMainThreadBlocked()); |
187 m_inDrawingImplTree = !!owner(); | 187 m_inDrawingImplTree = !!owner(); |
188 if (!m_inDrawingImplTree) | 188 if (!m_inDrawingImplTree) |
189 ASSERT(m_priorityAtLastPriorityUpdate == CCPriorityCalculator::lowestPri
ority()); | 189 ASSERT(m_priorityAtLastPriorityUpdate == PriorityCalculator::lowestPrior
ity()); |
190 } | 190 } |
191 | 191 |
192 } // namespace cc | 192 } // namespace cc |
OLD | NEW |