| 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/resources/resource_provider.h" | 5 #include "cc/resources/resource_provider.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 | 9 |
| 10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 } | 332 } |
| 333 | 333 |
| 334 ResourceProvider::ResourceId ResourceProvider::CreateResource( | 334 ResourceProvider::ResourceId ResourceProvider::CreateResource( |
| 335 gfx::Size size, | 335 gfx::Size size, |
| 336 GLint wrap_mode, | 336 GLint wrap_mode, |
| 337 TextureUsageHint hint, | 337 TextureUsageHint hint, |
| 338 ResourceFormat format) { | 338 ResourceFormat format) { |
| 339 DCHECK(!size.IsEmpty()); | 339 DCHECK(!size.IsEmpty()); |
| 340 switch (default_resource_type_) { | 340 switch (default_resource_type_) { |
| 341 case GLTexture: | 341 case GLTexture: |
| 342 return CreateGLTexture( | 342 return CreateGLTexture(size, |
| 343 size, GL_TEXTURE_POOL_UNMANAGED_CHROMIUM, wrap_mode, hint, format); | 343 GL_TEXTURE_2D, |
| 344 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM, |
| 345 wrap_mode, |
| 346 hint, |
| 347 format); |
| 344 case Bitmap: | 348 case Bitmap: |
| 345 DCHECK_EQ(RGBA_8888, format); | 349 DCHECK_EQ(RGBA_8888, format); |
| 346 return CreateBitmap(size, wrap_mode); | 350 return CreateBitmap(size, wrap_mode); |
| 347 case InvalidType: | 351 case InvalidType: |
| 348 break; | 352 break; |
| 349 } | 353 } |
| 350 | 354 |
| 351 LOG(FATAL) << "Invalid default resource type."; | 355 LOG(FATAL) << "Invalid default resource type."; |
| 352 return 0; | 356 return 0; |
| 353 } | 357 } |
| 354 | 358 |
| 355 ResourceProvider::ResourceId ResourceProvider::CreateManagedResource( | 359 ResourceProvider::ResourceId ResourceProvider::CreateManagedResource( |
| 356 gfx::Size size, | 360 gfx::Size size, |
| 361 GLenum target, |
| 357 GLint wrap_mode, | 362 GLint wrap_mode, |
| 358 TextureUsageHint hint, | 363 TextureUsageHint hint, |
| 359 ResourceFormat format) { | 364 ResourceFormat format) { |
| 360 DCHECK(!size.IsEmpty()); | 365 DCHECK(!size.IsEmpty()); |
| 361 switch (default_resource_type_) { | 366 switch (default_resource_type_) { |
| 362 case GLTexture: | 367 case GLTexture: |
| 363 return CreateGLTexture( | 368 return CreateGLTexture(size, |
| 364 size, GL_TEXTURE_POOL_MANAGED_CHROMIUM, wrap_mode, hint, format); | 369 target, |
| 370 GL_TEXTURE_POOL_MANAGED_CHROMIUM, |
| 371 wrap_mode, |
| 372 hint, |
| 373 format); |
| 365 case Bitmap: | 374 case Bitmap: |
| 366 DCHECK_EQ(RGBA_8888, format); | 375 DCHECK_EQ(RGBA_8888, format); |
| 367 return CreateBitmap(size, wrap_mode); | 376 return CreateBitmap(size, wrap_mode); |
| 368 case InvalidType: | 377 case InvalidType: |
| 369 break; | 378 break; |
| 370 } | 379 } |
| 371 | 380 |
| 372 LOG(FATAL) << "Invalid default resource type."; | 381 LOG(FATAL) << "Invalid default resource type."; |
| 373 return 0; | 382 return 0; |
| 374 } | 383 } |
| 375 | 384 |
| 376 ResourceProvider::ResourceId ResourceProvider::CreateGLTexture( | 385 ResourceProvider::ResourceId ResourceProvider::CreateGLTexture( |
| 377 gfx::Size size, | 386 gfx::Size size, |
| 387 GLenum target, |
| 378 GLenum texture_pool, | 388 GLenum texture_pool, |
| 379 GLint wrap_mode, | 389 GLint wrap_mode, |
| 380 TextureUsageHint hint, | 390 TextureUsageHint hint, |
| 381 ResourceFormat format) { | 391 ResourceFormat format) { |
| 382 DCHECK_LE(size.width(), max_texture_size_); | 392 DCHECK_LE(size.width(), max_texture_size_); |
| 383 DCHECK_LE(size.height(), max_texture_size_); | 393 DCHECK_LE(size.height(), max_texture_size_); |
| 384 DCHECK(thread_checker_.CalledOnValidThread()); | 394 DCHECK(thread_checker_.CalledOnValidThread()); |
| 385 | 395 |
| 386 ResourceId id = next_id_++; | 396 ResourceId id = next_id_++; |
| 387 Resource resource( | 397 Resource resource( |
| 388 0, size, GL_TEXTURE_2D, GL_LINEAR, texture_pool, wrap_mode, hint, format); | 398 0, size, target, GL_LINEAR, texture_pool, wrap_mode, hint, format); |
| 389 resource.allocated = false; | 399 resource.allocated = false; |
| 390 resources_[id] = resource; | 400 resources_[id] = resource; |
| 391 return id; | 401 return id; |
| 392 } | 402 } |
| 393 | 403 |
| 394 ResourceProvider::ResourceId ResourceProvider::CreateBitmap( | 404 ResourceProvider::ResourceId ResourceProvider::CreateBitmap( |
| 395 gfx::Size size, GLint wrap_mode) { | 405 gfx::Size size, GLint wrap_mode) { |
| 396 DCHECK(thread_checker_.CalledOnValidThread()); | 406 DCHECK(thread_checker_.CalledOnValidThread()); |
| 397 | 407 |
| 398 scoped_ptr<SharedBitmap> bitmap; | 408 scoped_ptr<SharedBitmap> bitmap; |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 782 DCHECK(texture_id_); | 792 DCHECK(texture_id_); |
| 783 } | 793 } |
| 784 | 794 |
| 785 ResourceProvider::ScopedReadLockGL::~ScopedReadLockGL() { | 795 ResourceProvider::ScopedReadLockGL::~ScopedReadLockGL() { |
| 786 resource_provider_->UnlockForRead(resource_id_); | 796 resource_provider_->UnlockForRead(resource_id_); |
| 787 } | 797 } |
| 788 | 798 |
| 789 ResourceProvider::ScopedSamplerGL::ScopedSamplerGL( | 799 ResourceProvider::ScopedSamplerGL::ScopedSamplerGL( |
| 790 ResourceProvider* resource_provider, | 800 ResourceProvider* resource_provider, |
| 791 ResourceProvider::ResourceId resource_id, | 801 ResourceProvider::ResourceId resource_id, |
| 792 GLenum target, | |
| 793 GLenum filter) | 802 GLenum filter) |
| 794 : ScopedReadLockGL(resource_provider, resource_id), | 803 : ScopedReadLockGL(resource_provider, resource_id), |
| 795 target_(target), | 804 unit_(GL_TEXTURE0), |
| 796 unit_(GL_TEXTURE0) { | 805 target_(resource_provider->BindForSampling(resource_id, unit_, filter)) { |
| 797 resource_provider->BindForSampling(resource_id, target, unit_, filter); | |
| 798 } | 806 } |
| 799 | 807 |
| 800 ResourceProvider::ScopedSamplerGL::ScopedSamplerGL( | 808 ResourceProvider::ScopedSamplerGL::ScopedSamplerGL( |
| 801 ResourceProvider* resource_provider, | 809 ResourceProvider* resource_provider, |
| 802 ResourceProvider::ResourceId resource_id, | 810 ResourceProvider::ResourceId resource_id, |
| 803 GLenum target, | |
| 804 GLenum unit, | 811 GLenum unit, |
| 805 GLenum filter) | 812 GLenum filter) |
| 806 : ScopedReadLockGL(resource_provider, resource_id), | 813 : ScopedReadLockGL(resource_provider, resource_id), |
| 807 target_(target), | 814 unit_(unit), |
| 808 unit_(unit) { | 815 target_(resource_provider->BindForSampling(resource_id, unit_, filter)) { |
| 809 resource_provider->BindForSampling(resource_id, target, unit, filter); | |
| 810 } | 816 } |
| 811 | 817 |
| 812 ResourceProvider::ScopedSamplerGL::~ScopedSamplerGL() { | 818 ResourceProvider::ScopedSamplerGL::~ScopedSamplerGL() { |
| 813 } | 819 } |
| 814 | 820 |
| 815 ResourceProvider::ScopedWriteLockGL::ScopedWriteLockGL( | 821 ResourceProvider::ScopedWriteLockGL::ScopedWriteLockGL( |
| 816 ResourceProvider* resource_provider, | 822 ResourceProvider* resource_provider, |
| 817 ResourceProvider::ResourceId resource_id) | 823 ResourceProvider::ResourceId resource_id) |
| 818 : resource_provider_(resource_provider), | 824 : resource_provider_(resource_provider), |
| 819 resource_id_(resource_id), | 825 resource_id_(resource_id), |
| (...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1480 DCHECK(context3d); | 1486 DCHECK(context3d); |
| 1481 DCHECK(resource->gl_pixel_buffer_id); | 1487 DCHECK(resource->gl_pixel_buffer_id); |
| 1482 context3d->bindBuffer( | 1488 context3d->bindBuffer( |
| 1483 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1489 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| 1484 resource->gl_pixel_buffer_id); | 1490 resource->gl_pixel_buffer_id); |
| 1485 context3d->unmapBufferCHROMIUM(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM); | 1491 context3d->unmapBufferCHROMIUM(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM); |
| 1486 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | 1492 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
| 1487 } | 1493 } |
| 1488 } | 1494 } |
| 1489 | 1495 |
| 1490 void ResourceProvider::BindForSampling(ResourceProvider::ResourceId resource_id, | 1496 GLenum ResourceProvider::BindForSampling( |
| 1491 GLenum target, | 1497 ResourceProvider::ResourceId resource_id, |
| 1492 GLenum unit, | 1498 GLenum unit, |
| 1493 GLenum filter) { | 1499 GLenum filter) { |
| 1494 DCHECK(thread_checker_.CalledOnValidThread()); | 1500 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1495 WebGraphicsContext3D* context3d = Context3d(); | 1501 WebGraphicsContext3D* context3d = Context3d(); |
| 1496 ResourceMap::iterator it = resources_.find(resource_id); | 1502 ResourceMap::iterator it = resources_.find(resource_id); |
| 1497 DCHECK(it != resources_.end()); | 1503 DCHECK(it != resources_.end()); |
| 1498 Resource* resource = &it->second; | 1504 Resource* resource = &it->second; |
| 1499 DCHECK(resource->lock_for_read_count); | 1505 DCHECK(resource->lock_for_read_count); |
| 1500 DCHECK(!resource->locked_for_write || resource->set_pixels_completion_forced); | 1506 DCHECK(!resource->locked_for_write || resource->set_pixels_completion_forced); |
| 1501 | 1507 |
| 1502 ScopedSetActiveTexture scoped_active_tex(context3d, unit); | 1508 ScopedSetActiveTexture scoped_active_tex(context3d, unit); |
| 1509 GLenum target = resource->target; |
| 1503 GLC(context3d, context3d->bindTexture(target, resource->gl_id)); | 1510 GLC(context3d, context3d->bindTexture(target, resource->gl_id)); |
| 1504 if (filter != resource->filter) { | 1511 if (filter != resource->filter) { |
| 1505 DCHECK_EQ(resource->target, target); | |
| 1506 GLC(context3d, | 1512 GLC(context3d, |
| 1507 context3d->texParameteri(target, GL_TEXTURE_MIN_FILTER, filter)); | 1513 context3d->texParameteri(target, GL_TEXTURE_MIN_FILTER, filter)); |
| 1508 GLC(context3d, | 1514 GLC(context3d, |
| 1509 context3d->texParameteri(target, GL_TEXTURE_MAG_FILTER, filter)); | 1515 context3d->texParameteri(target, GL_TEXTURE_MAG_FILTER, filter)); |
| 1510 resource->filter = filter; | 1516 resource->filter = filter; |
| 1511 } | 1517 } |
| 1512 | 1518 |
| 1513 if (resource->image_id && resource->dirty_image) { | 1519 if (resource->image_id && resource->dirty_image) { |
| 1514 // Release image currently bound to texture. | 1520 // Release image currently bound to texture. |
| 1515 if (resource->bound_image_id) | 1521 if (resource->bound_image_id) |
| 1516 context3d->releaseTexImage2DCHROMIUM(target, resource->bound_image_id); | 1522 context3d->releaseTexImage2DCHROMIUM(target, resource->bound_image_id); |
| 1517 context3d->bindTexImage2DCHROMIUM(target, resource->image_id); | 1523 context3d->bindTexImage2DCHROMIUM(target, resource->image_id); |
| 1518 resource->bound_image_id = resource->image_id; | 1524 resource->bound_image_id = resource->image_id; |
| 1519 resource->dirty_image = false; | 1525 resource->dirty_image = false; |
| 1520 } | 1526 } |
| 1527 |
| 1528 return target; |
| 1521 } | 1529 } |
| 1522 | 1530 |
| 1523 void ResourceProvider::BeginSetPixels(ResourceId id) { | 1531 void ResourceProvider::BeginSetPixels(ResourceId id) { |
| 1524 Resource* resource = GetResource(id); | 1532 Resource* resource = GetResource(id); |
| 1525 DCHECK(!resource->pending_set_pixels); | 1533 DCHECK(!resource->pending_set_pixels); |
| 1526 | 1534 |
| 1527 LazyCreate(resource); | 1535 LazyCreate(resource); |
| 1528 DCHECK(resource->gl_id || resource->allocated); | 1536 DCHECK(resource->gl_id || resource->allocated); |
| 1529 DCHECK(ReadLockFenceHasPassed(resource)); | 1537 DCHECK(ReadLockFenceHasPassed(resource)); |
| 1530 DCHECK(!resource->image_id); | 1538 DCHECK(!resource->image_id); |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1830 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit); | 1838 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit); |
| 1831 return active_unit; | 1839 return active_unit; |
| 1832 } | 1840 } |
| 1833 | 1841 |
| 1834 blink::WebGraphicsContext3D* ResourceProvider::Context3d() const { | 1842 blink::WebGraphicsContext3D* ResourceProvider::Context3d() const { |
| 1835 ContextProvider* context_provider = output_surface_->context_provider(); | 1843 ContextProvider* context_provider = output_surface_->context_provider(); |
| 1836 return context_provider ? context_provider->Context3d() : NULL; | 1844 return context_provider ? context_provider->Context3d() : NULL; |
| 1837 } | 1845 } |
| 1838 | 1846 |
| 1839 } // namespace cc | 1847 } // namespace cc |
| OLD | NEW |