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 "CCResourceProvider.h" | 7 #include "CCResourceProvider.h" |
8 | 8 |
9 #include "CCProxy.h" | 9 #include "CCProxy.h" |
10 #include "CCRendererGL.h" // For the GLC() macro. | 10 #include "CCRendererGL.h" // For the GLC() macro. |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 Resource resource(textureId, 0, IntSize(), 0); | 127 Resource resource(textureId, 0, IntSize(), 0); |
128 resource.external = true; | 128 resource.external = true; |
129 m_resources.add(id, resource); | 129 m_resources.add(id, resource); |
130 return id; | 130 return id; |
131 } | 131 } |
132 | 132 |
133 void CCResourceProvider::deleteResource(ResourceId id) | 133 void CCResourceProvider::deleteResource(ResourceId id) |
134 { | 134 { |
135 ASSERT(CCProxy::isImplThread()); | 135 ASSERT(CCProxy::isImplThread()); |
136 ResourceMap::iterator it = m_resources.find(id); | 136 ResourceMap::iterator it = m_resources.find(id); |
137 ASSERT(it != m_resources.end() && !it->second.lockedForWrite && !it->second.
lockForReadCount); | 137 ASSERT(it != m_resources.end()); |
| 138 ASSERT(!it->second.lockedForWrite); |
| 139 ASSERT(!it->second.lockForReadCount); |
138 | 140 |
139 if (it->second.glId && !it->second.external) { | 141 if (it->second.glId && !it->second.external) { |
140 WebGraphicsContext3D* context3d = m_context->context3D(); | 142 WebGraphicsContext3D* context3d = m_context->context3D(); |
141 ASSERT(context3d); | 143 ASSERT(context3d); |
142 GLC(context3d, context3d->deleteTexture(it->second.glId)); | 144 GLC(context3d, context3d->deleteTexture(it->second.glId)); |
143 } | 145 } |
144 if (it->second.pixels) | 146 if (it->second.pixels) |
145 delete it->second.pixels; | 147 delete it->second.pixels; |
146 | 148 |
147 m_resources.remove(it); | 149 m_resources.remove(it); |
(...skipping 15 matching lines...) Expand all Loading... |
163 { | 165 { |
164 ResourceMap::iterator it = m_resources.find(id); | 166 ResourceMap::iterator it = m_resources.find(id); |
165 ASSERT(it != m_resources.end()); | 167 ASSERT(it != m_resources.end()); |
166 return it->second.type; | 168 return it->second.type; |
167 } | 169 } |
168 | 170 |
169 void CCResourceProvider::upload(ResourceId id, const uint8_t* image, const IntRe
ct& imageRect, const IntRect& sourceRect, const IntSize& destOffset) | 171 void CCResourceProvider::upload(ResourceId id, const uint8_t* image, const IntRe
ct& imageRect, const IntRect& sourceRect, const IntSize& destOffset) |
170 { | 172 { |
171 ASSERT(CCProxy::isImplThread()); | 173 ASSERT(CCProxy::isImplThread()); |
172 ResourceMap::iterator it = m_resources.find(id); | 174 ResourceMap::iterator it = m_resources.find(id); |
173 ASSERT(it != m_resources.end() && !it->second.lockedForWrite && !it->second.
lockForReadCount && !it->second.external); | 175 ASSERT(it != m_resources.end()); |
| 176 ASSERT(!it->second.lockedForWrite); |
| 177 ASSERT(!it->second.lockForReadCount); |
| 178 ASSERT(!it->second.external); |
174 | 179 |
175 if (it->second.glId) { | 180 if (it->second.glId) { |
176 WebGraphicsContext3D* context3d = m_context->context3D(); | 181 WebGraphicsContext3D* context3d = m_context->context3D(); |
177 ASSERT(context3d); | 182 ASSERT(context3d); |
178 ASSERT(m_texSubImage.get()); | 183 ASSERT(m_texSubImage.get()); |
179 context3d->bindTexture(GraphicsContext3D::TEXTURE_2D, it->second.glId); | 184 context3d->bindTexture(GraphicsContext3D::TEXTURE_2D, it->second.glId); |
180 m_texSubImage->upload(image, imageRect, sourceRect, destOffset, it->seco
nd.format, context3d); | 185 m_texSubImage->upload(image, imageRect, sourceRect, destOffset, it->seco
nd.format, context3d); |
181 } | 186 } |
182 | 187 |
183 if (it->second.pixels) { | 188 if (it->second.pixels) { |
(...skipping 27 matching lines...) Expand all Loading... |
211 return false; | 216 return false; |
212 | 217 |
213 context3d->shallowFlushCHROMIUM(); | 218 context3d->shallowFlushCHROMIUM(); |
214 return true; | 219 return true; |
215 } | 220 } |
216 | 221 |
217 const CCResourceProvider::Resource* CCResourceProvider::lockForRead(ResourceId i
d) | 222 const CCResourceProvider::Resource* CCResourceProvider::lockForRead(ResourceId i
d) |
218 { | 223 { |
219 ASSERT(CCProxy::isImplThread()); | 224 ASSERT(CCProxy::isImplThread()); |
220 ResourceMap::iterator it = m_resources.find(id); | 225 ResourceMap::iterator it = m_resources.find(id); |
221 ASSERT(it != m_resources.end() && !it->second.lockedForWrite); | 226 ASSERT(it != m_resources.end()); |
| 227 ASSERT(!it->second.lockedForWrite); |
222 it->second.lockForReadCount++; | 228 it->second.lockForReadCount++; |
223 return &it->second; | 229 return &it->second; |
224 } | 230 } |
225 | 231 |
226 void CCResourceProvider::unlockForRead(ResourceId id) | 232 void CCResourceProvider::unlockForRead(ResourceId id) |
227 { | 233 { |
228 ASSERT(CCProxy::isImplThread()); | 234 ASSERT(CCProxy::isImplThread()); |
229 ResourceMap::iterator it = m_resources.find(id); | 235 ResourceMap::iterator it = m_resources.find(id); |
230 ASSERT(it != m_resources.end() && it->second.lockForReadCount > 0); | 236 ASSERT(it != m_resources.end()); |
| 237 ASSERT(it->second.lockForReadCount > 0); |
231 it->second.lockForReadCount--; | 238 it->second.lockForReadCount--; |
232 } | 239 } |
233 | 240 |
234 const CCResourceProvider::Resource* CCResourceProvider::lockForWrite(ResourceId
id) | 241 const CCResourceProvider::Resource* CCResourceProvider::lockForWrite(ResourceId
id) |
235 { | 242 { |
236 ASSERT(CCProxy::isImplThread()); | 243 ASSERT(CCProxy::isImplThread()); |
237 ResourceMap::iterator it = m_resources.find(id); | 244 ResourceMap::iterator it = m_resources.find(id); |
238 ASSERT(it != m_resources.end() && !it->second.lockedForWrite && !it->second.
lockForReadCount && !it->second.external); | 245 ASSERT(it != m_resources.end()); |
| 246 ASSERT(!it->second.lockedForWrite); |
| 247 ASSERT(!it->second.lockForReadCount); |
| 248 ASSERT(!it->second.external); |
239 it->second.lockedForWrite = true; | 249 it->second.lockedForWrite = true; |
240 return &it->second; | 250 return &it->second; |
241 } | 251 } |
242 | 252 |
243 void CCResourceProvider::unlockForWrite(ResourceId id) | 253 void CCResourceProvider::unlockForWrite(ResourceId id) |
244 { | 254 { |
245 ASSERT(CCProxy::isImplThread()); | 255 ASSERT(CCProxy::isImplThread()); |
246 ResourceMap::iterator it = m_resources.find(id); | 256 ResourceMap::iterator it = m_resources.find(id); |
247 ASSERT(it != m_resources.end() && it->second.lockedForWrite && !it->second.e
xternal); | 257 ASSERT(it != m_resources.end()); |
| 258 ASSERT(it->second.lockedForWrite); |
| 259 ASSERT(!it->second.external); |
248 it->second.lockedForWrite = false; | 260 it->second.lockedForWrite = false; |
249 } | 261 } |
250 | 262 |
251 CCResourceProvider::ScopedReadLockGL::ScopedReadLockGL(CCResourceProvider* resou
rceProvider, CCResourceProvider::ResourceId resourceId) | 263 CCResourceProvider::ScopedReadLockGL::ScopedReadLockGL(CCResourceProvider* resou
rceProvider, CCResourceProvider::ResourceId resourceId) |
252 : m_resourceProvider(resourceProvider) | 264 : m_resourceProvider(resourceProvider) |
253 , m_resourceId(resourceId) | 265 , m_resourceId(resourceId) |
254 , m_textureId(resourceProvider->lockForRead(resourceId)->glId) | 266 , m_textureId(resourceProvider->lockForRead(resourceId)->glId) |
255 { | 267 { |
256 ASSERT(m_textureId); | 268 ASSERT(m_textureId); |
257 } | 269 } |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 GLC(context3d, context3d->bindTexture(GraphicsContext3D::TEXTURE_2D, res
ource.glId)); | 490 GLC(context3d, context3d->bindTexture(GraphicsContext3D::TEXTURE_2D, res
ource.glId)); |
479 GLC(context3d, context3d->consumeTextureCHROMIUM(GraphicsContext3D::TEXT
URE_2D, it->mailbox.name)); | 491 GLC(context3d, context3d->consumeTextureCHROMIUM(GraphicsContext3D::TEXT
URE_2D, it->mailbox.name)); |
480 m_mailboxes.append(it->mailbox); | 492 m_mailboxes.append(it->mailbox); |
481 } | 493 } |
482 } | 494 } |
483 | 495 |
484 bool CCResourceProvider::transferResource(WebGraphicsContext3D* context, Resourc
eId id, TransferableResource* resource) | 496 bool CCResourceProvider::transferResource(WebGraphicsContext3D* context, Resourc
eId id, TransferableResource* resource) |
485 { | 497 { |
486 ASSERT(CCProxy::isImplThread()); | 498 ASSERT(CCProxy::isImplThread()); |
487 ResourceMap::const_iterator it = m_resources.find(id); | 499 ResourceMap::const_iterator it = m_resources.find(id); |
488 ASSERT(it != m_resources.end() && !it->second.lockedForWrite && !it->second.
lockForReadCount && !it->second.external); | 500 ASSERT(it != m_resources.end()); |
| 501 ASSERT(!it->second.lockedForWrite); |
| 502 ASSERT(!it->second.lockForReadCount); |
| 503 ASSERT(!it->second.external); |
489 if (it->second.exported) | 504 if (it->second.exported) |
490 return false; | 505 return false; |
491 resource->id = id; | 506 resource->id = id; |
492 resource->format = it->second.format; | 507 resource->format = it->second.format; |
493 resource->size = it->second.size; | 508 resource->size = it->second.size; |
494 if (!m_mailboxes.isEmpty()) | 509 if (!m_mailboxes.isEmpty()) |
495 resource->mailbox = m_mailboxes.takeFirst(); | 510 resource->mailbox = m_mailboxes.takeFirst(); |
496 else | 511 else |
497 GLC(context, context->genMailboxCHROMIUM(resource->mailbox.name)); | 512 GLC(context, context->genMailboxCHROMIUM(resource->mailbox.name)); |
498 GLC(context, context->bindTexture(GraphicsContext3D::TEXTURE_2D, it->second.
glId)); | 513 GLC(context, context->bindTexture(GraphicsContext3D::TEXTURE_2D, it->second.
glId)); |
(...skipping 21 matching lines...) Expand all Loading... |
520 for (ResourceMap::iterator it = m_resources.begin(); it != m_resources.e
nd(); ++it) { | 535 for (ResourceMap::iterator it = m_resources.begin(); it != m_resources.e
nd(); ++it) { |
521 if (childPoolSet.contains(it->second.pool)) | 536 if (childPoolSet.contains(it->second.pool)) |
522 ++maxMailboxCount; | 537 ++maxMailboxCount; |
523 } | 538 } |
524 } | 539 } |
525 while (m_mailboxes.size() > maxMailboxCount) | 540 while (m_mailboxes.size() > maxMailboxCount) |
526 m_mailboxes.removeFirst(); | 541 m_mailboxes.removeFirst(); |
527 } | 542 } |
528 | 543 |
529 } | 544 } |
OLD | NEW |