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 "cc/prioritized_texture.h" | 7 #include "cc/prioritized_resource.h" |
8 | 8 |
9 #include "cc/platform_color.h" | 9 #include "cc/platform_color.h" |
10 #include "cc/prioritized_texture_manager.h" | 10 #include "cc/prioritized_resource_manager.h" |
11 #include "cc/priority_calculator.h" | 11 #include "cc/priority_calculator.h" |
12 #include "cc/proxy.h" | 12 #include "cc/proxy.h" |
13 #include <algorithm> | 13 #include <algorithm> |
14 | 14 |
15 using namespace std; | 15 using namespace std; |
16 | 16 |
17 namespace cc { | 17 namespace cc { |
18 | 18 |
19 PrioritizedTexture::PrioritizedTexture(PrioritizedTextureManager* manager, gfx::
Size size, GLenum format) | 19 PrioritizedResource::PrioritizedResource(PrioritizedResourceManager* manager, gf
x::Size size, GLenum format) |
20 : m_size(size) | 20 : m_size(size) |
21 , m_format(format) | 21 , m_format(format) |
22 , m_bytes(0) | 22 , m_bytes(0) |
23 , m_contentsSwizzled(false) | 23 , m_contentsSwizzled(false) |
24 , m_priority(PriorityCalculator::lowestPriority()) | 24 , m_priority(PriorityCalculator::lowestPriority()) |
25 , m_isAbovePriorityCutoff(false) | 25 , m_isAbovePriorityCutoff(false) |
26 , m_isSelfManaged(false) | 26 , m_isSelfManaged(false) |
27 , m_backing(0) | 27 , m_backing(0) |
28 , m_manager(0) | 28 , m_manager(0) |
29 { | 29 { |
30 // m_manager is set in registerTexture() so validity can be checked. | 30 // m_manager is set in registerTexture() so validity can be checked. |
31 DCHECK(format || size.IsEmpty()); | 31 DCHECK(format || size.IsEmpty()); |
32 if (format) | 32 if (format) |
33 m_bytes = Texture::memorySizeBytes(size, format); | 33 m_bytes = Texture::memorySizeBytes(size, format); |
34 if (manager) | 34 if (manager) |
35 manager->registerTexture(this); | 35 manager->registerTexture(this); |
36 } | 36 } |
37 | 37 |
38 PrioritizedTexture::~PrioritizedTexture() | 38 PrioritizedResource::~PrioritizedResource() |
39 { | 39 { |
40 if (m_manager) | 40 if (m_manager) |
41 m_manager->unregisterTexture(this); | 41 m_manager->unregisterTexture(this); |
42 } | 42 } |
43 | 43 |
44 void PrioritizedTexture::setTextureManager(PrioritizedTextureManager* manager) | 44 void PrioritizedResource::setTextureManager(PrioritizedResourceManager* manager) |
45 { | 45 { |
46 if (m_manager == manager) | 46 if (m_manager == manager) |
47 return; | 47 return; |
48 if (m_manager) | 48 if (m_manager) |
49 m_manager->unregisterTexture(this); | 49 m_manager->unregisterTexture(this); |
50 if (manager) | 50 if (manager) |
51 manager->registerTexture(this); | 51 manager->registerTexture(this); |
52 } | 52 } |
53 | 53 |
54 void PrioritizedTexture::setDimensions(gfx::Size size, GLenum format) | 54 void PrioritizedResource::setDimensions(gfx::Size size, GLenum format) |
55 { | 55 { |
56 if (m_format != format || m_size != size) { | 56 if (m_format != format || m_size != size) { |
57 m_isAbovePriorityCutoff = false; | 57 m_isAbovePriorityCutoff = false; |
58 m_format = format; | 58 m_format = format; |
59 m_size = size; | 59 m_size = size; |
60 m_bytes = Texture::memorySizeBytes(size, format); | 60 m_bytes = Texture::memorySizeBytes(size, format); |
61 DCHECK(m_manager || !m_backing); | 61 DCHECK(m_manager || !m_backing); |
62 if (m_manager) | 62 if (m_manager) |
63 m_manager->returnBackingTexture(this); | 63 m_manager->returnBackingTexture(this); |
64 } | 64 } |
65 } | 65 } |
66 | 66 |
67 bool PrioritizedTexture::requestLate() | 67 bool PrioritizedResource::requestLate() |
68 { | 68 { |
69 if (!m_manager) | 69 if (!m_manager) |
70 return false; | 70 return false; |
71 return m_manager->requestLate(this); | 71 return m_manager->requestLate(this); |
72 } | 72 } |
73 | 73 |
74 bool PrioritizedTexture::backingResourceWasEvicted() const | 74 bool PrioritizedResource::backingResourceWasEvicted() const |
75 { | 75 { |
76 return m_backing ? m_backing->resourceHasBeenDeleted() : false; | 76 return m_backing ? m_backing->resourceHasBeenDeleted() : false; |
77 } | 77 } |
78 | 78 |
79 void PrioritizedTexture::acquireBackingTexture(ResourceProvider* resourceProvide
r) | 79 void PrioritizedResource::acquireBackingTexture(ResourceProvider* resourceProvid
er) |
80 { | 80 { |
81 DCHECK(m_isAbovePriorityCutoff); | 81 DCHECK(m_isAbovePriorityCutoff); |
82 if (m_isAbovePriorityCutoff) | 82 if (m_isAbovePriorityCutoff) |
83 m_manager->acquireBackingTextureIfNeeded(this, resourceProvider); | 83 m_manager->acquireBackingTextureIfNeeded(this, resourceProvider); |
84 } | 84 } |
85 | 85 |
86 ResourceProvider::ResourceId PrioritizedTexture::resourceId() const | 86 ResourceProvider::ResourceId PrioritizedResource::resourceId() const |
87 { | 87 { |
88 if (m_backing) | 88 if (m_backing) |
89 return m_backing->id(); | 89 return m_backing->id(); |
90 return 0; | 90 return 0; |
91 } | 91 } |
92 | 92 |
93 void PrioritizedTexture::setPixels(ResourceProvider* resourceProvider, | 93 void PrioritizedResource::setPixels(ResourceProvider* resourceProvider, |
94 const uint8_t* image, const gfx::Rect& imageR
ect, | 94 const uint8_t* image, const gfx::Rect& imageR
ect, |
95 const gfx::Rect& sourceRect, const gfx::Vecto
r2d& destOffset) | 95 const gfx::Rect& sourceRect, const gfx::Vecto
r2d& destOffset) |
96 { | 96 { |
97 DCHECK(m_isAbovePriorityCutoff); | 97 DCHECK(m_isAbovePriorityCutoff); |
98 if (m_isAbovePriorityCutoff) | 98 if (m_isAbovePriorityCutoff) |
99 acquireBackingTexture(resourceProvider); | 99 acquireBackingTexture(resourceProvider); |
100 DCHECK(m_backing); | 100 DCHECK(m_backing); |
101 resourceProvider->setPixels(resourceId(), image, imageRect, sourceRect, dest
Offset); | 101 resourceProvider->setPixels(resourceId(), image, imageRect, sourceRect, dest
Offset); |
102 | 102 |
103 // The component order may be bgra if we uploaded bgra pixels to rgba | 103 // The component order may be bgra if we uploaded bgra pixels to rgba |
104 // texture. Mark contents as swizzled if image component order is | 104 // texture. Mark contents as swizzled if image component order is |
105 // different than texture format. | 105 // different than texture format. |
106 m_contentsSwizzled = !PlatformColor::sameComponentOrder(m_format); | 106 m_contentsSwizzled = !PlatformColor::sameComponentOrder(m_format); |
107 } | 107 } |
108 | 108 |
109 void PrioritizedTexture::link(Backing* backing) | 109 void PrioritizedResource::link(Backing* backing) |
110 { | 110 { |
111 DCHECK(backing); | 111 DCHECK(backing); |
112 DCHECK(!backing->m_owner); | 112 DCHECK(!backing->m_owner); |
113 DCHECK(!m_backing); | 113 DCHECK(!m_backing); |
114 | 114 |
115 m_backing = backing; | 115 m_backing = backing; |
116 m_backing->m_owner = this; | 116 m_backing->m_owner = this; |
117 } | 117 } |
118 | 118 |
119 void PrioritizedTexture::unlink() | 119 void PrioritizedResource::unlink() |
120 { | 120 { |
121 DCHECK(m_backing); | 121 DCHECK(m_backing); |
122 DCHECK(m_backing->m_owner == this); | 122 DCHECK(m_backing->m_owner == this); |
123 | 123 |
124 m_backing->m_owner = 0; | 124 m_backing->m_owner = 0; |
125 m_backing = 0; | 125 m_backing = 0; |
126 } | 126 } |
127 | 127 |
128 void PrioritizedTexture::setToSelfManagedMemoryPlaceholder(size_t bytes) | 128 void PrioritizedResource::setToSelfManagedMemoryPlaceholder(size_t bytes) |
129 { | 129 { |
130 setDimensions(gfx::Size(), GL_RGBA); | 130 setDimensions(gfx::Size(), GL_RGBA); |
131 setIsSelfManaged(true); | 131 setIsSelfManaged(true); |
132 m_bytes = bytes; | 132 m_bytes = bytes; |
133 } | 133 } |
134 | 134 |
135 PrioritizedTexture::Backing::Backing(unsigned id, ResourceProvider* resourceProv
ider, gfx::Size size, GLenum format) | 135 PrioritizedResource::Backing::Backing(unsigned id, ResourceProvider* resourcePro
vider, gfx::Size size, GLenum format) |
136 : Texture(id, size, format) | 136 : Texture(id, size, format) |
137 , m_owner(0) | 137 , m_owner(0) |
138 , m_priorityAtLastPriorityUpdate(PriorityCalculator::lowestPriority()) | 138 , m_priorityAtLastPriorityUpdate(PriorityCalculator::lowestPriority()) |
139 , m_wasAbovePriorityCutoffAtLastPriorityUpdate(false) | 139 , m_wasAbovePriorityCutoffAtLastPriorityUpdate(false) |
140 , m_inDrawingImplTree(false) | 140 , m_inDrawingImplTree(false) |
141 , m_resourceHasBeenDeleted(false) | 141 , m_resourceHasBeenDeleted(false) |
142 #ifndef NDEBUG | 142 #ifndef NDEBUG |
143 , m_resourceProvider(resourceProvider) | 143 , m_resourceProvider(resourceProvider) |
144 #endif | 144 #endif |
145 { | 145 { |
146 } | 146 } |
147 | 147 |
148 PrioritizedTexture::Backing::~Backing() | 148 PrioritizedResource::Backing::~Backing() |
149 { | 149 { |
150 DCHECK(!m_owner); | 150 DCHECK(!m_owner); |
151 DCHECK(m_resourceHasBeenDeleted); | 151 DCHECK(m_resourceHasBeenDeleted); |
152 } | 152 } |
153 | 153 |
154 void PrioritizedTexture::Backing::deleteResource(ResourceProvider* resourceProvi
der) | 154 void PrioritizedResource::Backing::deleteResource(ResourceProvider* resourceProv
ider) |
155 { | 155 { |
156 DCHECK(Proxy::isImplThread()); | 156 DCHECK(Proxy::isImplThread()); |
157 DCHECK(!m_resourceHasBeenDeleted); | 157 DCHECK(!m_resourceHasBeenDeleted); |
158 #ifndef NDEBUG | 158 #ifndef NDEBUG |
159 DCHECK(resourceProvider == m_resourceProvider); | 159 DCHECK(resourceProvider == m_resourceProvider); |
160 #endif | 160 #endif |
161 | 161 |
162 resourceProvider->deleteResource(id()); | 162 resourceProvider->deleteResource(id()); |
163 setId(0); | 163 setId(0); |
164 m_resourceHasBeenDeleted = true; | 164 m_resourceHasBeenDeleted = true; |
165 } | 165 } |
166 | 166 |
167 bool PrioritizedTexture::Backing::resourceHasBeenDeleted() const | 167 bool PrioritizedResource::Backing::resourceHasBeenDeleted() const |
168 { | 168 { |
169 DCHECK(Proxy::isImplThread()); | 169 DCHECK(Proxy::isImplThread()); |
170 return m_resourceHasBeenDeleted; | 170 return m_resourceHasBeenDeleted; |
171 } | 171 } |
172 | 172 |
173 bool PrioritizedTexture::Backing::canBeRecycled() const | 173 bool PrioritizedResource::Backing::canBeRecycled() const |
174 { | 174 { |
175 DCHECK(Proxy::isImplThread()); | 175 DCHECK(Proxy::isImplThread()); |
176 return !m_wasAbovePriorityCutoffAtLastPriorityUpdate && !m_inDrawingImplTree
; | 176 return !m_wasAbovePriorityCutoffAtLastPriorityUpdate && !m_inDrawingImplTree
; |
177 } | 177 } |
178 | 178 |
179 void PrioritizedTexture::Backing::updatePriority() | 179 void PrioritizedResource::Backing::updatePriority() |
180 { | 180 { |
181 DCHECK(Proxy::isImplThread() && Proxy::isMainThreadBlocked()); | 181 DCHECK(Proxy::isImplThread() && Proxy::isMainThreadBlocked()); |
182 if (m_owner) { | 182 if (m_owner) { |
183 m_priorityAtLastPriorityUpdate = m_owner->requestPriority(); | 183 m_priorityAtLastPriorityUpdate = m_owner->requestPriority(); |
184 m_wasAbovePriorityCutoffAtLastPriorityUpdate = m_owner->isAbovePriorityC
utoff(); | 184 m_wasAbovePriorityCutoffAtLastPriorityUpdate = m_owner->isAbovePriorityC
utoff(); |
185 } else { | 185 } else { |
186 m_priorityAtLastPriorityUpdate = PriorityCalculator::lowestPriority(); | 186 m_priorityAtLastPriorityUpdate = PriorityCalculator::lowestPriority(); |
187 m_wasAbovePriorityCutoffAtLastPriorityUpdate = false; | 187 m_wasAbovePriorityCutoffAtLastPriorityUpdate = false; |
188 } | 188 } |
189 } | 189 } |
190 | 190 |
191 void PrioritizedTexture::Backing::updateInDrawingImplTree() | 191 void PrioritizedResource::Backing::updateInDrawingImplTree() |
192 { | 192 { |
193 DCHECK(Proxy::isImplThread() && Proxy::isMainThreadBlocked()); | 193 DCHECK(Proxy::isImplThread() && Proxy::isMainThreadBlocked()); |
194 m_inDrawingImplTree = !!owner(); | 194 m_inDrawingImplTree = !!owner(); |
195 if (!m_inDrawingImplTree) | 195 if (!m_inDrawingImplTree) |
196 DCHECK(m_priorityAtLastPriorityUpdate == PriorityCalculator::lowestPrior
ity()); | 196 DCHECK(m_priorityAtLastPriorityUpdate == PriorityCalculator::lowestPrior
ity()); |
197 } | 197 } |
198 | 198 |
199 void PrioritizedTexture::returnBackingTexture() | 199 void PrioritizedResource::returnBackingTexture() |
200 { | 200 { |
201 DCHECK(m_manager || !m_backing); | 201 DCHECK(m_manager || !m_backing); |
202 if (m_manager) | 202 if (m_manager) |
203 m_manager->returnBackingTexture(this); | 203 m_manager->returnBackingTexture(this); |
204 } | 204 } |
205 | 205 |
206 } // namespace cc | 206 } // namespace cc |
OLD | NEW |