Chromium Code Reviews| 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 "cc/resource_provider.h" | 5 #include "cc/resource_provider.h" |
| 6 | 6 |
| 7 #include <limits.h> | 7 #include <limits.h> |
| 8 | 8 |
| 9 #include "base/debug/alias.h" | 9 #include "base/debug/alias.h" |
| 10 #include "base/hash_tables.h" | 10 #include "base/hash_tables.h" |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 227 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL _CLAMP_TO_EDGE)); | 227 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL _CLAMP_TO_EDGE)); |
| 228 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL _CLAMP_TO_EDGE)); | 228 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL _CLAMP_TO_EDGE)); |
| 229 | 229 |
| 230 ResourceId id = m_nextId++; | 230 ResourceId id = m_nextId++; |
| 231 Resource resource(textureId, gfx::Size(), 0, GL_LINEAR); | 231 Resource resource(textureId, gfx::Size(), 0, GL_LINEAR); |
| 232 resource.external = true; | 232 resource.external = true; |
| 233 m_resources[id] = resource; | 233 m_resources[id] = resource; |
| 234 return id; | 234 return id; |
| 235 } | 235 } |
| 236 | 236 |
| 237 ResourceProvider::ResourceId ResourceProvider::createResourceFromTextureMailbox( const std::string& mailbox, const base::Callback<void(unsigned)>& releaseCallbac k) | |
| 238 { | |
| 239 DCHECK(m_threadChecker.CalledOnValidThread()); | |
| 240 | |
| 241 const int8* name = reinterpret_cast<const int8*>(mailbox.data()); | |
| 242 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); | |
| 243 DCHECK(context3d); | |
| 244 unsigned textureId = context3d->createTexture(); | |
| 245 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); | |
| 246 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, name)); | |
|
piman
2013/01/08 02:01:52
As an optimization (maybe for a follow up, add a T
alexst (slow to review)
2013/01/08 02:46:27
Done.
| |
| 247 | |
| 248 ResourceId id = m_nextId++; | |
| 249 Resource resource(textureId, gfx::Size(), 0, GL_LINEAR); | |
| 250 resource.external = true; | |
| 251 resource.mailbox.setName(name); | |
| 252 resource.mailbox.releaseCallback = releaseCallback; | |
| 253 m_resources[id] = resource; | |
| 254 return id; | |
| 255 } | |
| 256 | |
| 237 void ResourceProvider::deleteResource(ResourceId id) | 257 void ResourceProvider::deleteResource(ResourceId id) |
| 238 { | 258 { |
| 239 DCHECK(m_threadChecker.CalledOnValidThread()); | 259 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 240 ResourceMap::iterator it = m_resources.find(id); | 260 ResourceMap::iterator it = m_resources.find(id); |
| 241 CHECK(it != m_resources.end()); | 261 CHECK(it != m_resources.end()); |
| 242 Resource* resource = &it->second; | 262 Resource* resource = &it->second; |
| 243 DCHECK(!resource->lockedForWrite); | 263 DCHECK(!resource->lockedForWrite); |
| 244 DCHECK(!resource->lockForReadCount); | 264 DCHECK(!resource->lockForReadCount); |
| 245 DCHECK(!resource->markedForDeletion); | 265 DCHECK(!resource->markedForDeletion); |
| 246 | 266 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 262 if (resource->glUploadQueryId) { | 282 if (resource->glUploadQueryId) { |
| 263 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); | 283 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); |
| 264 DCHECK(context3d); | 284 DCHECK(context3d); |
| 265 GLC(context3d, context3d->deleteQueryEXT(resource->glUploadQueryId)); | 285 GLC(context3d, context3d->deleteQueryEXT(resource->glUploadQueryId)); |
| 266 } | 286 } |
| 267 if (resource->glPixelBufferId) { | 287 if (resource->glPixelBufferId) { |
| 268 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); | 288 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); |
| 269 DCHECK(context3d); | 289 DCHECK(context3d); |
| 270 GLC(context3d, context3d->deleteBuffer(resource->glPixelBufferId)); | 290 GLC(context3d, context3d->deleteBuffer(resource->glPixelBufferId)); |
| 271 } | 291 } |
| 292 if (!resource->mailbox.isZero() && resource->external) { | |
| 293 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); | |
| 294 DCHECK(context3d); | |
| 295 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->glId)); | |
| 296 GLC(context3d, context3d->produceTextureCHROMIUM(GL_TEXTURE_2D, resource ->mailbox.name)); | |
| 297 GLC(context3d, context3d->deleteTexture(resource->glId)); | |
| 298 if (!resource->mailbox.releaseCallback.is_null()) { | |
| 299 unsigned syncPoint = context3d->insertSyncPoint(); | |
| 300 resource->mailbox.releaseCallback.Run(syncPoint); | |
| 301 } | |
| 302 } | |
| 272 if (resource->pixels) | 303 if (resource->pixels) |
| 273 delete[] resource->pixels; | 304 delete[] resource->pixels; |
| 274 if (resource->pixelBuffer) | 305 if (resource->pixelBuffer) |
| 275 delete[] resource->pixelBuffer; | 306 delete[] resource->pixelBuffer; |
| 276 | 307 |
| 277 m_resources.erase(it); | 308 m_resources.erase(it); |
| 278 } | 309 } |
| 279 | 310 |
| 280 ResourceProvider::ResourceType ResourceProvider::resourceType(ResourceId id) | 311 ResourceProvider::ResourceType ResourceProvider::resourceType(ResourceId id) |
| 281 { | 312 { |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 677 | 708 |
| 678 bool ResourceProvider::transferResource(WebGraphicsContext3D* context, ResourceI d id, TransferableResource* resource) | 709 bool ResourceProvider::transferResource(WebGraphicsContext3D* context, ResourceI d id, TransferableResource* resource) |
| 679 { | 710 { |
| 680 DCHECK(m_threadChecker.CalledOnValidThread()); | 711 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 681 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); | 712 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); |
| 682 ResourceMap::iterator it = m_resources.find(id); | 713 ResourceMap::iterator it = m_resources.find(id); |
| 683 CHECK(it != m_resources.end()); | 714 CHECK(it != m_resources.end()); |
| 684 Resource* source = &it->second; | 715 Resource* source = &it->second; |
| 685 DCHECK(!source->lockedForWrite); | 716 DCHECK(!source->lockedForWrite); |
| 686 DCHECK(!source->lockForReadCount); | 717 DCHECK(!source->lockForReadCount); |
| 687 DCHECK(!source->external); | 718 DCHECK(!source->external || (source->external && !source->mailbox.isZero())) ; |
| 688 if (source->exported) | 719 if (source->exported) |
| 689 return false; | 720 return false; |
| 690 resource->id = id; | 721 resource->id = id; |
| 691 resource->format = source->format; | 722 resource->format = source->format; |
| 692 resource->filter = source->filter; | 723 resource->filter = source->filter; |
| 693 resource->size = source->size; | 724 resource->size = source->size; |
| 694 | 725 |
| 695 if (source->mailbox.isZero()) { | 726 if (source->mailbox.isZero()) { |
| 696 GLbyte name[GL_MAILBOX_SIZE_CHROMIUM]; | 727 GLbyte name[GL_MAILBOX_SIZE_CHROMIUM]; |
| 697 GLC(context3d, context3d->genMailboxCHROMIUM(name)); | 728 GLC(context3d, context3d->genMailboxCHROMIUM(name)); |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 949 return false; | 980 return false; |
| 950 } | 981 } |
| 951 | 982 |
| 952 resource->pendingSetPixels = false; | 983 resource->pendingSetPixels = false; |
| 953 unlockForWrite(id); | 984 unlockForWrite(id); |
| 954 | 985 |
| 955 return true; | 986 return true; |
| 956 } | 987 } |
| 957 | 988 |
| 958 } // namespace cc | 989 } // namespace cc |
| OLD | NEW |