| 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 #ifdef LOG | 8 #ifdef LOG |
| 9 #undef LOG | 9 #undef LOG |
| 10 #endif | 10 #endif |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 { | 133 { |
| 134 ASSERT(CCProxy::isImplThread()); | 134 ASSERT(CCProxy::isImplThread()); |
| 135 return m_context->context3D(); | 135 return m_context->context3D(); |
| 136 } | 136 } |
| 137 | 137 |
| 138 bool CCResourceProvider::inUseByConsumer(ResourceId id) | 138 bool CCResourceProvider::inUseByConsumer(ResourceId id) |
| 139 { | 139 { |
| 140 ASSERT(CCProxy::isImplThread()); | 140 ASSERT(CCProxy::isImplThread()); |
| 141 ResourceMap::iterator it = m_resources.find(id); | 141 ResourceMap::iterator it = m_resources.find(id); |
| 142 CHECK(it != m_resources.end()); | 142 CHECK(it != m_resources.end()); |
| 143 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE | |
| 144 Resource* resource = &it->value; | |
| 145 #else | |
| 146 Resource* resource = &it->second; | 143 Resource* resource = &it->second; |
| 147 #endif | |
| 148 return !!resource->lockForReadCount || resource->exported; | 144 return !!resource->lockForReadCount || resource->exported; |
| 149 } | 145 } |
| 150 | 146 |
| 151 CCResourceProvider::ResourceId CCResourceProvider::createResource(int pool, cons
t IntSize& size, GC3Denum format, TextureUsageHint hint) | 147 CCResourceProvider::ResourceId CCResourceProvider::createResource(int pool, cons
t IntSize& size, GC3Denum format, TextureUsageHint hint) |
| 152 { | 148 { |
| 153 switch (m_defaultResourceType) { | 149 switch (m_defaultResourceType) { |
| 154 case GLTexture: | 150 case GLTexture: |
| 155 return createGLTexture(pool, size, format, hint); | 151 return createGLTexture(pool, size, format, hint); |
| 156 case Bitmap: | 152 case Bitmap: |
| 157 ASSERT(format == GraphicsContext3D::RGBA); | 153 ASSERT(format == GraphicsContext3D::RGBA); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 177 | 173 |
| 178 if (m_useTextureUsageHint && hint == TextureUsageFramebuffer) | 174 if (m_useTextureUsageHint && hint == TextureUsageFramebuffer) |
| 179 GLC(context3d, context3d->texParameteri(GraphicsContext3D::TEXTURE_2D, E
xtensions3DChromium::GL_TEXTURE_USAGE_ANGLE, Extensions3DChromium::GL_FRAMEBUFFE
R_ATTACHMENT_ANGLE)); | 175 GLC(context3d, context3d->texParameteri(GraphicsContext3D::TEXTURE_2D, E
xtensions3DChromium::GL_TEXTURE_USAGE_ANGLE, Extensions3DChromium::GL_FRAMEBUFFE
R_ATTACHMENT_ANGLE)); |
| 180 if (m_useTextureStorageExt && isTextureFormatSupportedForStorage(format)) { | 176 if (m_useTextureStorageExt && isTextureFormatSupportedForStorage(format)) { |
| 181 GC3Denum storageFormat = textureToStorageFormat(format); | 177 GC3Denum storageFormat = textureToStorageFormat(format); |
| 182 GLC(context3d, context3d->texStorage2DEXT(GraphicsContext3D::TEXTURE_2D,
1, storageFormat, size.width(), size.height())); | 178 GLC(context3d, context3d->texStorage2DEXT(GraphicsContext3D::TEXTURE_2D,
1, storageFormat, size.width(), size.height())); |
| 183 } else | 179 } else |
| 184 GLC(context3d, context3d->texImage2D(GraphicsContext3D::TEXTURE_2D, 0, f
ormat, size.width(), size.height(), 0, format, GraphicsContext3D::UNSIGNED_BYTE,
0)); | 180 GLC(context3d, context3d->texImage2D(GraphicsContext3D::TEXTURE_2D, 0, f
ormat, size.width(), size.height(), 0, format, GraphicsContext3D::UNSIGNED_BYTE,
0)); |
| 185 ResourceId id = m_nextId++; | 181 ResourceId id = m_nextId++; |
| 186 Resource resource(textureId, pool, size, format); | 182 Resource resource(textureId, pool, size, format); |
| 187 m_resources.add(id, resource); | 183 m_resources[id] = resource; |
| 188 return id; | 184 return id; |
| 189 } | 185 } |
| 190 | 186 |
| 191 CCResourceProvider::ResourceId CCResourceProvider::createBitmap(int pool, const
IntSize& size) | 187 CCResourceProvider::ResourceId CCResourceProvider::createBitmap(int pool, const
IntSize& size) |
| 192 { | 188 { |
| 193 ASSERT(CCProxy::isImplThread()); | 189 ASSERT(CCProxy::isImplThread()); |
| 194 | 190 |
| 195 uint8_t* pixels = new uint8_t[size.width() * size.height() * 4]; | 191 uint8_t* pixels = new uint8_t[size.width() * size.height() * 4]; |
| 196 | 192 |
| 197 ResourceId id = m_nextId++; | 193 ResourceId id = m_nextId++; |
| 198 Resource resource(pixels, pool, size, GraphicsContext3D::RGBA); | 194 Resource resource(pixels, pool, size, GraphicsContext3D::RGBA); |
| 199 m_resources.add(id, resource); | 195 m_resources[id] = resource; |
| 200 return id; | 196 return id; |
| 201 } | 197 } |
| 202 | 198 |
| 203 CCResourceProvider::ResourceId CCResourceProvider::createResourceFromExternalTex
ture(unsigned textureId) | 199 CCResourceProvider::ResourceId CCResourceProvider::createResourceFromExternalTex
ture(unsigned textureId) |
| 204 { | 200 { |
| 205 ASSERT(CCProxy::isImplThread()); | 201 ASSERT(CCProxy::isImplThread()); |
| 206 ASSERT(m_context->context3D()); | 202 ASSERT(m_context->context3D()); |
| 207 ResourceId id = m_nextId++; | 203 ResourceId id = m_nextId++; |
| 208 Resource resource(textureId, 0, IntSize(), 0); | 204 Resource resource(textureId, 0, IntSize(), 0); |
| 209 resource.external = true; | 205 resource.external = true; |
| 210 m_resources.add(id, resource); | 206 m_resources[id] = resource; |
| 211 return id; | 207 return id; |
| 212 } | 208 } |
| 213 | 209 |
| 214 void CCResourceProvider::deleteResource(ResourceId id) | 210 void CCResourceProvider::deleteResource(ResourceId id) |
| 215 { | 211 { |
| 216 ASSERT(CCProxy::isImplThread()); | 212 ASSERT(CCProxy::isImplThread()); |
| 217 ResourceMap::iterator it = m_resources.find(id); | 213 ResourceMap::iterator it = m_resources.find(id); |
| 218 CHECK(it != m_resources.end()); | 214 CHECK(it != m_resources.end()); |
| 219 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE | |
| 220 Resource* resource = &it->value; | |
| 221 #else | |
| 222 Resource* resource = &it->second; | 215 Resource* resource = &it->second; |
| 223 #endif | |
| 224 ASSERT(!resource->lockedForWrite); | 216 ASSERT(!resource->lockedForWrite); |
| 225 ASSERT(!resource->lockForReadCount); | 217 ASSERT(!resource->lockForReadCount); |
| 226 ASSERT(!resource->markedForDeletion); | 218 ASSERT(!resource->markedForDeletion); |
| 227 | 219 |
| 228 if (resource->exported) { | 220 if (resource->exported) { |
| 229 resource->markedForDeletion = true; | 221 resource->markedForDeletion = true; |
| 230 return; | 222 return; |
| 231 } else | 223 } else |
| 232 deleteResourceInternal(it); | 224 deleteResourceInternal(it); |
| 233 } | 225 } |
| 234 | 226 |
| 235 void CCResourceProvider::deleteResourceInternal(ResourceMap::iterator it) | 227 void CCResourceProvider::deleteResourceInternal(ResourceMap::iterator it) |
| 236 { | 228 { |
| 237 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE | |
| 238 Resource* resource = &it->value; | |
| 239 #else | |
| 240 Resource* resource = &it->second; | 229 Resource* resource = &it->second; |
| 241 #endif | |
| 242 if (resource->glId && !resource->external) { | 230 if (resource->glId && !resource->external) { |
| 243 WebGraphicsContext3D* context3d = m_context->context3D(); | 231 WebGraphicsContext3D* context3d = m_context->context3D(); |
| 244 ASSERT(context3d); | 232 ASSERT(context3d); |
| 245 GLC(context3d, context3d->deleteTexture(resource->glId)); | 233 GLC(context3d, context3d->deleteTexture(resource->glId)); |
| 246 } | 234 } |
| 247 if (resource->pixels) | 235 if (resource->pixels) |
| 248 delete resource->pixels; | 236 delete resource->pixels; |
| 249 | 237 |
| 250 m_resources.remove(it); | 238 m_resources.erase(it); |
| 251 } | 239 } |
| 252 | 240 |
| 253 void CCResourceProvider::deleteOwnedResources(int pool) | 241 void CCResourceProvider::deleteOwnedResources(int pool) |
| 254 { | 242 { |
| 255 ASSERT(CCProxy::isImplThread()); | 243 ASSERT(CCProxy::isImplThread()); |
| 256 ResourceIdArray toDelete; | 244 ResourceIdArray toDelete; |
| 257 for (ResourceMap::iterator it = m_resources.begin(); it != m_resources.end()
; ++it) { | 245 for (ResourceMap::iterator it = m_resources.begin(); it != m_resources.end()
; ++it) { |
| 258 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE | 246 if (it->second.pool == pool && !it->second.external && !it->second.marke
dForDeletion) |
| 259 if (it->value.pool == pool && !it->value.external && !it->value.markedFo
rDeletion) | |
| 260 toDelete.append(it->key); | |
| 261 #else | |
| 262 if (it->second.pool == pool && !it->second.external && !it->value.marked
ForDeletion) | |
| 263 toDelete.append(it->first); | 247 toDelete.append(it->first); |
| 264 #endif | |
| 265 } | 248 } |
| 266 for (ResourceIdArray::iterator it = toDelete.begin(); it != toDelete.end();
++it) | 249 for (ResourceIdArray::iterator it = toDelete.begin(); it != toDelete.end();
++it) |
| 267 deleteResource(*it); | 250 deleteResource(*it); |
| 268 } | 251 } |
| 269 | 252 |
| 270 CCResourceProvider::ResourceType CCResourceProvider::resourceType(ResourceId id) | 253 CCResourceProvider::ResourceType CCResourceProvider::resourceType(ResourceId id) |
| 271 { | 254 { |
| 272 ResourceMap::iterator it = m_resources.find(id); | 255 ResourceMap::iterator it = m_resources.find(id); |
| 273 CHECK(it != m_resources.end()); | 256 CHECK(it != m_resources.end()); |
| 274 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE | |
| 275 Resource* resource = &it->value; | |
| 276 #else | |
| 277 Resource* resource = &it->second; | 257 Resource* resource = &it->second; |
| 278 #endif | |
| 279 return resource->type; | 258 return resource->type; |
| 280 } | 259 } |
| 281 | 260 |
| 282 void CCResourceProvider::upload(ResourceId id, const uint8_t* image, const IntRe
ct& imageRect, const IntRect& sourceRect, const IntSize& destOffset) | 261 void CCResourceProvider::upload(ResourceId id, const uint8_t* image, const IntRe
ct& imageRect, const IntRect& sourceRect, const IntSize& destOffset) |
| 283 { | 262 { |
| 284 ASSERT(CCProxy::isImplThread()); | 263 ASSERT(CCProxy::isImplThread()); |
| 285 ResourceMap::iterator it = m_resources.find(id); | 264 ResourceMap::iterator it = m_resources.find(id); |
| 286 CHECK(it != m_resources.end()); | 265 CHECK(it != m_resources.end()); |
| 287 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE | |
| 288 Resource* resource = &it->value; | |
| 289 #else | |
| 290 Resource* resource = &it->second; | 266 Resource* resource = &it->second; |
| 291 #endif | |
| 292 ASSERT(!resource->lockedForWrite); | 267 ASSERT(!resource->lockedForWrite); |
| 293 ASSERT(!resource->lockForReadCount); | 268 ASSERT(!resource->lockForReadCount); |
| 294 ASSERT(!resource->external); | 269 ASSERT(!resource->external); |
| 295 ASSERT(!resource->exported); | 270 ASSERT(!resource->exported); |
| 296 | 271 |
| 297 if (resource->glId) { | 272 if (resource->glId) { |
| 298 WebGraphicsContext3D* context3d = m_context->context3D(); | 273 WebGraphicsContext3D* context3d = m_context->context3D(); |
| 299 ASSERT(context3d); | 274 ASSERT(context3d); |
| 300 ASSERT(m_texSubImage.get()); | 275 ASSERT(m_texSubImage.get()); |
| 301 context3d->bindTexture(GraphicsContext3D::TEXTURE_2D, resource->glId); | 276 context3d->bindTexture(GraphicsContext3D::TEXTURE_2D, resource->glId); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 context3d->shallowFlushCHROMIUM(); | 310 context3d->shallowFlushCHROMIUM(); |
| 336 return true; | 311 return true; |
| 337 } | 312 } |
| 338 | 313 |
| 339 const CCResourceProvider::Resource* CCResourceProvider::lockForRead(ResourceId i
d) | 314 const CCResourceProvider::Resource* CCResourceProvider::lockForRead(ResourceId i
d) |
| 340 { | 315 { |
| 341 ASSERT(CCProxy::isImplThread()); | 316 ASSERT(CCProxy::isImplThread()); |
| 342 ResourceMap::iterator it = m_resources.find(id); | 317 ResourceMap::iterator it = m_resources.find(id); |
| 343 CHECK(it != m_resources.end()); | 318 CHECK(it != m_resources.end()); |
| 344 | 319 |
| 345 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE | |
| 346 Resource* resource = &it->value; | |
| 347 #else | |
| 348 Resource* resource = &it->second; | 320 Resource* resource = &it->second; |
| 349 #endif | |
| 350 ASSERT(!resource->lockedForWrite); | 321 ASSERT(!resource->lockedForWrite); |
| 351 ASSERT(!resource->exported); | 322 ASSERT(!resource->exported); |
| 352 resource->lockForReadCount++; | 323 resource->lockForReadCount++; |
| 353 return resource; | 324 return resource; |
| 354 } | 325 } |
| 355 | 326 |
| 356 void CCResourceProvider::unlockForRead(ResourceId id) | 327 void CCResourceProvider::unlockForRead(ResourceId id) |
| 357 { | 328 { |
| 358 ASSERT(CCProxy::isImplThread()); | 329 ASSERT(CCProxy::isImplThread()); |
| 359 ResourceMap::iterator it = m_resources.find(id); | 330 ResourceMap::iterator it = m_resources.find(id); |
| 360 CHECK(it != m_resources.end()); | 331 CHECK(it != m_resources.end()); |
| 361 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE | |
| 362 Resource* resource = &it->value; | |
| 363 #else | |
| 364 Resource* resource = &it->second; | 332 Resource* resource = &it->second; |
| 365 #endif | |
| 366 ASSERT(resource->lockForReadCount > 0); | 333 ASSERT(resource->lockForReadCount > 0); |
| 367 ASSERT(!resource->exported); | 334 ASSERT(!resource->exported); |
| 368 resource->lockForReadCount--; | 335 resource->lockForReadCount--; |
| 369 } | 336 } |
| 370 | 337 |
| 371 const CCResourceProvider::Resource* CCResourceProvider::lockForWrite(ResourceId
id) | 338 const CCResourceProvider::Resource* CCResourceProvider::lockForWrite(ResourceId
id) |
| 372 { | 339 { |
| 373 ASSERT(CCProxy::isImplThread()); | 340 ASSERT(CCProxy::isImplThread()); |
| 374 ResourceMap::iterator it = m_resources.find(id); | 341 ResourceMap::iterator it = m_resources.find(id); |
| 375 CHECK(it != m_resources.end()); | 342 CHECK(it != m_resources.end()); |
| 376 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE | |
| 377 Resource* resource = &it->value; | |
| 378 #else | |
| 379 Resource* resource = &it->second; | 343 Resource* resource = &it->second; |
| 380 #endif | |
| 381 ASSERT(!resource->lockedForWrite); | 344 ASSERT(!resource->lockedForWrite); |
| 382 ASSERT(!resource->lockForReadCount); | 345 ASSERT(!resource->lockForReadCount); |
| 383 ASSERT(!resource->exported); | 346 ASSERT(!resource->exported); |
| 384 ASSERT(!resource->external); | 347 ASSERT(!resource->external); |
| 385 resource->lockedForWrite = true; | 348 resource->lockedForWrite = true; |
| 386 return resource; | 349 return resource; |
| 387 } | 350 } |
| 388 | 351 |
| 389 void CCResourceProvider::unlockForWrite(ResourceId id) | 352 void CCResourceProvider::unlockForWrite(ResourceId id) |
| 390 { | 353 { |
| 391 ASSERT(CCProxy::isImplThread()); | 354 ASSERT(CCProxy::isImplThread()); |
| 392 ResourceMap::iterator it = m_resources.find(id); | 355 ResourceMap::iterator it = m_resources.find(id); |
| 393 CHECK(it != m_resources.end()); | 356 CHECK(it != m_resources.end()); |
| 394 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE | |
| 395 Resource* resource = &it->value; | |
| 396 #else | |
| 397 Resource* resource = &it->second; | 357 Resource* resource = &it->second; |
| 398 #endif | |
| 399 ASSERT(resource->lockedForWrite); | 358 ASSERT(resource->lockedForWrite); |
| 400 ASSERT(!resource->exported); | 359 ASSERT(!resource->exported); |
| 401 ASSERT(!resource->external); | 360 ASSERT(!resource->external); |
| 402 resource->lockedForWrite = false; | 361 resource->lockedForWrite = false; |
| 403 } | 362 } |
| 404 | 363 |
| 405 CCResourceProvider::ScopedReadLockGL::ScopedReadLockGL(CCResourceProvider* resou
rceProvider, CCResourceProvider::ResourceId resourceId) | 364 CCResourceProvider::ScopedReadLockGL::ScopedReadLockGL(CCResourceProvider* resou
rceProvider, CCResourceProvider::ResourceId resourceId) |
| 406 : m_resourceProvider(resourceProvider) | 365 : m_resourceProvider(resourceProvider) |
| 407 , m_resourceId(resourceId) | 366 , m_resourceId(resourceId) |
| 408 , m_textureId(resourceProvider->lockForRead(resourceId)->glId) | 367 , m_textureId(resourceProvider->lockForRead(resourceId)->glId) |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 GLC(context3d, context3d->getIntegerv(GraphicsContext3D::MAX_TEXTURE_SIZE, &
m_maxTextureSize)); | 469 GLC(context3d, context3d->getIntegerv(GraphicsContext3D::MAX_TEXTURE_SIZE, &
m_maxTextureSize)); |
| 511 return true; | 470 return true; |
| 512 } | 471 } |
| 513 | 472 |
| 514 int CCResourceProvider::createChild(int pool) | 473 int CCResourceProvider::createChild(int pool) |
| 515 { | 474 { |
| 516 ASSERT(CCProxy::isImplThread()); | 475 ASSERT(CCProxy::isImplThread()); |
| 517 Child childInfo; | 476 Child childInfo; |
| 518 childInfo.pool = pool; | 477 childInfo.pool = pool; |
| 519 int child = m_nextChild++; | 478 int child = m_nextChild++; |
| 520 m_children.add(child, childInfo); | 479 m_children[child] = childInfo; |
| 521 return child; | 480 return child; |
| 522 } | 481 } |
| 523 | 482 |
| 524 void CCResourceProvider::destroyChild(int child) | 483 void CCResourceProvider::destroyChild(int child) |
| 525 { | 484 { |
| 526 ASSERT(CCProxy::isImplThread()); | 485 ASSERT(CCProxy::isImplThread()); |
| 527 ChildMap::iterator it = m_children.find(child); | 486 ChildMap::iterator it = m_children.find(child); |
| 528 ASSERT(it != m_children.end()); | 487 ASSERT(it != m_children.end()); |
| 529 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE | |
| 530 deleteOwnedResources(it->value.pool); | |
| 531 #else | |
| 532 deleteOwnedResources(it->second.pool); | 488 deleteOwnedResources(it->second.pool); |
| 533 #endif | 489 m_children.erase(it); |
| 534 m_children.remove(it); | |
| 535 trimMailboxDeque(); | 490 trimMailboxDeque(); |
| 536 } | 491 } |
| 537 | 492 |
| 538 const CCResourceProvider::ResourceIdMap& CCResourceProvider::getChildToParentMap
(int child) const | 493 const CCResourceProvider::ResourceIdMap& CCResourceProvider::getChildToParentMap
(int child) const |
| 539 { | 494 { |
| 540 ASSERT(CCProxy::isImplThread()); | 495 ASSERT(CCProxy::isImplThread()); |
| 541 ChildMap::const_iterator it = m_children.find(child); | 496 ChildMap::const_iterator it = m_children.find(child); |
| 542 ASSERT(it != m_children.end()); | 497 ASSERT(it != m_children.end()); |
| 543 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE | |
| 544 return it->value.childToParentMap; | |
| 545 #else | |
| 546 return it->second.childToParentMap; | 498 return it->second.childToParentMap; |
| 547 #endif | |
| 548 } | 499 } |
| 549 | 500 |
| 550 CCResourceProvider::TransferableResourceList CCResourceProvider::prepareSendToPa
rent(const ResourceIdArray& resources) | 501 CCResourceProvider::TransferableResourceList CCResourceProvider::prepareSendToPa
rent(const ResourceIdArray& resources) |
| 551 { | 502 { |
| 552 ASSERT(CCProxy::isImplThread()); | 503 ASSERT(CCProxy::isImplThread()); |
| 553 TransferableResourceList list; | 504 TransferableResourceList list; |
| 554 list.syncPoint = 0; | 505 list.syncPoint = 0; |
| 555 WebGraphicsContext3D* context3d = m_context->context3D(); | 506 WebGraphicsContext3D* context3d = m_context->context3D(); |
| 556 if (!context3d || !context3d->makeContextCurrent()) { | 507 if (!context3d || !context3d->makeContextCurrent()) { |
| 557 // FIXME: Implement this path for software compositing. | 508 // FIXME: Implement this path for software compositing. |
| 558 return list; | 509 return list; |
| 559 } | 510 } |
| 560 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources
.end(); ++it) { | 511 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources
.end(); ++it) { |
| 561 TransferableResource resource; | 512 TransferableResource resource; |
| 562 if (transferResource(context3d, *it, &resource)) { | 513 if (transferResource(context3d, *it, &resource)) { |
| 563 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE | |
| 564 m_resources.find(*it)->value.exported = true; | |
| 565 #else | |
| 566 m_resources.find(*it)->second.exported = true; | 514 m_resources.find(*it)->second.exported = true; |
| 567 #endif | |
| 568 list.resources.append(resource); | 515 list.resources.append(resource); |
| 569 } | 516 } |
| 570 } | 517 } |
| 571 if (list.resources.size()) | 518 if (list.resources.size()) |
| 572 list.syncPoint = context3d->insertSyncPoint(); | 519 list.syncPoint = context3d->insertSyncPoint(); |
| 573 return list; | 520 return list; |
| 574 } | 521 } |
| 575 | 522 |
| 576 CCResourceProvider::TransferableResourceList CCResourceProvider::prepareSendToCh
ild(int child, const ResourceIdArray& resources) | 523 CCResourceProvider::TransferableResourceList CCResourceProvider::prepareSendToCh
ild(int child, const ResourceIdArray& resources) |
| 577 { | 524 { |
| 578 ASSERT(CCProxy::isImplThread()); | 525 ASSERT(CCProxy::isImplThread()); |
| 579 TransferableResourceList list; | 526 TransferableResourceList list; |
| 580 list.syncPoint = 0; | 527 list.syncPoint = 0; |
| 581 WebGraphicsContext3D* context3d = m_context->context3D(); | 528 WebGraphicsContext3D* context3d = m_context->context3D(); |
| 582 if (!context3d || !context3d->makeContextCurrent()) { | 529 if (!context3d || !context3d->makeContextCurrent()) { |
| 583 // FIXME: Implement this path for software compositing. | 530 // FIXME: Implement this path for software compositing. |
| 584 return list; | 531 return list; |
| 585 } | 532 } |
| 586 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE | |
| 587 Child& childInfo = m_children.find(child)->value; | |
| 588 #else | |
| 589 Child& childInfo = m_children.find(child)->second; | 533 Child& childInfo = m_children.find(child)->second; |
| 590 #endif | |
| 591 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources
.end(); ++it) { | 534 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources
.end(); ++it) { |
| 592 TransferableResource resource; | 535 TransferableResource resource; |
| 593 if (!transferResource(context3d, *it, &resource)) | 536 if (!transferResource(context3d, *it, &resource)) |
| 594 ASSERT_NOT_REACHED(); | 537 ASSERT_NOT_REACHED(); |
| 595 resource.id = childInfo.parentToChildMap.get(*it); | 538 ASSERT(childInfo.parentToChildMap.find(*it) != childInfo.parentToChildMa
p.end()); |
| 596 childInfo.parentToChildMap.remove(*it); | 539 resource.id = childInfo.parentToChildMap[*it]; |
| 597 childInfo.childToParentMap.remove(resource.id); | 540 childInfo.parentToChildMap.erase(*it); |
| 541 childInfo.childToParentMap.erase(resource.id); |
| 598 list.resources.append(resource); | 542 list.resources.append(resource); |
| 599 deleteResource(*it); | 543 deleteResource(*it); |
| 600 } | 544 } |
| 601 if (list.resources.size()) | 545 if (list.resources.size()) |
| 602 list.syncPoint = context3d->insertSyncPoint(); | 546 list.syncPoint = context3d->insertSyncPoint(); |
| 603 return list; | 547 return list; |
| 604 } | 548 } |
| 605 | 549 |
| 606 void CCResourceProvider::receiveFromChild(int child, const TransferableResourceL
ist& resources) | 550 void CCResourceProvider::receiveFromChild(int child, const TransferableResourceL
ist& resources) |
| 607 { | 551 { |
| 608 ASSERT(CCProxy::isImplThread()); | 552 ASSERT(CCProxy::isImplThread()); |
| 609 WebGraphicsContext3D* context3d = m_context->context3D(); | 553 WebGraphicsContext3D* context3d = m_context->context3D(); |
| 610 if (!context3d || !context3d->makeContextCurrent()) { | 554 if (!context3d || !context3d->makeContextCurrent()) { |
| 611 // FIXME: Implement this path for software compositing. | 555 // FIXME: Implement this path for software compositing. |
| 612 return; | 556 return; |
| 613 } | 557 } |
| 614 if (resources.syncPoint) { | 558 if (resources.syncPoint) { |
| 615 // NOTE: If the parent is a browser and the child a renderer, the parent | 559 // NOTE: If the parent is a browser and the child a renderer, the parent |
| 616 // is not supposed to have its context wait, because that could induce | 560 // is not supposed to have its context wait, because that could induce |
| 617 // deadlocks and/or security issues. The caller is responsible for | 561 // deadlocks and/or security issues. The caller is responsible for |
| 618 // waiting asynchronously, and resetting syncPoint before calling this. | 562 // waiting asynchronously, and resetting syncPoint before calling this. |
| 619 // However if the parent is a renderer (e.g. browser tag), it may be ok | 563 // However if the parent is a renderer (e.g. browser tag), it may be ok |
| 620 // (and is simpler) to wait. | 564 // (and is simpler) to wait. |
| 621 GLC(context3d, context3d->waitSyncPoint(resources.syncPoint)); | 565 GLC(context3d, context3d->waitSyncPoint(resources.syncPoint)); |
| 622 } | 566 } |
| 623 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE | |
| 624 Child& childInfo = m_children.find(child)->value; | |
| 625 #else | |
| 626 Child& childInfo = m_children.find(child)->second; | 567 Child& childInfo = m_children.find(child)->second; |
| 627 #endif | |
| 628 for (Vector<TransferableResource>::const_iterator it = resources.resources.b
egin(); it != resources.resources.end(); ++it) { | 568 for (Vector<TransferableResource>::const_iterator it = resources.resources.b
egin(); it != resources.resources.end(); ++it) { |
| 629 unsigned textureId; | 569 unsigned textureId; |
| 630 GLC(context3d, textureId = context3d->createTexture()); | 570 GLC(context3d, textureId = context3d->createTexture()); |
| 631 GLC(context3d, context3d->bindTexture(GraphicsContext3D::TEXTURE_2D, tex
tureId)); | 571 GLC(context3d, context3d->bindTexture(GraphicsContext3D::TEXTURE_2D, tex
tureId)); |
| 632 GLC(context3d, context3d->consumeTextureCHROMIUM(GraphicsContext3D::TEXT
URE_2D, it->mailbox.name)); | 572 GLC(context3d, context3d->consumeTextureCHROMIUM(GraphicsContext3D::TEXT
URE_2D, it->mailbox.name)); |
| 633 ResourceId id = m_nextId++; | 573 ResourceId id = m_nextId++; |
| 634 Resource resource(textureId, childInfo.pool, it->size, it->format); | 574 Resource resource(textureId, childInfo.pool, it->size, it->format); |
| 635 m_resources.add(id, resource); | 575 m_resources[id] = resource; |
| 636 m_mailboxes.append(it->mailbox); | 576 m_mailboxes.append(it->mailbox); |
| 637 childInfo.parentToChildMap.add(id, it->id); | 577 childInfo.parentToChildMap[id] = it->id; |
| 638 childInfo.childToParentMap.add(it->id, id); | 578 childInfo.childToParentMap[it->id] = id; |
| 639 } | 579 } |
| 640 } | 580 } |
| 641 | 581 |
| 642 void CCResourceProvider::receiveFromParent(const TransferableResourceList& resou
rces) | 582 void CCResourceProvider::receiveFromParent(const TransferableResourceList& resou
rces) |
| 643 { | 583 { |
| 644 ASSERT(CCProxy::isImplThread()); | 584 ASSERT(CCProxy::isImplThread()); |
| 645 WebGraphicsContext3D* context3d = m_context->context3D(); | 585 WebGraphicsContext3D* context3d = m_context->context3D(); |
| 646 if (!context3d || !context3d->makeContextCurrent()) { | 586 if (!context3d || !context3d->makeContextCurrent()) { |
| 647 // FIXME: Implement this path for software compositing. | 587 // FIXME: Implement this path for software compositing. |
| 648 return; | 588 return; |
| 649 } | 589 } |
| 650 if (resources.syncPoint) | 590 if (resources.syncPoint) |
| 651 GLC(context3d, context3d->waitSyncPoint(resources.syncPoint)); | 591 GLC(context3d, context3d->waitSyncPoint(resources.syncPoint)); |
| 652 for (Vector<TransferableResource>::const_iterator it = resources.resources.b
egin(); it != resources.resources.end(); ++it) { | 592 for (Vector<TransferableResource>::const_iterator it = resources.resources.b
egin(); it != resources.resources.end(); ++it) { |
| 653 ResourceMap::iterator mapIterator = m_resources.find(it->id); | 593 ResourceMap::iterator mapIterator = m_resources.find(it->id); |
| 654 ASSERT(mapIterator != m_resources.end()); | 594 ASSERT(mapIterator != m_resources.end()); |
| 655 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE | |
| 656 Resource* resource = &mapIterator->value; | |
| 657 #else | |
| 658 Resource* resource = &mapIterator->second; | 595 Resource* resource = &mapIterator->second; |
| 659 #endif | |
| 660 ASSERT(resource->exported); | 596 ASSERT(resource->exported); |
| 661 resource->exported = false; | 597 resource->exported = false; |
| 662 GLC(context3d, context3d->bindTexture(GraphicsContext3D::TEXTURE_2D, res
ource->glId)); | 598 GLC(context3d, context3d->bindTexture(GraphicsContext3D::TEXTURE_2D, res
ource->glId)); |
| 663 GLC(context3d, context3d->consumeTextureCHROMIUM(GraphicsContext3D::TEXT
URE_2D, it->mailbox.name)); | 599 GLC(context3d, context3d->consumeTextureCHROMIUM(GraphicsContext3D::TEXT
URE_2D, it->mailbox.name)); |
| 664 m_mailboxes.append(it->mailbox); | 600 m_mailboxes.append(it->mailbox); |
| 665 if (resource->markedForDeletion) | 601 if (resource->markedForDeletion) |
| 666 deleteResourceInternal(mapIterator); | 602 deleteResourceInternal(mapIterator); |
| 667 } | 603 } |
| 668 } | 604 } |
| 669 | 605 |
| 670 bool CCResourceProvider::transferResource(WebGraphicsContext3D* context, Resourc
eId id, TransferableResource* resource) | 606 bool CCResourceProvider::transferResource(WebGraphicsContext3D* context, Resourc
eId id, TransferableResource* resource) |
| 671 { | 607 { |
| 672 ASSERT(CCProxy::isImplThread()); | 608 ASSERT(CCProxy::isImplThread()); |
| 673 ResourceMap::const_iterator it = m_resources.find(id); | 609 ResourceMap::const_iterator it = m_resources.find(id); |
| 674 CHECK(it != m_resources.end()); | 610 CHECK(it != m_resources.end()); |
| 675 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE | |
| 676 const Resource* source = &it->value; | |
| 677 #else | |
| 678 const Resource* source = &it->second; | 611 const Resource* source = &it->second; |
| 679 #endif | |
| 680 ASSERT(!source->lockedForWrite); | 612 ASSERT(!source->lockedForWrite); |
| 681 ASSERT(!source->lockForReadCount); | 613 ASSERT(!source->lockForReadCount); |
| 682 ASSERT(!source->external); | 614 ASSERT(!source->external); |
| 683 if (source->exported) | 615 if (source->exported) |
| 684 return false; | 616 return false; |
| 685 resource->id = id; | 617 resource->id = id; |
| 686 resource->format = source->format; | 618 resource->format = source->format; |
| 687 resource->size = source->size; | 619 resource->size = source->size; |
| 688 if (!m_mailboxes.isEmpty()) | 620 if (!m_mailboxes.isEmpty()) |
| 689 resource->mailbox = m_mailboxes.takeFirst(); | 621 resource->mailbox = m_mailboxes.takeFirst(); |
| 690 else | 622 else |
| 691 GLC(context, context->genMailboxCHROMIUM(resource->mailbox.name)); | 623 GLC(context, context->genMailboxCHROMIUM(resource->mailbox.name)); |
| 692 GLC(context, context->bindTexture(GraphicsContext3D::TEXTURE_2D, source->glI
d)); | 624 GLC(context, context->bindTexture(GraphicsContext3D::TEXTURE_2D, source->glI
d)); |
| 693 GLC(context, context->produceTextureCHROMIUM(GraphicsContext3D::TEXTURE_2D,
resource->mailbox.name)); | 625 GLC(context, context->produceTextureCHROMIUM(GraphicsContext3D::TEXTURE_2D,
resource->mailbox.name)); |
| 694 return true; | 626 return true; |
| 695 } | 627 } |
| 696 | 628 |
| 697 void CCResourceProvider::trimMailboxDeque() | 629 void CCResourceProvider::trimMailboxDeque() |
| 698 { | 630 { |
| 699 // Trim the mailbox deque to the maximum number of resources we may need to | 631 // Trim the mailbox deque to the maximum number of resources we may need to |
| 700 // send. | 632 // send. |
| 701 // If we have a parent, any non-external resource not already transfered is | 633 // If we have a parent, any non-external resource not already transfered is |
| 702 // eligible to be sent to the parent. Otherwise, all resources belonging to | 634 // eligible to be sent to the parent. Otherwise, all resources belonging to |
| 703 // a child might need to be sent back to the child. | 635 // a child might need to be sent back to the child. |
| 704 size_t maxMailboxCount = 0; | 636 size_t maxMailboxCount = 0; |
| 705 if (m_context->capabilities().hasParentCompositor) { | 637 if (m_context->capabilities().hasParentCompositor) { |
| 706 for (ResourceMap::iterator it = m_resources.begin(); it != m_resources.e
nd(); ++it) { | 638 for (ResourceMap::iterator it = m_resources.begin(); it != m_resources.e
nd(); ++it) { |
| 707 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE | |
| 708 if (!it->value.exported && !it->value.external) | |
| 709 #else | |
| 710 if (!it->second.exported && !it->second.external) | 639 if (!it->second.exported && !it->second.external) |
| 711 #endif | |
| 712 ++maxMailboxCount; | 640 ++maxMailboxCount; |
| 713 } | 641 } |
| 714 } else { | 642 } else { |
| 715 base::hash_set<int> childPoolSet; | 643 base::hash_set<int> childPoolSet; |
| 716 for (ChildMap::iterator it = m_children.begin(); it != m_children.end();
++it) | 644 for (ChildMap::iterator it = m_children.begin(); it != m_children.end();
++it) |
| 717 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE | |
| 718 childPoolSet.insert(it->value.pool); | |
| 719 #else | |
| 720 childPoolSet.insert(it->second.pool); | 645 childPoolSet.insert(it->second.pool); |
| 721 #endif | |
| 722 for (ResourceMap::iterator it = m_resources.begin(); it != m_resources.e
nd(); ++it) { | 646 for (ResourceMap::iterator it = m_resources.begin(); it != m_resources.e
nd(); ++it) { |
| 723 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE | |
| 724 if (ContainsKey(childPoolSet, it->value.pool)) | |
| 725 #else | |
| 726 if (ContainsKey(childPoolSet, it->second.pool)) | 647 if (ContainsKey(childPoolSet, it->second.pool)) |
| 727 #endif | |
| 728 ++maxMailboxCount; | 648 ++maxMailboxCount; |
| 729 } | 649 } |
| 730 } | 650 } |
| 731 while (m_mailboxes.size() > maxMailboxCount) | 651 while (m_mailboxes.size() > maxMailboxCount) |
| 732 m_mailboxes.removeFirst(); | 652 m_mailboxes.removeFirst(); |
| 733 } | 653 } |
| 734 | 654 |
| 735 } | 655 } |
| OLD | NEW |