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 information. Mailbox will be consumed in lockForRead(). |
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.allocated = true; | 252 resource.allocated = true; |
261 resource.mailbox.setName(name); | 253 resource.mailbox.setName(reinterpret_cast<const int8*>(mailbox.data())); |
262 resource.mailboxReleaseCallback = releaseCallback; | 254 resource.mailboxReleaseCallback = releaseCallback; |
263 m_resources[id] = resource; | 255 m_resources[id] = resource; |
264 return id; | 256 return id; |
265 } | 257 } |
266 | 258 |
267 void ResourceProvider::deleteResource(ResourceId id) | 259 void ResourceProvider::deleteResource(ResourceId id) |
268 { | 260 { |
269 DCHECK(m_threadChecker.CalledOnValidThread()); | 261 DCHECK(m_threadChecker.CalledOnValidThread()); |
270 ResourceMap::iterator it = m_resources.find(id); | 262 ResourceMap::iterator it = m_resources.find(id); |
271 CHECK(it != m_resources.end()); | 263 CHECK(it != m_resources.end()); |
(...skipping 23 matching lines...) Expand all Loading... |
295 GLC(context3d, context3d->deleteQueryEXT(resource->glUploadQueryId)); | 287 GLC(context3d, context3d->deleteQueryEXT(resource->glUploadQueryId)); |
296 } | 288 } |
297 if (resource->glPixelBufferId) { | 289 if (resource->glPixelBufferId) { |
298 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); | 290 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); |
299 DCHECK(context3d); | 291 DCHECK(context3d); |
300 GLC(context3d, context3d->deleteBuffer(resource->glPixelBufferId)); | 292 GLC(context3d, context3d->deleteBuffer(resource->glPixelBufferId)); |
301 } | 293 } |
302 if (!resource->mailbox.isZero() && resource->external) { | 294 if (!resource->mailbox.isZero() && resource->external) { |
303 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); | 295 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); |
304 DCHECK(context3d); | 296 DCHECK(context3d); |
305 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->glId)); | 297 unsigned syncPoint = 0; |
306 GLC(context3d, context3d->produceTextureCHROMIUM(GL_TEXTURE_2D, resource
->mailbox.name)); | 298 if (resource->glId) { |
307 GLC(context3d, context3d->deleteTexture(resource->glId)); | 299 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->glId)
); |
308 if (!resource->mailboxReleaseCallback.is_null()) { | 300 GLC(context3d, context3d->produceTextureCHROMIUM(GL_TEXTURE_2D, reso
urce->mailbox.name)); |
309 unsigned syncPoint = context3d->insertSyncPoint(); | 301 GLC(context3d, context3d->deleteTexture(resource->glId)); |
| 302 syncPoint = context3d->insertSyncPoint(); |
| 303 } |
| 304 if (!resource->mailboxReleaseCallback.is_null()) |
310 resource->mailboxReleaseCallback.Run(syncPoint); | 305 resource->mailboxReleaseCallback.Run(syncPoint); |
311 } | |
312 } | 306 } |
313 if (resource->pixels) | 307 if (resource->pixels) |
314 delete[] resource->pixels; | 308 delete[] resource->pixels; |
315 if (resource->pixelBuffer) | 309 if (resource->pixelBuffer) |
316 delete[] resource->pixelBuffer; | 310 delete[] resource->pixelBuffer; |
317 | 311 |
318 m_resources.erase(it); | 312 m_resources.erase(it); |
319 } | 313 } |
320 | 314 |
321 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... |
423 const ResourceProvider::Resource* ResourceProvider::lockForRead(ResourceId id) | 417 const ResourceProvider::Resource* ResourceProvider::lockForRead(ResourceId id) |
424 { | 418 { |
425 DCHECK(m_threadChecker.CalledOnValidThread()); | 419 DCHECK(m_threadChecker.CalledOnValidThread()); |
426 ResourceMap::iterator it = m_resources.find(id); | 420 ResourceMap::iterator it = m_resources.find(id); |
427 CHECK(it != m_resources.end()); | 421 CHECK(it != m_resources.end()); |
428 Resource* resource = &it->second; | 422 Resource* resource = &it->second; |
429 DCHECK(!resource->lockedForWrite); | 423 DCHECK(!resource->lockedForWrite); |
430 DCHECK(!resource->exported); | 424 DCHECK(!resource->exported); |
431 DCHECK(resource->allocated); // Uninitialized! Call setPixels or lockForWrit
e first. | 425 DCHECK(resource->allocated); // Uninitialized! Call setPixels or lockForWrit
e first. |
432 | 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 |
433 resource->lockForReadCount++; | 435 resource->lockForReadCount++; |
434 return resource; | 436 return resource; |
435 } | 437 } |
436 | 438 |
437 void ResourceProvider::unlockForRead(ResourceId id) | 439 void ResourceProvider::unlockForRead(ResourceId id) |
438 { | 440 { |
439 DCHECK(m_threadChecker.CalledOnValidThread()); | 441 DCHECK(m_threadChecker.CalledOnValidThread()); |
440 ResourceMap::iterator it = m_resources.find(id); | 442 ResourceMap::iterator it = m_resources.find(id); |
441 CHECK(it != m_resources.end()); | 443 CHECK(it != m_resources.end()); |
442 Resource* resource = &it->second; | 444 Resource* resource = &it->second; |
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1043 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->glId)); | 1045 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->glId)); |
1044 if (m_useTextureStorageExt && isTextureFormatSupportedForStorage(format)) { | 1046 if (m_useTextureStorageExt && isTextureFormatSupportedForStorage(format)) { |
1045 GLenum storageFormat = textureToStorageFormat(format); | 1047 GLenum storageFormat = textureToStorageFormat(format); |
1046 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())); |
1047 } else | 1049 } else |
1048 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)); |
1049 } | 1051 } |
1050 | 1052 |
1051 | 1053 |
1052 } // namespace cc | 1054 } // namespace cc |
OLD | NEW |