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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 237 Resource resource(textureId, gfx::Size(), 0, GL_LINEAR); | 237 Resource resource(textureId, gfx::Size(), 0, GL_LINEAR); |
| 238 resource.external = true; | 238 resource.external = true; |
| 239 resource.allocated = true; | 239 resource.allocated = true; |
| 240 m_resources[id] = resource; | 240 m_resources[id] = resource; |
| 241 return id; | 241 return id; |
| 242 } | 242 } |
| 243 | 243 |
| 244 ResourceProvider::ResourceId ResourceProvider::createResourceFromTextureMailbox( const std::string& mailbox, const base::Callback<void(unsigned)>& releaseCallbac k) | 244 ResourceProvider::ResourceId ResourceProvider::createResourceFromTextureMailbox( const std::string& mailbox, const base::Callback<void(unsigned)>& releaseCallbac k) |
| 245 { | 245 { |
| 246 DCHECK(m_threadChecker.CalledOnValidThread()); | 246 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 247 | 247 // Just store the infomration. Mailbox will be consumed in lockForRead(). |
|
danakj
2013/01/11 00:23:41
"infomration"
| |
| 248 // FIXME: As an optimization, delay consuming the mailbox | |
| 249 // and creating the texture ID until lockForRead. | |
| 250 const int8* name = reinterpret_cast<const int8*>(mailbox.data()); | |
| 251 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); | |
| 252 DCHECK(context3d); | |
| 253 unsigned textureId = context3d->createTexture(); | |
| 254 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); | |
| 255 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, name)); | |
| 256 | |
| 257 ResourceId id = m_nextId++; | 248 ResourceId id = m_nextId++; |
| 249 unsigned textureId = 0; | |
| 258 Resource resource(textureId, gfx::Size(), 0, GL_LINEAR); | 250 Resource resource(textureId, gfx::Size(), 0, GL_LINEAR); |
| 259 resource.external = true; | 251 resource.external = true; |
| 260 resource.mailbox.setName(name); | 252 resource.allocated = true; |
| 253 resource.mailbox.setName(reinterpret_cast<const int8*>(mailbox.data())); | |
| 261 resource.mailboxReleaseCallback = releaseCallback; | 254 resource.mailboxReleaseCallback = releaseCallback; |
| 262 m_resources[id] = resource; | 255 m_resources[id] = resource; |
| 263 return id; | 256 return id; |
| 264 } | 257 } |
| 265 | 258 |
| 266 void ResourceProvider::deleteResource(ResourceId id) | 259 void ResourceProvider::deleteResource(ResourceId id) |
| 267 { | 260 { |
| 268 DCHECK(m_threadChecker.CalledOnValidThread()); | 261 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 269 ResourceMap::iterator it = m_resources.find(id); | 262 ResourceMap::iterator it = m_resources.find(id); |
| 270 CHECK(it != m_resources.end()); | 263 CHECK(it != m_resources.end()); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 294 GLC(context3d, context3d->deleteQueryEXT(resource->glUploadQueryId)); | 287 GLC(context3d, context3d->deleteQueryEXT(resource->glUploadQueryId)); |
| 295 } | 288 } |
| 296 if (resource->glPixelBufferId) { | 289 if (resource->glPixelBufferId) { |
| 297 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); | 290 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); |
| 298 DCHECK(context3d); | 291 DCHECK(context3d); |
| 299 GLC(context3d, context3d->deleteBuffer(resource->glPixelBufferId)); | 292 GLC(context3d, context3d->deleteBuffer(resource->glPixelBufferId)); |
| 300 } | 293 } |
| 301 if (!resource->mailbox.isZero() && resource->external) { | 294 if (!resource->mailbox.isZero() && resource->external) { |
| 302 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); | 295 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); |
| 303 DCHECK(context3d); | 296 DCHECK(context3d); |
| 304 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->glId)); | 297 unsigned syncPoint = 0; |
| 305 GLC(context3d, context3d->produceTextureCHROMIUM(GL_TEXTURE_2D, resource ->mailbox.name)); | 298 if (resource->glId) { |
| 306 GLC(context3d, context3d->deleteTexture(resource->glId)); | 299 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->glId) ); |
| 307 if (!resource->mailboxReleaseCallback.is_null()) { | 300 GLC(context3d, context3d->produceTextureCHROMIUM(GL_TEXTURE_2D, reso urce->mailbox.name)); |
| 308 unsigned syncPoint = context3d->insertSyncPoint(); | 301 GLC(context3d, context3d->deleteTexture(resource->glId)); |
| 302 syncPoint = context3d->insertSyncPoint(); | |
| 303 } | |
| 304 if (!resource->mailboxReleaseCallback.is_null()) | |
| 309 resource->mailboxReleaseCallback.Run(syncPoint); | 305 resource->mailboxReleaseCallback.Run(syncPoint); |
| 310 } | |
| 311 } | 306 } |
| 312 if (resource->pixels) | 307 if (resource->pixels) |
| 313 delete[] resource->pixels; | 308 delete[] resource->pixels; |
| 314 if (resource->pixelBuffer) | 309 if (resource->pixelBuffer) |
| 315 delete[] resource->pixelBuffer; | 310 delete[] resource->pixelBuffer; |
| 316 | 311 |
| 317 m_resources.erase(it); | 312 m_resources.erase(it); |
| 318 } | 313 } |
| 319 | 314 |
| 320 ResourceProvider::ResourceType ResourceProvider::resourceType(ResourceId id) | 315 ResourceProvider::ResourceType ResourceProvider::resourceType(ResourceId id) |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 422 const ResourceProvider::Resource* ResourceProvider::lockForRead(ResourceId id) | 417 const ResourceProvider::Resource* ResourceProvider::lockForRead(ResourceId id) |
| 423 { | 418 { |
| 424 DCHECK(m_threadChecker.CalledOnValidThread()); | 419 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 425 ResourceMap::iterator it = m_resources.find(id); | 420 ResourceMap::iterator it = m_resources.find(id); |
| 426 CHECK(it != m_resources.end()); | 421 CHECK(it != m_resources.end()); |
| 427 Resource* resource = &it->second; | 422 Resource* resource = &it->second; |
| 428 DCHECK(!resource->lockedForWrite); | 423 DCHECK(!resource->lockedForWrite); |
| 429 DCHECK(!resource->exported); | 424 DCHECK(!resource->exported); |
| 430 DCHECK(resource->allocated); // Uninitialized! Call setPixels or lockForWrit e first. | 425 DCHECK(resource->allocated); // Uninitialized! Call setPixels or lockForWrit e first. |
| 431 | 426 |
| 427 if (!resource->glId && resource->external && !resource->mailbox.isZero()) { | |
| 428 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); | |
| 429 DCHECK(context3d); | |
| 430 resource->glId = context3d->createTexture(); | |
| 431 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->glId)); | |
| 432 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, resource ->mailbox.name)); | |
| 433 } | |
| 434 | |
| 432 resource->lockForReadCount++; | 435 resource->lockForReadCount++; |
| 433 return resource; | 436 return resource; |
| 434 } | 437 } |
| 435 | 438 |
| 436 void ResourceProvider::unlockForRead(ResourceId id) | 439 void ResourceProvider::unlockForRead(ResourceId id) |
| 437 { | 440 { |
| 438 DCHECK(m_threadChecker.CalledOnValidThread()); | 441 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 439 ResourceMap::iterator it = m_resources.find(id); | 442 ResourceMap::iterator it = m_resources.find(id); |
| 440 CHECK(it != m_resources.end()); | 443 CHECK(it != m_resources.end()); |
| 441 Resource* resource = &it->second; | 444 Resource* resource = &it->second; |
| (...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1042 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->glId)); | 1045 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->glId)); |
| 1043 if (m_useTextureStorageExt && isTextureFormatSupportedForStorage(format)) { | 1046 if (m_useTextureStorageExt && isTextureFormatSupportedForStorage(format)) { |
| 1044 GLenum storageFormat = textureToStorageFormat(format); | 1047 GLenum storageFormat = textureToStorageFormat(format); |
| 1045 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, 1, storageForma t, size.width(), size.height())); | 1048 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, 1, storageForma t, size.width(), size.height())); |
| 1046 } else | 1049 } else |
| 1047 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, 0, format, size.widt h(), size.height(), 0, format, GL_UNSIGNED_BYTE, 0)); | 1050 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, 0, format, size.widt h(), size.height(), 0, format, GL_UNSIGNED_BYTE, 0)); |
| 1048 } | 1051 } |
| 1049 | 1052 |
| 1050 | 1053 |
| 1051 } // namespace cc | 1054 } // namespace cc |
| OLD | NEW |