| 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 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 lost(false), | 259 lost(false), |
| 260 marked_for_deletion(false), | 260 marked_for_deletion(false), |
| 261 pending_set_pixels(false), | 261 pending_set_pixels(false), |
| 262 set_pixels_completion_forced(false), | 262 set_pixels_completion_forced(false), |
| 263 allocated(false), | 263 allocated(false), |
| 264 read_lock_fences_enabled(false), | 264 read_lock_fences_enabled(false), |
| 265 has_shared_bitmap_id(false), | 265 has_shared_bitmap_id(false), |
| 266 allow_overlay(false), | 266 allow_overlay(false), |
| 267 read_lock_fence(NULL), | 267 read_lock_fence(NULL), |
| 268 size(), | 268 size(), |
| 269 origin(INTERNAL), | 269 origin(Internal), |
| 270 target(0), | 270 target(0), |
| 271 original_filter(0), | 271 original_filter(0), |
| 272 filter(0), | 272 filter(0), |
| 273 image_id(0), | 273 image_id(0), |
| 274 bound_image_id(0), | 274 bound_image_id(0), |
| 275 texture_pool(0), | 275 texture_pool(0), |
| 276 wrap_mode(0), | 276 wrap_mode(0), |
| 277 hint(TEXTURE_HINT_IMMUTABLE), | 277 hint(TextureHintImmutable), |
| 278 type(RESOURCE_TYPE_INVALID), | 278 type(InvalidType), |
| 279 format(RGBA_8888), | 279 format(RGBA_8888), |
| 280 shared_bitmap(NULL), | 280 shared_bitmap(NULL), |
| 281 gpu_memory_buffer(NULL) { | 281 gpu_memory_buffer(NULL) { |
| 282 } | 282 } |
| 283 | 283 |
| 284 ResourceProvider::Resource::~Resource() {} | 284 ResourceProvider::Resource::~Resource() {} |
| 285 | 285 |
| 286 ResourceProvider::Resource::Resource(GLuint texture_id, | 286 ResourceProvider::Resource::Resource(GLuint texture_id, |
| 287 const gfx::Size& size, | 287 const gfx::Size& size, |
| 288 Origin origin, | 288 Origin origin, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 315 size(size), | 315 size(size), |
| 316 origin(origin), | 316 origin(origin), |
| 317 target(target), | 317 target(target), |
| 318 original_filter(filter), | 318 original_filter(filter), |
| 319 filter(filter), | 319 filter(filter), |
| 320 image_id(0), | 320 image_id(0), |
| 321 bound_image_id(0), | 321 bound_image_id(0), |
| 322 texture_pool(texture_pool), | 322 texture_pool(texture_pool), |
| 323 wrap_mode(wrap_mode), | 323 wrap_mode(wrap_mode), |
| 324 hint(hint), | 324 hint(hint), |
| 325 type(RESOURCE_TYPE_GL_TEXTURE), | 325 type(GLTexture), |
| 326 format(format), | 326 format(format), |
| 327 shared_bitmap(NULL), | 327 shared_bitmap(NULL), |
| 328 gpu_memory_buffer(NULL) { | 328 gpu_memory_buffer(NULL) { |
| 329 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); | 329 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); |
| 330 DCHECK_EQ(origin == INTERNAL, !!texture_pool); | 330 DCHECK_EQ(origin == Internal, !!texture_pool); |
| 331 } | 331 } |
| 332 | 332 |
| 333 ResourceProvider::Resource::Resource(uint8_t* pixels, | 333 ResourceProvider::Resource::Resource(uint8_t* pixels, |
| 334 SharedBitmap* bitmap, | 334 SharedBitmap* bitmap, |
| 335 const gfx::Size& size, | 335 const gfx::Size& size, |
| 336 Origin origin, | 336 Origin origin, |
| 337 GLenum filter, | 337 GLenum filter, |
| 338 GLint wrap_mode) | 338 GLint wrap_mode) |
| 339 : child_id(0), | 339 : child_id(0), |
| 340 gl_id(0), | 340 gl_id(0), |
| (...skipping 17 matching lines...) Expand all Loading... |
| 358 read_lock_fence(NULL), | 358 read_lock_fence(NULL), |
| 359 size(size), | 359 size(size), |
| 360 origin(origin), | 360 origin(origin), |
| 361 target(0), | 361 target(0), |
| 362 original_filter(filter), | 362 original_filter(filter), |
| 363 filter(filter), | 363 filter(filter), |
| 364 image_id(0), | 364 image_id(0), |
| 365 bound_image_id(0), | 365 bound_image_id(0), |
| 366 texture_pool(0), | 366 texture_pool(0), |
| 367 wrap_mode(wrap_mode), | 367 wrap_mode(wrap_mode), |
| 368 hint(TEXTURE_HINT_IMMUTABLE), | 368 hint(TextureHintImmutable), |
| 369 type(RESOURCE_TYPE_BITMAP), | 369 type(Bitmap), |
| 370 format(RGBA_8888), | 370 format(RGBA_8888), |
| 371 shared_bitmap(bitmap), | 371 shared_bitmap(bitmap), |
| 372 gpu_memory_buffer(NULL) { | 372 gpu_memory_buffer(NULL) { |
| 373 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); | 373 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); |
| 374 DCHECK(origin == DELEGATED || pixels); | 374 DCHECK(origin == Delegated || pixels); |
| 375 if (bitmap) | 375 if (bitmap) |
| 376 shared_bitmap_id = bitmap->id(); | 376 shared_bitmap_id = bitmap->id(); |
| 377 } | 377 } |
| 378 | 378 |
| 379 ResourceProvider::Resource::Resource(const SharedBitmapId& bitmap_id, | 379 ResourceProvider::Resource::Resource(const SharedBitmapId& bitmap_id, |
| 380 const gfx::Size& size, | 380 const gfx::Size& size, |
| 381 Origin origin, | 381 Origin origin, |
| 382 GLenum filter, | 382 GLenum filter, |
| 383 GLint wrap_mode) | 383 GLint wrap_mode) |
| 384 : child_id(0), | 384 : child_id(0), |
| (...skipping 18 matching lines...) Expand all Loading... |
| 403 read_lock_fence(NULL), | 403 read_lock_fence(NULL), |
| 404 size(size), | 404 size(size), |
| 405 origin(origin), | 405 origin(origin), |
| 406 target(0), | 406 target(0), |
| 407 original_filter(filter), | 407 original_filter(filter), |
| 408 filter(filter), | 408 filter(filter), |
| 409 image_id(0), | 409 image_id(0), |
| 410 bound_image_id(0), | 410 bound_image_id(0), |
| 411 texture_pool(0), | 411 texture_pool(0), |
| 412 wrap_mode(wrap_mode), | 412 wrap_mode(wrap_mode), |
| 413 hint(TEXTURE_HINT_IMMUTABLE), | 413 hint(TextureHintImmutable), |
| 414 type(RESOURCE_TYPE_BITMAP), | 414 type(Bitmap), |
| 415 format(RGBA_8888), | 415 format(RGBA_8888), |
| 416 shared_bitmap_id(bitmap_id), | 416 shared_bitmap_id(bitmap_id), |
| 417 shared_bitmap(NULL), | 417 shared_bitmap(NULL), |
| 418 gpu_memory_buffer(NULL) { | 418 gpu_memory_buffer(NULL) { |
| 419 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); | 419 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); |
| 420 } | 420 } |
| 421 | 421 |
| 422 ResourceProvider::Child::Child() : marked_for_deletion(false) {} | 422 ResourceProvider::Child::Child() : marked_for_deletion(false) {} |
| 423 | 423 |
| 424 ResourceProvider::Child::~Child() {} | 424 ResourceProvider::Child::~Child() {} |
| (...skipping 13 matching lines...) Expand all Loading... |
| 438 blocking_main_thread_task_runner, | 438 blocking_main_thread_task_runner, |
| 439 highp_threshold_min, | 439 highp_threshold_min, |
| 440 use_rgba_4444_texture_format, | 440 use_rgba_4444_texture_format, |
| 441 id_allocation_chunk_size)); | 441 id_allocation_chunk_size)); |
| 442 | 442 |
| 443 if (resource_provider->ContextGL()) | 443 if (resource_provider->ContextGL()) |
| 444 resource_provider->InitializeGL(); | 444 resource_provider->InitializeGL(); |
| 445 else | 445 else |
| 446 resource_provider->InitializeSoftware(); | 446 resource_provider->InitializeSoftware(); |
| 447 | 447 |
| 448 DCHECK_NE(RESOURCE_TYPE_INVALID, resource_provider->default_resource_type()); | 448 DCHECK_NE(InvalidType, resource_provider->default_resource_type()); |
| 449 return resource_provider.Pass(); | 449 return resource_provider.Pass(); |
| 450 } | 450 } |
| 451 | 451 |
| 452 ResourceProvider::~ResourceProvider() { | 452 ResourceProvider::~ResourceProvider() { |
| 453 while (!children_.empty()) | 453 while (!children_.empty()) |
| 454 DestroyChildInternal(children_.begin(), FOR_SHUTDOWN); | 454 DestroyChildInternal(children_.begin(), ForShutdown); |
| 455 while (!resources_.empty()) | 455 while (!resources_.empty()) |
| 456 DeleteResourceInternal(resources_.begin(), FOR_SHUTDOWN); | 456 DeleteResourceInternal(resources_.begin(), ForShutdown); |
| 457 | 457 |
| 458 CleanUpGLIfNeeded(); | 458 CleanUpGLIfNeeded(); |
| 459 } | 459 } |
| 460 | 460 |
| 461 bool ResourceProvider::InUseByConsumer(ResourceId id) { | 461 bool ResourceProvider::InUseByConsumer(ResourceId id) { |
| 462 Resource* resource = GetResource(id); | 462 Resource* resource = GetResource(id); |
| 463 return resource->lock_for_read_count > 0 || resource->exported_count > 0 || | 463 return resource->lock_for_read_count > 0 || resource->exported_count > 0 || |
| 464 resource->lost; | 464 resource->lost; |
| 465 } | 465 } |
| 466 | 466 |
| 467 bool ResourceProvider::IsLost(ResourceId id) { | 467 bool ResourceProvider::IsLost(ResourceId id) { |
| 468 Resource* resource = GetResource(id); | 468 Resource* resource = GetResource(id); |
| 469 return resource->lost; | 469 return resource->lost; |
| 470 } | 470 } |
| 471 | 471 |
| 472 bool ResourceProvider::AllowOverlay(ResourceId id) { | 472 bool ResourceProvider::AllowOverlay(ResourceId id) { |
| 473 Resource* resource = GetResource(id); | 473 Resource* resource = GetResource(id); |
| 474 return resource->allow_overlay; | 474 return resource->allow_overlay; |
| 475 } | 475 } |
| 476 | 476 |
| 477 ResourceProvider::ResourceId ResourceProvider::CreateResource( | 477 ResourceProvider::ResourceId ResourceProvider::CreateResource( |
| 478 const gfx::Size& size, | 478 const gfx::Size& size, |
| 479 GLint wrap_mode, | 479 GLint wrap_mode, |
| 480 TextureHint hint, | 480 TextureHint hint, |
| 481 ResourceFormat format) { | 481 ResourceFormat format) { |
| 482 DCHECK(!size.IsEmpty()); | 482 DCHECK(!size.IsEmpty()); |
| 483 switch (default_resource_type_) { | 483 switch (default_resource_type_) { |
| 484 case RESOURCE_TYPE_GL_TEXTURE: | 484 case GLTexture: |
| 485 return CreateGLTexture(size, | 485 return CreateGLTexture(size, |
| 486 GL_TEXTURE_2D, | 486 GL_TEXTURE_2D, |
| 487 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM, | 487 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM, |
| 488 wrap_mode, | 488 wrap_mode, |
| 489 hint, | 489 hint, |
| 490 format); | 490 format); |
| 491 case RESOURCE_TYPE_BITMAP: | 491 case Bitmap: |
| 492 DCHECK_EQ(RGBA_8888, format); | 492 DCHECK_EQ(RGBA_8888, format); |
| 493 return CreateBitmap(size, wrap_mode); | 493 return CreateBitmap(size, wrap_mode); |
| 494 case RESOURCE_TYPE_INVALID: | 494 case InvalidType: |
| 495 break; | 495 break; |
| 496 } | 496 } |
| 497 | 497 |
| 498 LOG(FATAL) << "Invalid default resource type."; | 498 LOG(FATAL) << "Invalid default resource type."; |
| 499 return 0; | 499 return 0; |
| 500 } | 500 } |
| 501 | 501 |
| 502 ResourceProvider::ResourceId ResourceProvider::CreateManagedResource( | 502 ResourceProvider::ResourceId ResourceProvider::CreateManagedResource( |
| 503 const gfx::Size& size, | 503 const gfx::Size& size, |
| 504 GLenum target, | 504 GLenum target, |
| 505 GLint wrap_mode, | 505 GLint wrap_mode, |
| 506 TextureHint hint, | 506 TextureHint hint, |
| 507 ResourceFormat format) { | 507 ResourceFormat format) { |
| 508 DCHECK(!size.IsEmpty()); | 508 DCHECK(!size.IsEmpty()); |
| 509 switch (default_resource_type_) { | 509 switch (default_resource_type_) { |
| 510 case RESOURCE_TYPE_GL_TEXTURE: | 510 case GLTexture: |
| 511 return CreateGLTexture(size, | 511 return CreateGLTexture(size, |
| 512 target, | 512 target, |
| 513 GL_TEXTURE_POOL_MANAGED_CHROMIUM, | 513 GL_TEXTURE_POOL_MANAGED_CHROMIUM, |
| 514 wrap_mode, | 514 wrap_mode, |
| 515 hint, | 515 hint, |
| 516 format); | 516 format); |
| 517 case RESOURCE_TYPE_BITMAP: | 517 case Bitmap: |
| 518 DCHECK_EQ(RGBA_8888, format); | 518 DCHECK_EQ(RGBA_8888, format); |
| 519 return CreateBitmap(size, wrap_mode); | 519 return CreateBitmap(size, wrap_mode); |
| 520 case RESOURCE_TYPE_INVALID: | 520 case InvalidType: |
| 521 break; | 521 break; |
| 522 } | 522 } |
| 523 | 523 |
| 524 LOG(FATAL) << "Invalid default resource type."; | 524 LOG(FATAL) << "Invalid default resource type."; |
| 525 return 0; | 525 return 0; |
| 526 } | 526 } |
| 527 | 527 |
| 528 ResourceProvider::ResourceId ResourceProvider::CreateGLTexture( | 528 ResourceProvider::ResourceId ResourceProvider::CreateGLTexture( |
| 529 const gfx::Size& size, | 529 const gfx::Size& size, |
| 530 GLenum target, | 530 GLenum target, |
| 531 GLenum texture_pool, | 531 GLenum texture_pool, |
| 532 GLint wrap_mode, | 532 GLint wrap_mode, |
| 533 TextureHint hint, | 533 TextureHint hint, |
| 534 ResourceFormat format) { | 534 ResourceFormat format) { |
| 535 DCHECK_LE(size.width(), max_texture_size_); | 535 DCHECK_LE(size.width(), max_texture_size_); |
| 536 DCHECK_LE(size.height(), max_texture_size_); | 536 DCHECK_LE(size.height(), max_texture_size_); |
| 537 DCHECK(thread_checker_.CalledOnValidThread()); | 537 DCHECK(thread_checker_.CalledOnValidThread()); |
| 538 | 538 |
| 539 ResourceId id = next_id_++; | 539 ResourceId id = next_id_++; |
| 540 Resource resource(0, size, Resource::INTERNAL, target, GL_LINEAR, | 540 Resource resource(0, |
| 541 texture_pool, wrap_mode, hint, format); | 541 size, |
| 542 Resource::Internal, |
| 543 target, |
| 544 GL_LINEAR, |
| 545 texture_pool, |
| 546 wrap_mode, |
| 547 hint, |
| 548 format); |
| 542 resource.allocated = false; | 549 resource.allocated = false; |
| 543 resources_[id] = resource; | 550 resources_[id] = resource; |
| 544 return id; | 551 return id; |
| 545 } | 552 } |
| 546 | 553 |
| 547 ResourceProvider::ResourceId ResourceProvider::CreateBitmap( | 554 ResourceProvider::ResourceId ResourceProvider::CreateBitmap( |
| 548 const gfx::Size& size, GLint wrap_mode) { | 555 const gfx::Size& size, GLint wrap_mode) { |
| 549 DCHECK(thread_checker_.CalledOnValidThread()); | 556 DCHECK(thread_checker_.CalledOnValidThread()); |
| 550 | 557 |
| 551 scoped_ptr<SharedBitmap> bitmap = | 558 scoped_ptr<SharedBitmap> bitmap = |
| 552 shared_bitmap_manager_->AllocateSharedBitmap(size); | 559 shared_bitmap_manager_->AllocateSharedBitmap(size); |
| 553 uint8_t* pixels = bitmap->pixels(); | 560 uint8_t* pixels = bitmap->pixels(); |
| 554 DCHECK(pixels); | 561 DCHECK(pixels); |
| 555 | 562 |
| 556 ResourceId id = next_id_++; | 563 ResourceId id = next_id_++; |
| 557 Resource resource(pixels, bitmap.release(), size, Resource::INTERNAL, | 564 Resource resource( |
| 558 GL_LINEAR, wrap_mode); | 565 pixels, bitmap.release(), size, Resource::Internal, GL_LINEAR, wrap_mode); |
| 559 resource.allocated = true; | 566 resource.allocated = true; |
| 560 resources_[id] = resource; | 567 resources_[id] = resource; |
| 561 return id; | 568 return id; |
| 562 } | 569 } |
| 563 | 570 |
| 564 ResourceProvider::ResourceId ResourceProvider::CreateResourceFromIOSurface( | 571 ResourceProvider::ResourceId ResourceProvider::CreateResourceFromIOSurface( |
| 565 const gfx::Size& size, | 572 const gfx::Size& size, |
| 566 unsigned io_surface_id) { | 573 unsigned io_surface_id) { |
| 567 DCHECK(thread_checker_.CalledOnValidThread()); | 574 DCHECK(thread_checker_.CalledOnValidThread()); |
| 568 | 575 |
| 569 ResourceId id = next_id_++; | 576 ResourceId id = next_id_++; |
| 570 Resource resource(0, gfx::Size(), Resource::INTERNAL, | 577 Resource resource(0, |
| 571 GL_TEXTURE_RECTANGLE_ARB, GL_LINEAR, | 578 gfx::Size(), |
| 572 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM, GL_CLAMP_TO_EDGE, | 579 Resource::Internal, |
| 573 TEXTURE_HINT_IMMUTABLE, RGBA_8888); | 580 GL_TEXTURE_RECTANGLE_ARB, |
| 581 GL_LINEAR, |
| 582 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM, |
| 583 GL_CLAMP_TO_EDGE, |
| 584 TextureHintImmutable, |
| 585 RGBA_8888); |
| 574 LazyCreate(&resource); | 586 LazyCreate(&resource); |
| 575 GLES2Interface* gl = ContextGL(); | 587 GLES2Interface* gl = ContextGL(); |
| 576 DCHECK(gl); | 588 DCHECK(gl); |
| 577 gl->BindTexture(GL_TEXTURE_RECTANGLE_ARB, resource.gl_id); | 589 gl->BindTexture(GL_TEXTURE_RECTANGLE_ARB, resource.gl_id); |
| 578 gl->TexImageIOSurface2DCHROMIUM( | 590 gl->TexImageIOSurface2DCHROMIUM( |
| 579 GL_TEXTURE_RECTANGLE_ARB, size.width(), size.height(), io_surface_id, 0); | 591 GL_TEXTURE_RECTANGLE_ARB, size.width(), size.height(), io_surface_id, 0); |
| 580 resource.allocated = true; | 592 resource.allocated = true; |
| 581 resources_[id] = resource; | 593 resources_[id] = resource; |
| 582 return id; | 594 return id; |
| 583 } | 595 } |
| 584 | 596 |
| 585 ResourceProvider::ResourceId ResourceProvider::CreateResourceFromTextureMailbox( | 597 ResourceProvider::ResourceId ResourceProvider::CreateResourceFromTextureMailbox( |
| 586 const TextureMailbox& mailbox, | 598 const TextureMailbox& mailbox, |
| 587 scoped_ptr<SingleReleaseCallbackImpl> release_callback_impl) { | 599 scoped_ptr<SingleReleaseCallbackImpl> release_callback_impl) { |
| 588 DCHECK(thread_checker_.CalledOnValidThread()); | 600 DCHECK(thread_checker_.CalledOnValidThread()); |
| 589 // Just store the information. Mailbox will be consumed in LockForRead(). | 601 // Just store the information. Mailbox will be consumed in LockForRead(). |
| 590 ResourceId id = next_id_++; | 602 ResourceId id = next_id_++; |
| 591 DCHECK(mailbox.IsValid()); | 603 DCHECK(mailbox.IsValid()); |
| 592 Resource& resource = resources_[id]; | 604 Resource& resource = resources_[id]; |
| 593 if (mailbox.IsTexture()) { | 605 if (mailbox.IsTexture()) { |
| 594 resource = Resource(0, gfx::Size(), Resource::EXTERNAL, mailbox.target(), | 606 resource = Resource(0, |
| 595 mailbox.nearest_neighbor() ? GL_NEAREST : GL_LINEAR, 0, | 607 gfx::Size(), |
| 596 GL_CLAMP_TO_EDGE, TEXTURE_HINT_IMMUTABLE, RGBA_8888); | 608 Resource::External, |
| 609 mailbox.target(), |
| 610 mailbox.nearest_neighbor() ? GL_NEAREST : GL_LINEAR, |
| 611 0, |
| 612 GL_CLAMP_TO_EDGE, |
| 613 TextureHintImmutable, |
| 614 RGBA_8888); |
| 597 } else { | 615 } else { |
| 598 DCHECK(mailbox.IsSharedMemory()); | 616 DCHECK(mailbox.IsSharedMemory()); |
| 599 SharedBitmap* shared_bitmap = mailbox.shared_bitmap(); | 617 SharedBitmap* shared_bitmap = mailbox.shared_bitmap(); |
| 600 uint8_t* pixels = shared_bitmap->pixels(); | 618 uint8_t* pixels = shared_bitmap->pixels(); |
| 601 DCHECK(pixels); | 619 DCHECK(pixels); |
| 602 resource = Resource(pixels, shared_bitmap, mailbox.shared_memory_size(), | 620 resource = Resource(pixels, shared_bitmap, mailbox.shared_memory_size(), |
| 603 Resource::EXTERNAL, GL_LINEAR, GL_CLAMP_TO_EDGE); | 621 Resource::External, GL_LINEAR, GL_CLAMP_TO_EDGE); |
| 604 } | 622 } |
| 605 resource.allocated = true; | 623 resource.allocated = true; |
| 606 resource.mailbox = mailbox; | 624 resource.mailbox = mailbox; |
| 607 resource.release_callback_impl = | 625 resource.release_callback_impl = |
| 608 base::Bind(&SingleReleaseCallbackImpl::Run, | 626 base::Bind(&SingleReleaseCallbackImpl::Run, |
| 609 base::Owned(release_callback_impl.release())); | 627 base::Owned(release_callback_impl.release())); |
| 610 resource.allow_overlay = mailbox.allow_overlay(); | 628 resource.allow_overlay = mailbox.allow_overlay(); |
| 611 return id; | 629 return id; |
| 612 } | 630 } |
| 613 | 631 |
| 614 void ResourceProvider::DeleteResource(ResourceId id) { | 632 void ResourceProvider::DeleteResource(ResourceId id) { |
| 615 DCHECK(thread_checker_.CalledOnValidThread()); | 633 DCHECK(thread_checker_.CalledOnValidThread()); |
| 616 ResourceMap::iterator it = resources_.find(id); | 634 ResourceMap::iterator it = resources_.find(id); |
| 617 CHECK(it != resources_.end()); | 635 CHECK(it != resources_.end()); |
| 618 Resource* resource = &it->second; | 636 Resource* resource = &it->second; |
| 619 DCHECK(!resource->marked_for_deletion); | 637 DCHECK(!resource->marked_for_deletion); |
| 620 DCHECK_EQ(resource->imported_count, 0); | 638 DCHECK_EQ(resource->imported_count, 0); |
| 621 DCHECK(resource->pending_set_pixels || !resource->locked_for_write); | 639 DCHECK(resource->pending_set_pixels || !resource->locked_for_write); |
| 622 | 640 |
| 623 if (resource->exported_count > 0 || resource->lock_for_read_count > 0) { | 641 if (resource->exported_count > 0 || resource->lock_for_read_count > 0) { |
| 624 resource->marked_for_deletion = true; | 642 resource->marked_for_deletion = true; |
| 625 return; | 643 return; |
| 626 } else { | 644 } else { |
| 627 DeleteResourceInternal(it, NORMAL); | 645 DeleteResourceInternal(it, Normal); |
| 628 } | 646 } |
| 629 } | 647 } |
| 630 | 648 |
| 631 void ResourceProvider::DeleteResourceInternal(ResourceMap::iterator it, | 649 void ResourceProvider::DeleteResourceInternal(ResourceMap::iterator it, |
| 632 DeleteStyle style) { | 650 DeleteStyle style) { |
| 633 TRACE_EVENT0("cc", "ResourceProvider::DeleteResourceInternal"); | 651 TRACE_EVENT0("cc", "ResourceProvider::DeleteResourceInternal"); |
| 634 Resource* resource = &it->second; | 652 Resource* resource = &it->second; |
| 635 bool lost_resource = resource->lost; | 653 bool lost_resource = resource->lost; |
| 636 | 654 |
| 637 DCHECK(resource->exported_count == 0 || style != NORMAL); | 655 DCHECK(resource->exported_count == 0 || style != Normal); |
| 638 if (style == FOR_SHUTDOWN && resource->exported_count > 0) | 656 if (style == ForShutdown && resource->exported_count > 0) |
| 639 lost_resource = true; | 657 lost_resource = true; |
| 640 | 658 |
| 641 if (resource->image_id) { | 659 if (resource->image_id) { |
| 642 DCHECK(resource->origin == Resource::INTERNAL); | 660 DCHECK(resource->origin == Resource::Internal); |
| 643 GLES2Interface* gl = ContextGL(); | 661 GLES2Interface* gl = ContextGL(); |
| 644 DCHECK(gl); | 662 DCHECK(gl); |
| 645 GLC(gl, gl->DestroyImageCHROMIUM(resource->image_id)); | 663 GLC(gl, gl->DestroyImageCHROMIUM(resource->image_id)); |
| 646 } | 664 } |
| 647 if (resource->gl_upload_query_id) { | 665 if (resource->gl_upload_query_id) { |
| 648 DCHECK(resource->origin == Resource::INTERNAL); | 666 DCHECK(resource->origin == Resource::Internal); |
| 649 GLES2Interface* gl = ContextGL(); | 667 GLES2Interface* gl = ContextGL(); |
| 650 DCHECK(gl); | 668 DCHECK(gl); |
| 651 GLC(gl, gl->DeleteQueriesEXT(1, &resource->gl_upload_query_id)); | 669 GLC(gl, gl->DeleteQueriesEXT(1, &resource->gl_upload_query_id)); |
| 652 } | 670 } |
| 653 if (resource->gl_read_lock_query_id) { | 671 if (resource->gl_read_lock_query_id) { |
| 654 DCHECK(resource->origin == Resource::INTERNAL); | 672 DCHECK(resource->origin == Resource::Internal); |
| 655 GLES2Interface* gl = ContextGL(); | 673 GLES2Interface* gl = ContextGL(); |
| 656 DCHECK(gl); | 674 DCHECK(gl); |
| 657 GLC(gl, gl->DeleteQueriesEXT(1, &resource->gl_read_lock_query_id)); | 675 GLC(gl, gl->DeleteQueriesEXT(1, &resource->gl_read_lock_query_id)); |
| 658 } | 676 } |
| 659 if (resource->gl_pixel_buffer_id) { | 677 if (resource->gl_pixel_buffer_id) { |
| 660 DCHECK(resource->origin == Resource::INTERNAL); | 678 DCHECK(resource->origin == Resource::Internal); |
| 661 GLES2Interface* gl = ContextGL(); | 679 GLES2Interface* gl = ContextGL(); |
| 662 DCHECK(gl); | 680 DCHECK(gl); |
| 663 GLC(gl, gl->DeleteBuffers(1, &resource->gl_pixel_buffer_id)); | 681 GLC(gl, gl->DeleteBuffers(1, &resource->gl_pixel_buffer_id)); |
| 664 } | 682 } |
| 665 if (resource->origin == Resource::EXTERNAL) { | 683 if (resource->origin == Resource::External) { |
| 666 DCHECK(resource->mailbox.IsValid()); | 684 DCHECK(resource->mailbox.IsValid()); |
| 667 GLuint sync_point = resource->mailbox.sync_point(); | 685 GLuint sync_point = resource->mailbox.sync_point(); |
| 668 if (resource->type == RESOURCE_TYPE_GL_TEXTURE) { | 686 if (resource->type == GLTexture) { |
| 669 DCHECK(resource->mailbox.IsTexture()); | 687 DCHECK(resource->mailbox.IsTexture()); |
| 670 lost_resource |= lost_output_surface_; | 688 lost_resource |= lost_output_surface_; |
| 671 GLES2Interface* gl = ContextGL(); | 689 GLES2Interface* gl = ContextGL(); |
| 672 DCHECK(gl); | 690 DCHECK(gl); |
| 673 if (resource->gl_id) { | 691 if (resource->gl_id) { |
| 674 GLC(gl, gl->DeleteTextures(1, &resource->gl_id)); | 692 GLC(gl, gl->DeleteTextures(1, &resource->gl_id)); |
| 675 resource->gl_id = 0; | 693 resource->gl_id = 0; |
| 676 if (!lost_resource) | 694 if (!lost_resource) |
| 677 sync_point = gl->InsertSyncPointCHROMIUM(); | 695 sync_point = gl->InsertSyncPointCHROMIUM(); |
| 678 } | 696 } |
| 679 } else { | 697 } else { |
| 680 DCHECK(resource->mailbox.IsSharedMemory()); | 698 DCHECK(resource->mailbox.IsSharedMemory()); |
| 681 resource->shared_bitmap = nullptr; | 699 resource->shared_bitmap = nullptr; |
| 682 resource->pixels = nullptr; | 700 resource->pixels = nullptr; |
| 683 } | 701 } |
| 684 resource->release_callback_impl.Run( | 702 resource->release_callback_impl.Run( |
| 685 sync_point, lost_resource, blocking_main_thread_task_runner_); | 703 sync_point, lost_resource, blocking_main_thread_task_runner_); |
| 686 } | 704 } |
| 687 if (resource->gl_id) { | 705 if (resource->gl_id) { |
| 688 GLES2Interface* gl = ContextGL(); | 706 GLES2Interface* gl = ContextGL(); |
| 689 DCHECK(gl); | 707 DCHECK(gl); |
| 690 GLC(gl, gl->DeleteTextures(1, &resource->gl_id)); | 708 GLC(gl, gl->DeleteTextures(1, &resource->gl_id)); |
| 691 resource->gl_id = 0; | 709 resource->gl_id = 0; |
| 692 } | 710 } |
| 693 if (resource->shared_bitmap) { | 711 if (resource->shared_bitmap) { |
| 694 DCHECK(resource->origin != Resource::EXTERNAL); | 712 DCHECK(resource->origin != Resource::External); |
| 695 DCHECK_EQ(RESOURCE_TYPE_BITMAP, resource->type); | 713 DCHECK_EQ(Bitmap, resource->type); |
| 696 delete resource->shared_bitmap; | 714 delete resource->shared_bitmap; |
| 697 resource->pixels = NULL; | 715 resource->pixels = NULL; |
| 698 } | 716 } |
| 699 if (resource->pixels) { | 717 if (resource->pixels) { |
| 700 DCHECK(resource->origin == Resource::INTERNAL); | 718 DCHECK(resource->origin == Resource::Internal); |
| 701 delete[] resource->pixels; | 719 delete[] resource->pixels; |
| 702 resource->pixels = NULL; | 720 resource->pixels = NULL; |
| 703 } | 721 } |
| 704 if (resource->gpu_memory_buffer) { | 722 if (resource->gpu_memory_buffer) { |
| 705 DCHECK(resource->origin == Resource::INTERNAL); | 723 DCHECK(resource->origin == Resource::Internal); |
| 706 delete resource->gpu_memory_buffer; | 724 delete resource->gpu_memory_buffer; |
| 707 resource->gpu_memory_buffer = NULL; | 725 resource->gpu_memory_buffer = NULL; |
| 708 } | 726 } |
| 709 resources_.erase(it); | 727 resources_.erase(it); |
| 710 } | 728 } |
| 711 | 729 |
| 712 ResourceProvider::ResourceType ResourceProvider::GetResourceType( | 730 ResourceProvider::ResourceType ResourceProvider::GetResourceType( |
| 713 ResourceId id) { | 731 ResourceId id) { |
| 714 return GetResource(id)->type; | 732 return GetResource(id)->type; |
| 715 } | 733 } |
| 716 | 734 |
| 717 void ResourceProvider::SetPixels(ResourceId id, | 735 void ResourceProvider::SetPixels(ResourceId id, |
| 718 const uint8_t* image, | 736 const uint8_t* image, |
| 719 const gfx::Rect& image_rect, | 737 const gfx::Rect& image_rect, |
| 720 const gfx::Rect& source_rect, | 738 const gfx::Rect& source_rect, |
| 721 const gfx::Vector2d& dest_offset) { | 739 const gfx::Vector2d& dest_offset) { |
| 722 Resource* resource = GetResource(id); | 740 Resource* resource = GetResource(id); |
| 723 DCHECK(!resource->locked_for_write); | 741 DCHECK(!resource->locked_for_write); |
| 724 DCHECK(!resource->lock_for_read_count); | 742 DCHECK(!resource->lock_for_read_count); |
| 725 DCHECK(resource->origin == Resource::INTERNAL); | 743 DCHECK(resource->origin == Resource::Internal); |
| 726 DCHECK_EQ(resource->exported_count, 0); | 744 DCHECK_EQ(resource->exported_count, 0); |
| 727 DCHECK(ReadLockFenceHasPassed(resource)); | 745 DCHECK(ReadLockFenceHasPassed(resource)); |
| 728 LazyAllocate(resource); | 746 LazyAllocate(resource); |
| 729 | 747 |
| 730 if (resource->type == RESOURCE_TYPE_GL_TEXTURE) { | 748 if (resource->type == GLTexture) { |
| 731 DCHECK(resource->gl_id); | 749 DCHECK(resource->gl_id); |
| 732 DCHECK(!resource->pending_set_pixels); | 750 DCHECK(!resource->pending_set_pixels); |
| 733 DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D)); | 751 DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D)); |
| 734 GLES2Interface* gl = ContextGL(); | 752 GLES2Interface* gl = ContextGL(); |
| 735 DCHECK(gl); | 753 DCHECK(gl); |
| 736 DCHECK(texture_uploader_.get()); | 754 DCHECK(texture_uploader_.get()); |
| 737 gl->BindTexture(GL_TEXTURE_2D, resource->gl_id); | 755 gl->BindTexture(GL_TEXTURE_2D, resource->gl_id); |
| 738 texture_uploader_->Upload(image, | 756 texture_uploader_->Upload(image, |
| 739 image_rect, | 757 image_rect, |
| 740 source_rect, | 758 source_rect, |
| 741 dest_offset, | 759 dest_offset, |
| 742 resource->format, | 760 resource->format, |
| 743 resource->size); | 761 resource->size); |
| 744 } else { | 762 } else { |
| 745 DCHECK_EQ(RESOURCE_TYPE_BITMAP, resource->type); | 763 DCHECK_EQ(Bitmap, resource->type); |
| 746 DCHECK(resource->allocated); | 764 DCHECK(resource->allocated); |
| 747 DCHECK_EQ(RGBA_8888, resource->format); | 765 DCHECK_EQ(RGBA_8888, resource->format); |
| 748 DCHECK(source_rect.x() >= image_rect.x()); | 766 DCHECK(source_rect.x() >= image_rect.x()); |
| 749 DCHECK(source_rect.y() >= image_rect.y()); | 767 DCHECK(source_rect.y() >= image_rect.y()); |
| 750 DCHECK(source_rect.right() <= image_rect.right()); | 768 DCHECK(source_rect.right() <= image_rect.right()); |
| 751 DCHECK(source_rect.bottom() <= image_rect.bottom()); | 769 DCHECK(source_rect.bottom() <= image_rect.bottom()); |
| 752 SkImageInfo source_info = | 770 SkImageInfo source_info = |
| 753 SkImageInfo::MakeN32Premul(source_rect.width(), source_rect.height()); | 771 SkImageInfo::MakeN32Premul(source_rect.width(), source_rect.height()); |
| 754 size_t image_row_bytes = image_rect.width() * 4; | 772 size_t image_row_bytes = image_rect.width() * 4; |
| 755 gfx::Vector2d source_offset = source_rect.origin() - image_rect.origin(); | 773 gfx::Vector2d source_offset = source_rect.origin() - image_rect.origin(); |
| 756 image += source_offset.y() * image_row_bytes + source_offset.x() * 4; | 774 image += source_offset.y() * image_row_bytes + source_offset.x() * 4; |
| 757 | 775 |
| 758 ScopedWriteLockSoftware lock(this, id); | 776 ScopedWriteLockSoftware lock(this, id); |
| 759 SkCanvas dest(lock.sk_bitmap()); | 777 SkCanvas dest(lock.sk_bitmap()); |
| 760 dest.writePixels(source_info, image, image_row_bytes, dest_offset.x(), | 778 dest.writePixels(source_info, image, image_row_bytes, dest_offset.x(), |
| 761 dest_offset.y()); | 779 dest_offset.y()); |
| 762 } | 780 } |
| 763 } | 781 } |
| 764 | 782 |
| 765 void ResourceProvider::CopyToResource(ResourceId id, | |
| 766 const uint8_t* image, | |
| 767 const gfx::Size& image_size) { | |
| 768 Resource* resource = GetResource(id); | |
| 769 DCHECK(!resource->locked_for_write); | |
| 770 DCHECK(!resource->lock_for_read_count); | |
| 771 DCHECK(resource->origin == Resource::INTERNAL); | |
| 772 DCHECK_EQ(resource->exported_count, 0); | |
| 773 DCHECK(ReadLockFenceHasPassed(resource)); | |
| 774 LazyAllocate(resource); | |
| 775 | |
| 776 DCHECK_EQ(image_size.width(), resource->size.width()); | |
| 777 DCHECK_EQ(image_size.height(), resource->size.height()); | |
| 778 | |
| 779 if (resource->type == RESOURCE_TYPE_BITMAP) { | |
| 780 DCHECK_EQ(RESOURCE_TYPE_BITMAP, resource->type); | |
| 781 DCHECK(resource->allocated); | |
| 782 DCHECK_EQ(RGBA_8888, resource->format); | |
| 783 SkImageInfo source_info = | |
| 784 SkImageInfo::MakeN32Premul(image_size.width(), image_size.height()); | |
| 785 size_t image_stride = image_size.width() * 4; | |
| 786 | |
| 787 ScopedWriteLockSoftware lock(this, id); | |
| 788 SkCanvas dest(lock.sk_bitmap()); | |
| 789 dest.writePixels(source_info, image, image_stride, 0, 0); | |
| 790 } else { | |
| 791 DCHECK(resource->gl_id); | |
| 792 DCHECK(!resource->pending_set_pixels); | |
| 793 DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D)); | |
| 794 GLES2Interface* gl = ContextGL(); | |
| 795 DCHECK(gl); | |
| 796 DCHECK(texture_uploader_.get()); | |
| 797 gl->BindTexture(GL_TEXTURE_2D, resource->gl_id); | |
| 798 | |
| 799 if (resource->format == ETC1) { | |
| 800 size_t num_bytes = static_cast<size_t>(image_size.width()) * | |
| 801 image_size.height() * BitsPerPixel(ETC1) / 8; | |
| 802 gl->CompressedTexImage2D(GL_TEXTURE_2D, 0, GLInternalFormat(ETC1), | |
| 803 image_size.width(), image_size.height(), 0, | |
| 804 num_bytes, image); | |
| 805 } else { | |
| 806 gl->TexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, image_size.width(), | |
| 807 image_size.height(), GLDataFormat(resource->format), | |
| 808 GLDataType(resource->format), image); | |
| 809 } | |
| 810 } | |
| 811 } | |
| 812 | |
| 813 size_t ResourceProvider::NumBlockingUploads() { | 783 size_t ResourceProvider::NumBlockingUploads() { |
| 814 if (!texture_uploader_) | 784 if (!texture_uploader_) |
| 815 return 0; | 785 return 0; |
| 816 | 786 |
| 817 return texture_uploader_->NumBlockingUploads(); | 787 return texture_uploader_->NumBlockingUploads(); |
| 818 } | 788 } |
| 819 | 789 |
| 820 void ResourceProvider::MarkPendingUploadsAsNonBlocking() { | 790 void ResourceProvider::MarkPendingUploadsAsNonBlocking() { |
| 821 if (!texture_uploader_) | 791 if (!texture_uploader_) |
| 822 return; | 792 return; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 881 DCHECK(!resource->locked_for_write || | 851 DCHECK(!resource->locked_for_write || |
| 882 resource->set_pixels_completion_forced) << | 852 resource->set_pixels_completion_forced) << |
| 883 "locked for write: " << resource->locked_for_write << | 853 "locked for write: " << resource->locked_for_write << |
| 884 " pixels completion forced: " << resource->set_pixels_completion_forced; | 854 " pixels completion forced: " << resource->set_pixels_completion_forced; |
| 885 DCHECK_EQ(resource->exported_count, 0); | 855 DCHECK_EQ(resource->exported_count, 0); |
| 886 // Uninitialized! Call SetPixels or LockForWrite first. | 856 // Uninitialized! Call SetPixels or LockForWrite first. |
| 887 DCHECK(resource->allocated); | 857 DCHECK(resource->allocated); |
| 888 | 858 |
| 889 LazyCreate(resource); | 859 LazyCreate(resource); |
| 890 | 860 |
| 891 if (resource->type == RESOURCE_TYPE_GL_TEXTURE && !resource->gl_id) { | 861 if (resource->type == GLTexture && !resource->gl_id) { |
| 892 DCHECK(resource->origin != Resource::INTERNAL); | 862 DCHECK(resource->origin != Resource::Internal); |
| 893 DCHECK(resource->mailbox.IsTexture()); | 863 DCHECK(resource->mailbox.IsTexture()); |
| 894 | 864 |
| 895 // Mailbox sync_points must be processed by a call to | 865 // Mailbox sync_points must be processed by a call to |
| 896 // WaitSyncPointIfNeeded() prior to calling LockForRead(). | 866 // WaitSyncPointIfNeeded() prior to calling LockForRead(). |
| 897 DCHECK(!resource->mailbox.sync_point()); | 867 DCHECK(!resource->mailbox.sync_point()); |
| 898 | 868 |
| 899 GLES2Interface* gl = ContextGL(); | 869 GLES2Interface* gl = ContextGL(); |
| 900 DCHECK(gl); | 870 DCHECK(gl); |
| 901 resource->gl_id = texture_id_allocator_->NextId(); | 871 resource->gl_id = texture_id_allocator_->NextId(); |
| 902 GLC(gl, gl->BindTexture(resource->target, resource->gl_id)); | 872 GLC(gl, gl->BindTexture(resource->target, resource->gl_id)); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 931 ResourceMap::iterator it = resources_.find(id); | 901 ResourceMap::iterator it = resources_.find(id); |
| 932 CHECK(it != resources_.end()); | 902 CHECK(it != resources_.end()); |
| 933 | 903 |
| 934 Resource* resource = &it->second; | 904 Resource* resource = &it->second; |
| 935 DCHECK_GT(resource->lock_for_read_count, 0); | 905 DCHECK_GT(resource->lock_for_read_count, 0); |
| 936 DCHECK_EQ(resource->exported_count, 0); | 906 DCHECK_EQ(resource->exported_count, 0); |
| 937 resource->lock_for_read_count--; | 907 resource->lock_for_read_count--; |
| 938 if (resource->marked_for_deletion && !resource->lock_for_read_count) { | 908 if (resource->marked_for_deletion && !resource->lock_for_read_count) { |
| 939 if (!resource->child_id) { | 909 if (!resource->child_id) { |
| 940 // The resource belongs to this ResourceProvider, so it can be destroyed. | 910 // The resource belongs to this ResourceProvider, so it can be destroyed. |
| 941 DeleteResourceInternal(it, NORMAL); | 911 DeleteResourceInternal(it, Normal); |
| 942 } else { | 912 } else { |
| 943 ChildMap::iterator child_it = children_.find(resource->child_id); | 913 ChildMap::iterator child_it = children_.find(resource->child_id); |
| 944 ResourceIdArray unused; | 914 ResourceIdArray unused; |
| 945 unused.push_back(id); | 915 unused.push_back(id); |
| 946 DeleteAndReturnUnusedResourcesToChild(child_it, NORMAL, unused); | 916 DeleteAndReturnUnusedResourcesToChild(child_it, Normal, unused); |
| 947 } | 917 } |
| 948 } | 918 } |
| 949 } | 919 } |
| 950 | 920 |
| 951 ResourceProvider::Resource* ResourceProvider::LockForWrite(ResourceId id) { | 921 ResourceProvider::Resource* ResourceProvider::LockForWrite(ResourceId id) { |
| 952 Resource* resource = GetResource(id); | 922 Resource* resource = GetResource(id); |
| 953 DCHECK(CanLockForWrite(id)); | 923 DCHECK(CanLockForWrite(id)); |
| 954 | 924 |
| 955 resource->locked_for_write = true; | 925 resource->locked_for_write = true; |
| 956 return resource; | 926 return resource; |
| 957 } | 927 } |
| 958 | 928 |
| 959 bool ResourceProvider::CanLockForWrite(ResourceId id) { | 929 bool ResourceProvider::CanLockForWrite(ResourceId id) { |
| 960 Resource* resource = GetResource(id); | 930 Resource* resource = GetResource(id); |
| 961 return !resource->locked_for_write && !resource->lock_for_read_count && | 931 return !resource->locked_for_write && !resource->lock_for_read_count && |
| 962 !resource->exported_count && resource->origin == Resource::INTERNAL && | 932 !resource->exported_count && resource->origin == Resource::Internal && |
| 963 !resource->lost && ReadLockFenceHasPassed(resource); | 933 !resource->lost && ReadLockFenceHasPassed(resource); |
| 964 } | 934 } |
| 965 | 935 |
| 966 void ResourceProvider::UnlockForWrite(ResourceProvider::Resource* resource) { | 936 void ResourceProvider::UnlockForWrite(ResourceProvider::Resource* resource) { |
| 967 DCHECK(resource->locked_for_write); | 937 DCHECK(resource->locked_for_write); |
| 968 DCHECK_EQ(resource->exported_count, 0); | 938 DCHECK_EQ(resource->exported_count, 0); |
| 969 DCHECK(resource->origin == Resource::INTERNAL); | 939 DCHECK(resource->origin == Resource::Internal); |
| 970 resource->locked_for_write = false; | 940 resource->locked_for_write = false; |
| 971 } | 941 } |
| 972 | 942 |
| 973 ResourceProvider::ScopedReadLockGL::ScopedReadLockGL( | 943 ResourceProvider::ScopedReadLockGL::ScopedReadLockGL( |
| 974 ResourceProvider* resource_provider, | 944 ResourceProvider* resource_provider, |
| 975 ResourceProvider::ResourceId resource_id) | 945 ResourceProvider::ResourceId resource_id) |
| 976 : resource_provider_(resource_provider), | 946 : resource_provider_(resource_provider), |
| 977 resource_id_(resource_id), | 947 resource_id_(resource_id), |
| 978 texture_id_(resource_provider->LockForRead(resource_id)->gl_id) { | 948 texture_id_(resource_provider->LockForRead(resource_id)->gl_id) { |
| 979 DCHECK(texture_id_); | 949 DCHECK(texture_id_); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1057 | 1027 |
| 1058 ResourceProvider::ScopedWriteLockGpuMemoryBuffer:: | 1028 ResourceProvider::ScopedWriteLockGpuMemoryBuffer:: |
| 1059 ScopedWriteLockGpuMemoryBuffer(ResourceProvider* resource_provider, | 1029 ScopedWriteLockGpuMemoryBuffer(ResourceProvider* resource_provider, |
| 1060 ResourceProvider::ResourceId resource_id) | 1030 ResourceProvider::ResourceId resource_id) |
| 1061 : resource_provider_(resource_provider), | 1031 : resource_provider_(resource_provider), |
| 1062 resource_(resource_provider->LockForWrite(resource_id)), | 1032 resource_(resource_provider->LockForWrite(resource_id)), |
| 1063 gpu_memory_buffer_manager_(resource_provider->gpu_memory_buffer_manager_), | 1033 gpu_memory_buffer_manager_(resource_provider->gpu_memory_buffer_manager_), |
| 1064 gpu_memory_buffer_(nullptr), | 1034 gpu_memory_buffer_(nullptr), |
| 1065 size_(resource_->size), | 1035 size_(resource_->size), |
| 1066 format_(resource_->format) { | 1036 format_(resource_->format) { |
| 1067 DCHECK_EQ(RESOURCE_TYPE_GL_TEXTURE, resource_->type); | 1037 DCHECK_EQ(GLTexture, resource_->type); |
| 1068 std::swap(gpu_memory_buffer_, resource_->gpu_memory_buffer); | 1038 std::swap(gpu_memory_buffer_, resource_->gpu_memory_buffer); |
| 1069 } | 1039 } |
| 1070 | 1040 |
| 1071 ResourceProvider::ScopedWriteLockGpuMemoryBuffer:: | 1041 ResourceProvider::ScopedWriteLockGpuMemoryBuffer:: |
| 1072 ~ScopedWriteLockGpuMemoryBuffer() { | 1042 ~ScopedWriteLockGpuMemoryBuffer() { |
| 1073 DCHECK(thread_checker_.CalledOnValidThread()); | 1043 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1074 resource_provider_->UnlockForWrite(resource_); | 1044 resource_provider_->UnlockForWrite(resource_); |
| 1075 if (!gpu_memory_buffer_) | 1045 if (!gpu_memory_buffer_) |
| 1076 return; | 1046 return; |
| 1077 | 1047 |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1210 bool use_rgba_4444_texture_format, | 1180 bool use_rgba_4444_texture_format, |
| 1211 size_t id_allocation_chunk_size) | 1181 size_t id_allocation_chunk_size) |
| 1212 : output_surface_(output_surface), | 1182 : output_surface_(output_surface), |
| 1213 shared_bitmap_manager_(shared_bitmap_manager), | 1183 shared_bitmap_manager_(shared_bitmap_manager), |
| 1214 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), | 1184 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), |
| 1215 blocking_main_thread_task_runner_(blocking_main_thread_task_runner), | 1185 blocking_main_thread_task_runner_(blocking_main_thread_task_runner), |
| 1216 lost_output_surface_(false), | 1186 lost_output_surface_(false), |
| 1217 highp_threshold_min_(highp_threshold_min), | 1187 highp_threshold_min_(highp_threshold_min), |
| 1218 next_id_(1), | 1188 next_id_(1), |
| 1219 next_child_(1), | 1189 next_child_(1), |
| 1220 default_resource_type_(RESOURCE_TYPE_INVALID), | 1190 default_resource_type_(InvalidType), |
| 1221 use_texture_storage_ext_(false), | 1191 use_texture_storage_ext_(false), |
| 1222 use_texture_format_bgra_(false), | 1192 use_texture_format_bgra_(false), |
| 1223 use_texture_usage_hint_(false), | 1193 use_texture_usage_hint_(false), |
| 1224 use_compressed_texture_etc1_(false), | 1194 use_compressed_texture_etc1_(false), |
| 1225 yuv_resource_format_(LUMINANCE_8), | 1195 yuv_resource_format_(LUMINANCE_8), |
| 1226 max_texture_size_(0), | 1196 max_texture_size_(0), |
| 1227 best_texture_format_(RGBA_8888), | 1197 best_texture_format_(RGBA_8888), |
| 1228 use_rgba_4444_texture_format_(use_rgba_4444_texture_format), | 1198 use_rgba_4444_texture_format_(use_rgba_4444_texture_format), |
| 1229 id_allocation_chunk_size_(id_allocation_chunk_size), | 1199 id_allocation_chunk_size_(id_allocation_chunk_size), |
| 1230 use_sync_query_(false) { | 1200 use_sync_query_(false) { |
| 1231 DCHECK(output_surface_->HasClient()); | 1201 DCHECK(output_surface_->HasClient()); |
| 1232 DCHECK(id_allocation_chunk_size_); | 1202 DCHECK(id_allocation_chunk_size_); |
| 1233 } | 1203 } |
| 1234 | 1204 |
| 1235 void ResourceProvider::InitializeSoftware() { | 1205 void ResourceProvider::InitializeSoftware() { |
| 1236 DCHECK(thread_checker_.CalledOnValidThread()); | 1206 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1237 DCHECK_NE(RESOURCE_TYPE_BITMAP, default_resource_type_); | 1207 DCHECK_NE(Bitmap, default_resource_type_); |
| 1238 | 1208 |
| 1239 CleanUpGLIfNeeded(); | 1209 CleanUpGLIfNeeded(); |
| 1240 | 1210 |
| 1241 default_resource_type_ = RESOURCE_TYPE_BITMAP; | 1211 default_resource_type_ = Bitmap; |
| 1242 // Pick an arbitrary limit here similar to what hardware might. | 1212 // Pick an arbitrary limit here similar to what hardware might. |
| 1243 max_texture_size_ = 16 * 1024; | 1213 max_texture_size_ = 16 * 1024; |
| 1244 best_texture_format_ = RGBA_8888; | 1214 best_texture_format_ = RGBA_8888; |
| 1245 } | 1215 } |
| 1246 | 1216 |
| 1247 void ResourceProvider::InitializeGL() { | 1217 void ResourceProvider::InitializeGL() { |
| 1248 DCHECK(thread_checker_.CalledOnValidThread()); | 1218 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1249 DCHECK(!texture_uploader_); | 1219 DCHECK(!texture_uploader_); |
| 1250 DCHECK_NE(RESOURCE_TYPE_GL_TEXTURE, default_resource_type_); | 1220 DCHECK_NE(GLTexture, default_resource_type_); |
| 1251 DCHECK(!texture_id_allocator_); | 1221 DCHECK(!texture_id_allocator_); |
| 1252 DCHECK(!buffer_id_allocator_); | 1222 DCHECK(!buffer_id_allocator_); |
| 1253 | 1223 |
| 1254 default_resource_type_ = RESOURCE_TYPE_GL_TEXTURE; | 1224 default_resource_type_ = GLTexture; |
| 1255 | 1225 |
| 1256 const ContextProvider::Capabilities& caps = | 1226 const ContextProvider::Capabilities& caps = |
| 1257 output_surface_->context_provider()->ContextCapabilities(); | 1227 output_surface_->context_provider()->ContextCapabilities(); |
| 1258 | 1228 |
| 1259 bool use_bgra = caps.gpu.texture_format_bgra8888; | 1229 bool use_bgra = caps.gpu.texture_format_bgra8888; |
| 1260 use_texture_storage_ext_ = caps.gpu.texture_storage; | 1230 use_texture_storage_ext_ = caps.gpu.texture_storage; |
| 1261 use_texture_format_bgra_ = caps.gpu.texture_format_bgra8888; | 1231 use_texture_format_bgra_ = caps.gpu.texture_format_bgra8888; |
| 1262 use_texture_usage_hint_ = caps.gpu.texture_usage; | 1232 use_texture_usage_hint_ = caps.gpu.texture_usage; |
| 1263 use_compressed_texture_etc1_ = caps.gpu.texture_format_etc1; | 1233 use_compressed_texture_etc1_ = caps.gpu.texture_format_etc1; |
| 1264 yuv_resource_format_ = caps.gpu.texture_rg ? RED_8 : LUMINANCE_8; | 1234 yuv_resource_format_ = caps.gpu.texture_rg ? RED_8 : LUMINANCE_8; |
| 1265 use_sync_query_ = caps.gpu.sync_query; | 1235 use_sync_query_ = caps.gpu.sync_query; |
| 1266 | 1236 |
| 1267 GLES2Interface* gl = ContextGL(); | 1237 GLES2Interface* gl = ContextGL(); |
| 1268 DCHECK(gl); | 1238 DCHECK(gl); |
| 1269 | 1239 |
| 1270 texture_uploader_ = TextureUploader::Create(gl); | 1240 texture_uploader_ = TextureUploader::Create(gl); |
| 1271 max_texture_size_ = 0; // Context expects cleared value. | 1241 max_texture_size_ = 0; // Context expects cleared value. |
| 1272 GLC(gl, gl->GetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size_)); | 1242 GLC(gl, gl->GetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size_)); |
| 1273 best_texture_format_ = PlatformColor::BestTextureFormat(use_bgra); | 1243 best_texture_format_ = PlatformColor::BestTextureFormat(use_bgra); |
| 1274 | 1244 |
| 1275 texture_id_allocator_.reset( | 1245 texture_id_allocator_.reset( |
| 1276 new TextureIdAllocator(gl, id_allocation_chunk_size_)); | 1246 new TextureIdAllocator(gl, id_allocation_chunk_size_)); |
| 1277 buffer_id_allocator_.reset( | 1247 buffer_id_allocator_.reset( |
| 1278 new BufferIdAllocator(gl, id_allocation_chunk_size_)); | 1248 new BufferIdAllocator(gl, id_allocation_chunk_size_)); |
| 1279 } | 1249 } |
| 1280 | 1250 |
| 1281 void ResourceProvider::CleanUpGLIfNeeded() { | 1251 void ResourceProvider::CleanUpGLIfNeeded() { |
| 1282 GLES2Interface* gl = ContextGL(); | 1252 GLES2Interface* gl = ContextGL(); |
| 1283 if (default_resource_type_ != RESOURCE_TYPE_GL_TEXTURE) { | 1253 if (default_resource_type_ != GLTexture) { |
| 1284 // We are not in GL mode, but double check before returning. | 1254 // We are not in GL mode, but double check before returning. |
| 1285 DCHECK(!gl); | 1255 DCHECK(!gl); |
| 1286 DCHECK(!texture_uploader_); | 1256 DCHECK(!texture_uploader_); |
| 1287 return; | 1257 return; |
| 1288 } | 1258 } |
| 1289 | 1259 |
| 1290 DCHECK(gl); | 1260 DCHECK(gl); |
| 1291 #if DCHECK_IS_ON() | 1261 #if DCHECK_IS_ON() |
| 1292 // Check that all GL resources has been deleted. | 1262 // Check that all GL resources has been deleted. |
| 1293 for (ResourceMap::const_iterator itr = resources_.begin(); | 1263 for (ResourceMap::const_iterator itr = resources_.begin(); |
| 1294 itr != resources_.end(); | 1264 itr != resources_.end(); |
| 1295 ++itr) { | 1265 ++itr) { |
| 1296 DCHECK_NE(RESOURCE_TYPE_GL_TEXTURE, itr->second.type); | 1266 DCHECK_NE(GLTexture, itr->second.type); |
| 1297 } | 1267 } |
| 1298 #endif // DCHECK_IS_ON() | 1268 #endif // DCHECK_IS_ON() |
| 1299 | 1269 |
| 1300 texture_uploader_ = nullptr; | 1270 texture_uploader_ = nullptr; |
| 1301 texture_id_allocator_ = nullptr; | 1271 texture_id_allocator_ = nullptr; |
| 1302 buffer_id_allocator_ = nullptr; | 1272 buffer_id_allocator_ = nullptr; |
| 1303 gl->Finish(); | 1273 gl->Finish(); |
| 1304 } | 1274 } |
| 1305 | 1275 |
| 1306 int ResourceProvider::CreateChild(const ReturnCallback& return_callback) { | 1276 int ResourceProvider::CreateChild(const ReturnCallback& return_callback) { |
| 1307 DCHECK(thread_checker_.CalledOnValidThread()); | 1277 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1308 | 1278 |
| 1309 Child child_info; | 1279 Child child_info; |
| 1310 child_info.return_callback = return_callback; | 1280 child_info.return_callback = return_callback; |
| 1311 | 1281 |
| 1312 int child = next_child_++; | 1282 int child = next_child_++; |
| 1313 children_[child] = child_info; | 1283 children_[child] = child_info; |
| 1314 return child; | 1284 return child; |
| 1315 } | 1285 } |
| 1316 | 1286 |
| 1317 void ResourceProvider::DestroyChild(int child_id) { | 1287 void ResourceProvider::DestroyChild(int child_id) { |
| 1318 ChildMap::iterator it = children_.find(child_id); | 1288 ChildMap::iterator it = children_.find(child_id); |
| 1319 DCHECK(it != children_.end()); | 1289 DCHECK(it != children_.end()); |
| 1320 DestroyChildInternal(it, NORMAL); | 1290 DestroyChildInternal(it, Normal); |
| 1321 } | 1291 } |
| 1322 | 1292 |
| 1323 void ResourceProvider::DestroyChildInternal(ChildMap::iterator it, | 1293 void ResourceProvider::DestroyChildInternal(ChildMap::iterator it, |
| 1324 DeleteStyle style) { | 1294 DeleteStyle style) { |
| 1325 DCHECK(thread_checker_.CalledOnValidThread()); | 1295 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1326 | 1296 |
| 1327 Child& child = it->second; | 1297 Child& child = it->second; |
| 1328 DCHECK(style == FOR_SHUTDOWN || !child.marked_for_deletion); | 1298 DCHECK(style == ForShutdown || !child.marked_for_deletion); |
| 1329 | 1299 |
| 1330 ResourceIdArray resources_for_child; | 1300 ResourceIdArray resources_for_child; |
| 1331 | 1301 |
| 1332 for (ResourceIdMap::iterator child_it = child.child_to_parent_map.begin(); | 1302 for (ResourceIdMap::iterator child_it = child.child_to_parent_map.begin(); |
| 1333 child_it != child.child_to_parent_map.end(); | 1303 child_it != child.child_to_parent_map.end(); |
| 1334 ++child_it) { | 1304 ++child_it) { |
| 1335 ResourceId id = child_it->second; | 1305 ResourceId id = child_it->second; |
| 1336 resources_for_child.push_back(id); | 1306 resources_for_child.push_back(id); |
| 1337 } | 1307 } |
| 1338 | 1308 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1402 ReturnedResourceArray to_return; | 1372 ReturnedResourceArray to_return; |
| 1403 to_return.push_back(it->ToReturnedResource()); | 1373 to_return.push_back(it->ToReturnedResource()); |
| 1404 child_info.return_callback.Run(to_return, | 1374 child_info.return_callback.Run(to_return, |
| 1405 blocking_main_thread_task_runner_); | 1375 blocking_main_thread_task_runner_); |
| 1406 continue; | 1376 continue; |
| 1407 } | 1377 } |
| 1408 | 1378 |
| 1409 ResourceId local_id = next_id_++; | 1379 ResourceId local_id = next_id_++; |
| 1410 Resource& resource = resources_[local_id]; | 1380 Resource& resource = resources_[local_id]; |
| 1411 if (it->is_software) { | 1381 if (it->is_software) { |
| 1412 resource = | 1382 resource = Resource(it->mailbox_holder.mailbox, |
| 1413 Resource(it->mailbox_holder.mailbox, it->size, Resource::DELEGATED, | 1383 it->size, |
| 1414 GL_LINEAR, it->is_repeated ? GL_REPEAT : GL_CLAMP_TO_EDGE); | 1384 Resource::Delegated, |
| 1385 GL_LINEAR, |
| 1386 it->is_repeated ? GL_REPEAT : GL_CLAMP_TO_EDGE); |
| 1415 } else { | 1387 } else { |
| 1416 resource = Resource(0, it->size, Resource::DELEGATED, | 1388 resource = Resource(0, |
| 1417 it->mailbox_holder.texture_target, it->filter, 0, | 1389 it->size, |
| 1390 Resource::Delegated, |
| 1391 it->mailbox_holder.texture_target, |
| 1392 it->filter, |
| 1393 0, |
| 1418 it->is_repeated ? GL_REPEAT : GL_CLAMP_TO_EDGE, | 1394 it->is_repeated ? GL_REPEAT : GL_CLAMP_TO_EDGE, |
| 1419 TEXTURE_HINT_IMMUTABLE, it->format); | 1395 TextureHintImmutable, |
| 1396 it->format); |
| 1420 resource.mailbox = TextureMailbox(it->mailbox_holder.mailbox, | 1397 resource.mailbox = TextureMailbox(it->mailbox_holder.mailbox, |
| 1421 it->mailbox_holder.texture_target, | 1398 it->mailbox_holder.texture_target, |
| 1422 it->mailbox_holder.sync_point); | 1399 it->mailbox_holder.sync_point); |
| 1423 } | 1400 } |
| 1424 resource.child_id = child; | 1401 resource.child_id = child; |
| 1425 // Don't allocate a texture for a child. | 1402 // Don't allocate a texture for a child. |
| 1426 resource.allocated = true; | 1403 resource.allocated = true; |
| 1427 resource.imported_count = 1; | 1404 resource.imported_count = 1; |
| 1428 resource.allow_overlay = it->allow_overlay; | 1405 resource.allow_overlay = it->allow_overlay; |
| 1429 child_info.parent_to_child_map[local_id] = it->id; | 1406 child_info.parent_to_child_map[local_id] = it->id; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1454 | 1431 |
| 1455 ResourceIdArray unused; | 1432 ResourceIdArray unused; |
| 1456 for (ResourceIdMap::iterator it = child_info.child_to_parent_map.begin(); | 1433 for (ResourceIdMap::iterator it = child_info.child_to_parent_map.begin(); |
| 1457 it != child_info.child_to_parent_map.end(); | 1434 it != child_info.child_to_parent_map.end(); |
| 1458 ++it) { | 1435 ++it) { |
| 1459 ResourceId local_id = it->second; | 1436 ResourceId local_id = it->second; |
| 1460 bool resource_is_in_use = child_info.in_use_resources.count(local_id) > 0; | 1437 bool resource_is_in_use = child_info.in_use_resources.count(local_id) > 0; |
| 1461 if (!resource_is_in_use) | 1438 if (!resource_is_in_use) |
| 1462 unused.push_back(local_id); | 1439 unused.push_back(local_id); |
| 1463 } | 1440 } |
| 1464 DeleteAndReturnUnusedResourcesToChild(child_it, NORMAL, unused); | 1441 DeleteAndReturnUnusedResourcesToChild(child_it, Normal, unused); |
| 1465 } | 1442 } |
| 1466 | 1443 |
| 1467 // static | 1444 // static |
| 1468 bool ResourceProvider::CompareResourceMapIteratorsByChildId( | 1445 bool ResourceProvider::CompareResourceMapIteratorsByChildId( |
| 1469 const std::pair<ReturnedResource, ResourceMap::iterator>& a, | 1446 const std::pair<ReturnedResource, ResourceMap::iterator>& a, |
| 1470 const std::pair<ReturnedResource, ResourceMap::iterator>& b) { | 1447 const std::pair<ReturnedResource, ResourceMap::iterator>& b) { |
| 1471 const ResourceMap::iterator& a_it = a.second; | 1448 const ResourceMap::iterator& a_it = a.second; |
| 1472 const ResourceMap::iterator& b_it = b.second; | 1449 const ResourceMap::iterator& b_it = b.second; |
| 1473 const Resource& a_resource = a_it->second; | 1450 const Resource& a_resource = a_it->second; |
| 1474 const Resource& b_resource = b_it->second; | 1451 const Resource& b_resource = b_it->second; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1521 // Need to wait for the current read lock fence to pass before we can | 1498 // Need to wait for the current read lock fence to pass before we can |
| 1522 // recycle this resource. | 1499 // recycle this resource. |
| 1523 if (resource->read_lock_fences_enabled) { | 1500 if (resource->read_lock_fences_enabled) { |
| 1524 if (current_read_lock_fence_.get()) | 1501 if (current_read_lock_fence_.get()) |
| 1525 current_read_lock_fence_->Set(); | 1502 current_read_lock_fence_->Set(); |
| 1526 resource->read_lock_fence = current_read_lock_fence_; | 1503 resource->read_lock_fence = current_read_lock_fence_; |
| 1527 } | 1504 } |
| 1528 | 1505 |
| 1529 if (returned.sync_point) { | 1506 if (returned.sync_point) { |
| 1530 DCHECK(!resource->has_shared_bitmap_id); | 1507 DCHECK(!resource->has_shared_bitmap_id); |
| 1531 if (resource->origin == Resource::INTERNAL) { | 1508 if (resource->origin == Resource::Internal) { |
| 1532 DCHECK(resource->gl_id); | 1509 DCHECK(resource->gl_id); |
| 1533 GLC(gl, gl->WaitSyncPointCHROMIUM(returned.sync_point)); | 1510 GLC(gl, gl->WaitSyncPointCHROMIUM(returned.sync_point)); |
| 1534 } else { | 1511 } else { |
| 1535 DCHECK(!resource->gl_id); | 1512 DCHECK(!resource->gl_id); |
| 1536 resource->mailbox.set_sync_point(returned.sync_point); | 1513 resource->mailbox.set_sync_point(returned.sync_point); |
| 1537 } | 1514 } |
| 1538 } | 1515 } |
| 1539 | 1516 |
| 1540 if (!resource->marked_for_deletion) | 1517 if (!resource->marked_for_deletion) |
| 1541 continue; | 1518 continue; |
| 1542 | 1519 |
| 1543 if (!resource->child_id) { | 1520 if (!resource->child_id) { |
| 1544 // The resource belongs to this ResourceProvider, so it can be destroyed. | 1521 // The resource belongs to this ResourceProvider, so it can be destroyed. |
| 1545 DeleteResourceInternal(map_iterator, NORMAL); | 1522 DeleteResourceInternal(map_iterator, Normal); |
| 1546 continue; | 1523 continue; |
| 1547 } | 1524 } |
| 1548 | 1525 |
| 1549 DCHECK(resource->origin == Resource::DELEGATED); | 1526 DCHECK(resource->origin == Resource::Delegated); |
| 1550 // Delete the resource and return it to the child it came from one. | 1527 // Delete the resource and return it to the child it came from one. |
| 1551 if (resource->child_id != child_id) { | 1528 if (resource->child_id != child_id) { |
| 1552 if (child_id) { | 1529 if (child_id) { |
| 1553 DCHECK_NE(resources_for_child.size(), 0u); | 1530 DCHECK_NE(resources_for_child.size(), 0u); |
| 1554 DCHECK(child_it != children_.end()); | 1531 DCHECK(child_it != children_.end()); |
| 1555 DeleteAndReturnUnusedResourcesToChild(child_it, NORMAL, | 1532 DeleteAndReturnUnusedResourcesToChild( |
| 1556 resources_for_child); | 1533 child_it, Normal, resources_for_child); |
| 1557 resources_for_child.clear(); | 1534 resources_for_child.clear(); |
| 1558 } | 1535 } |
| 1559 | 1536 |
| 1560 child_it = children_.find(resource->child_id); | 1537 child_it = children_.find(resource->child_id); |
| 1561 DCHECK(child_it != children_.end()); | 1538 DCHECK(child_it != children_.end()); |
| 1562 child_id = resource->child_id; | 1539 child_id = resource->child_id; |
| 1563 } | 1540 } |
| 1564 resources_for_child.push_back(local_id); | 1541 resources_for_child.push_back(local_id); |
| 1565 } | 1542 } |
| 1566 | 1543 |
| 1567 if (child_id) { | 1544 if (child_id) { |
| 1568 DCHECK_NE(resources_for_child.size(), 0u); | 1545 DCHECK_NE(resources_for_child.size(), 0u); |
| 1569 DCHECK(child_it != children_.end()); | 1546 DCHECK(child_it != children_.end()); |
| 1570 DeleteAndReturnUnusedResourcesToChild(child_it, NORMAL, | 1547 DeleteAndReturnUnusedResourcesToChild( |
| 1571 resources_for_child); | 1548 child_it, Normal, resources_for_child); |
| 1572 } | 1549 } |
| 1573 } | 1550 } |
| 1574 | 1551 |
| 1575 void ResourceProvider::TransferResource(GLES2Interface* gl, | 1552 void ResourceProvider::TransferResource(GLES2Interface* gl, |
| 1576 ResourceId id, | 1553 ResourceId id, |
| 1577 TransferableResource* resource) { | 1554 TransferableResource* resource) { |
| 1578 Resource* source = GetResource(id); | 1555 Resource* source = GetResource(id); |
| 1579 DCHECK(!source->locked_for_write); | 1556 DCHECK(!source->locked_for_write); |
| 1580 DCHECK(!source->lock_for_read_count); | 1557 DCHECK(!source->lock_for_read_count); |
| 1581 DCHECK(source->origin != Resource::EXTERNAL || source->mailbox.IsValid()); | 1558 DCHECK(source->origin != Resource::External || source->mailbox.IsValid()); |
| 1582 DCHECK(source->allocated); | 1559 DCHECK(source->allocated); |
| 1583 resource->id = id; | 1560 resource->id = id; |
| 1584 resource->format = source->format; | 1561 resource->format = source->format; |
| 1585 resource->mailbox_holder.texture_target = source->target; | 1562 resource->mailbox_holder.texture_target = source->target; |
| 1586 resource->filter = source->filter; | 1563 resource->filter = source->filter; |
| 1587 resource->size = source->size; | 1564 resource->size = source->size; |
| 1588 resource->is_repeated = (source->wrap_mode == GL_REPEAT); | 1565 resource->is_repeated = (source->wrap_mode == GL_REPEAT); |
| 1589 resource->allow_overlay = source->allow_overlay; | 1566 resource->allow_overlay = source->allow_overlay; |
| 1590 | 1567 |
| 1591 if (source->type == RESOURCE_TYPE_BITMAP) { | 1568 if (source->type == Bitmap) { |
| 1592 resource->mailbox_holder.mailbox = source->shared_bitmap_id; | 1569 resource->mailbox_holder.mailbox = source->shared_bitmap_id; |
| 1593 resource->is_software = true; | 1570 resource->is_software = true; |
| 1594 } else if (!source->mailbox.IsValid()) { | 1571 } else if (!source->mailbox.IsValid()) { |
| 1595 LazyCreate(source); | 1572 LazyCreate(source); |
| 1596 DCHECK(source->gl_id); | 1573 DCHECK(source->gl_id); |
| 1597 DCHECK(source->origin == Resource::INTERNAL); | 1574 DCHECK(source->origin == Resource::Internal); |
| 1598 GLC(gl, | 1575 GLC(gl, |
| 1599 gl->BindTexture(resource->mailbox_holder.texture_target, | 1576 gl->BindTexture(resource->mailbox_holder.texture_target, |
| 1600 source->gl_id)); | 1577 source->gl_id)); |
| 1601 if (source->image_id) { | 1578 if (source->image_id) { |
| 1602 DCHECK(source->dirty_image); | 1579 DCHECK(source->dirty_image); |
| 1603 BindImageForSampling(source); | 1580 BindImageForSampling(source); |
| 1604 } | 1581 } |
| 1605 // This is a resource allocated by the compositor, we need to produce it. | 1582 // This is a resource allocated by the compositor, we need to produce it. |
| 1606 // Don't set a sync point, the caller will do it. | 1583 // Don't set a sync point, the caller will do it. |
| 1607 GLC(gl, gl->GenMailboxCHROMIUM(resource->mailbox_holder.mailbox.name)); | 1584 GLC(gl, gl->GenMailboxCHROMIUM(resource->mailbox_holder.mailbox.name)); |
| 1608 GLC(gl, | 1585 GLC(gl, |
| 1609 gl->ProduceTextureCHROMIUM(resource->mailbox_holder.texture_target, | 1586 gl->ProduceTextureCHROMIUM(resource->mailbox_holder.texture_target, |
| 1610 resource->mailbox_holder.mailbox.name)); | 1587 resource->mailbox_holder.mailbox.name)); |
| 1611 source->mailbox = TextureMailbox(resource->mailbox_holder); | 1588 source->mailbox = TextureMailbox(resource->mailbox_holder); |
| 1612 } else { | 1589 } else { |
| 1613 DCHECK(source->mailbox.IsTexture()); | 1590 DCHECK(source->mailbox.IsTexture()); |
| 1614 if (source->image_id && source->dirty_image) { | 1591 if (source->image_id && source->dirty_image) { |
| 1615 DCHECK(source->gl_id); | 1592 DCHECK(source->gl_id); |
| 1616 DCHECK(source->origin == Resource::INTERNAL); | 1593 DCHECK(source->origin == Resource::Internal); |
| 1617 GLC(gl, | 1594 GLC(gl, |
| 1618 gl->BindTexture(resource->mailbox_holder.texture_target, | 1595 gl->BindTexture(resource->mailbox_holder.texture_target, |
| 1619 source->gl_id)); | 1596 source->gl_id)); |
| 1620 BindImageForSampling(source); | 1597 BindImageForSampling(source); |
| 1621 } | 1598 } |
| 1622 // This is either an external resource, or a compositor resource that we | 1599 // This is either an external resource, or a compositor resource that we |
| 1623 // already exported. Make sure to forward the sync point that we were given. | 1600 // already exported. Make sure to forward the sync point that we were given. |
| 1624 resource->mailbox_holder.mailbox = source->mailbox.mailbox(); | 1601 resource->mailbox_holder.mailbox = source->mailbox.mailbox(); |
| 1625 resource->mailbox_holder.texture_target = source->mailbox.target(); | 1602 resource->mailbox_holder.texture_target = source->mailbox.target(); |
| 1626 resource->mailbox_holder.sync_point = source->mailbox.sync_point(); | 1603 resource->mailbox_holder.sync_point = source->mailbox.sync_point(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1651 Resource& resource = it->second; | 1628 Resource& resource = it->second; |
| 1652 | 1629 |
| 1653 DCHECK(!resource.locked_for_write); | 1630 DCHECK(!resource.locked_for_write); |
| 1654 DCHECK_EQ(0u, child_info->in_use_resources.count(local_id)); | 1631 DCHECK_EQ(0u, child_info->in_use_resources.count(local_id)); |
| 1655 DCHECK(child_info->parent_to_child_map.count(local_id)); | 1632 DCHECK(child_info->parent_to_child_map.count(local_id)); |
| 1656 | 1633 |
| 1657 ResourceId child_id = child_info->parent_to_child_map[local_id]; | 1634 ResourceId child_id = child_info->parent_to_child_map[local_id]; |
| 1658 DCHECK(child_info->child_to_parent_map.count(child_id)); | 1635 DCHECK(child_info->child_to_parent_map.count(child_id)); |
| 1659 | 1636 |
| 1660 bool is_lost = | 1637 bool is_lost = |
| 1661 resource.lost || | 1638 resource.lost || (resource.type == GLTexture && lost_output_surface_); |
| 1662 (resource.type == RESOURCE_TYPE_GL_TEXTURE && lost_output_surface_); | |
| 1663 if (resource.exported_count > 0 || resource.lock_for_read_count > 0) { | 1639 if (resource.exported_count > 0 || resource.lock_for_read_count > 0) { |
| 1664 if (style != FOR_SHUTDOWN) { | 1640 if (style != ForShutdown) { |
| 1665 // Defer this until we receive the resource back from the parent or | 1641 // Defer this until we receive the resource back from the parent or |
| 1666 // the read lock is released. | 1642 // the read lock is released. |
| 1667 resource.marked_for_deletion = true; | 1643 resource.marked_for_deletion = true; |
| 1668 continue; | 1644 continue; |
| 1669 } | 1645 } |
| 1670 | 1646 |
| 1671 // We still have an exported_count, so we'll have to lose it. | 1647 // We still have an exported_count, so we'll have to lose it. |
| 1672 is_lost = true; | 1648 is_lost = true; |
| 1673 } | 1649 } |
| 1674 | 1650 |
| 1675 if (gl && resource.filter != resource.original_filter) { | 1651 if (gl && resource.filter != resource.original_filter) { |
| 1676 DCHECK(resource.target); | 1652 DCHECK(resource.target); |
| 1677 DCHECK(resource.gl_id); | 1653 DCHECK(resource.gl_id); |
| 1678 | 1654 |
| 1679 GLC(gl, gl->BindTexture(resource.target, resource.gl_id)); | 1655 GLC(gl, gl->BindTexture(resource.target, resource.gl_id)); |
| 1680 GLC(gl, | 1656 GLC(gl, |
| 1681 gl->TexParameteri(resource.target, | 1657 gl->TexParameteri(resource.target, |
| 1682 GL_TEXTURE_MIN_FILTER, | 1658 GL_TEXTURE_MIN_FILTER, |
| 1683 resource.original_filter)); | 1659 resource.original_filter)); |
| 1684 GLC(gl, | 1660 GLC(gl, |
| 1685 gl->TexParameteri(resource.target, | 1661 gl->TexParameteri(resource.target, |
| 1686 GL_TEXTURE_MAG_FILTER, | 1662 GL_TEXTURE_MAG_FILTER, |
| 1687 resource.original_filter)); | 1663 resource.original_filter)); |
| 1688 } | 1664 } |
| 1689 | 1665 |
| 1690 ReturnedResource returned; | 1666 ReturnedResource returned; |
| 1691 returned.id = child_id; | 1667 returned.id = child_id; |
| 1692 returned.sync_point = resource.mailbox.sync_point(); | 1668 returned.sync_point = resource.mailbox.sync_point(); |
| 1693 if (!returned.sync_point && resource.type == RESOURCE_TYPE_GL_TEXTURE) | 1669 if (!returned.sync_point && resource.type == GLTexture) |
| 1694 need_sync_point = true; | 1670 need_sync_point = true; |
| 1695 returned.count = resource.imported_count; | 1671 returned.count = resource.imported_count; |
| 1696 returned.lost = is_lost; | 1672 returned.lost = is_lost; |
| 1697 to_return.push_back(returned); | 1673 to_return.push_back(returned); |
| 1698 | 1674 |
| 1699 child_info->parent_to_child_map.erase(local_id); | 1675 child_info->parent_to_child_map.erase(local_id); |
| 1700 child_info->child_to_parent_map.erase(child_id); | 1676 child_info->child_to_parent_map.erase(child_id); |
| 1701 resource.imported_count = 0; | 1677 resource.imported_count = 0; |
| 1702 DeleteResourceInternal(it, style); | 1678 DeleteResourceInternal(it, style); |
| 1703 } | 1679 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1719 DCHECK(child_info->child_to_parent_map.empty()); | 1695 DCHECK(child_info->child_to_parent_map.empty()); |
| 1720 children_.erase(child_it); | 1696 children_.erase(child_it); |
| 1721 } | 1697 } |
| 1722 } | 1698 } |
| 1723 | 1699 |
| 1724 void ResourceProvider::AcquirePixelBuffer(ResourceId id) { | 1700 void ResourceProvider::AcquirePixelBuffer(ResourceId id) { |
| 1725 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 1701 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
| 1726 "ResourceProvider::AcquirePixelBuffer"); | 1702 "ResourceProvider::AcquirePixelBuffer"); |
| 1727 | 1703 |
| 1728 Resource* resource = GetResource(id); | 1704 Resource* resource = GetResource(id); |
| 1729 DCHECK(resource->origin == Resource::INTERNAL); | 1705 DCHECK(resource->origin == Resource::Internal); |
| 1730 DCHECK_EQ(resource->exported_count, 0); | 1706 DCHECK_EQ(resource->exported_count, 0); |
| 1731 DCHECK(!resource->image_id); | 1707 DCHECK(!resource->image_id); |
| 1732 DCHECK_NE(ETC1, resource->format); | 1708 DCHECK_NE(ETC1, resource->format); |
| 1733 | 1709 |
| 1734 DCHECK_EQ(RESOURCE_TYPE_GL_TEXTURE, resource->type); | 1710 DCHECK_EQ(GLTexture, resource->type); |
| 1735 GLES2Interface* gl = ContextGL(); | 1711 GLES2Interface* gl = ContextGL(); |
| 1736 DCHECK(gl); | 1712 DCHECK(gl); |
| 1737 if (!resource->gl_pixel_buffer_id) | 1713 if (!resource->gl_pixel_buffer_id) |
| 1738 resource->gl_pixel_buffer_id = buffer_id_allocator_->NextId(); | 1714 resource->gl_pixel_buffer_id = buffer_id_allocator_->NextId(); |
| 1739 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1715 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| 1740 resource->gl_pixel_buffer_id); | 1716 resource->gl_pixel_buffer_id); |
| 1741 unsigned bytes_per_pixel = BitsPerPixel(resource->format) / 8; | 1717 unsigned bytes_per_pixel = BitsPerPixel(resource->format) / 8; |
| 1742 gl->BufferData(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1718 gl->BufferData(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| 1743 resource->size.height() * | 1719 resource->size.height() * |
| 1744 RoundUp(bytes_per_pixel * resource->size.width(), 4u), | 1720 RoundUp(bytes_per_pixel * resource->size.width(), 4u), |
| 1745 NULL, | 1721 NULL, |
| 1746 GL_DYNAMIC_DRAW); | 1722 GL_DYNAMIC_DRAW); |
| 1747 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | 1723 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
| 1748 } | 1724 } |
| 1749 | 1725 |
| 1750 void ResourceProvider::ReleasePixelBuffer(ResourceId id) { | 1726 void ResourceProvider::ReleasePixelBuffer(ResourceId id) { |
| 1751 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 1727 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
| 1752 "ResourceProvider::ReleasePixelBuffer"); | 1728 "ResourceProvider::ReleasePixelBuffer"); |
| 1753 | 1729 |
| 1754 Resource* resource = GetResource(id); | 1730 Resource* resource = GetResource(id); |
| 1755 DCHECK(resource->origin == Resource::INTERNAL); | 1731 DCHECK(resource->origin == Resource::Internal); |
| 1756 DCHECK_EQ(resource->exported_count, 0); | 1732 DCHECK_EQ(resource->exported_count, 0); |
| 1757 DCHECK(!resource->image_id); | 1733 DCHECK(!resource->image_id); |
| 1758 | 1734 |
| 1759 // The pixel buffer can be released while there is a pending "set pixels" | 1735 // The pixel buffer can be released while there is a pending "set pixels" |
| 1760 // if completion has been forced. Any shared memory associated with this | 1736 // if completion has been forced. Any shared memory associated with this |
| 1761 // pixel buffer will not be freed until the waitAsyncTexImage2DCHROMIUM | 1737 // pixel buffer will not be freed until the waitAsyncTexImage2DCHROMIUM |
| 1762 // command has been processed on the service side. It is also safe to | 1738 // command has been processed on the service side. It is also safe to |
| 1763 // reuse any query id associated with this resource before they complete | 1739 // reuse any query id associated with this resource before they complete |
| 1764 // as each new query has a unique submit count. | 1740 // as each new query has a unique submit count. |
| 1765 if (resource->pending_set_pixels) { | 1741 if (resource->pending_set_pixels) { |
| 1766 DCHECK(resource->set_pixels_completion_forced); | 1742 DCHECK(resource->set_pixels_completion_forced); |
| 1767 resource->pending_set_pixels = false; | 1743 resource->pending_set_pixels = false; |
| 1768 resource->locked_for_write = false; | 1744 resource->locked_for_write = false; |
| 1769 } | 1745 } |
| 1770 | 1746 |
| 1771 DCHECK_EQ(RESOURCE_TYPE_GL_TEXTURE, resource->type); | 1747 DCHECK_EQ(GLTexture, resource->type); |
| 1772 if (!resource->gl_pixel_buffer_id) | 1748 if (!resource->gl_pixel_buffer_id) |
| 1773 return; | 1749 return; |
| 1774 GLES2Interface* gl = ContextGL(); | 1750 GLES2Interface* gl = ContextGL(); |
| 1775 DCHECK(gl); | 1751 DCHECK(gl); |
| 1776 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1752 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| 1777 resource->gl_pixel_buffer_id); | 1753 resource->gl_pixel_buffer_id); |
| 1778 gl->BufferData( | 1754 gl->BufferData( |
| 1779 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0, NULL, GL_DYNAMIC_DRAW); | 1755 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0, NULL, GL_DYNAMIC_DRAW); |
| 1780 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | 1756 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
| 1781 } | 1757 } |
| 1782 | 1758 |
| 1783 uint8_t* ResourceProvider::MapPixelBuffer(ResourceId id, int* stride) { | 1759 uint8_t* ResourceProvider::MapPixelBuffer(ResourceId id, int* stride) { |
| 1784 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 1760 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
| 1785 "ResourceProvider::MapPixelBuffer"); | 1761 "ResourceProvider::MapPixelBuffer"); |
| 1786 | 1762 |
| 1787 Resource* resource = GetResource(id); | 1763 Resource* resource = GetResource(id); |
| 1788 DCHECK(resource->origin == Resource::INTERNAL); | 1764 DCHECK(resource->origin == Resource::Internal); |
| 1789 DCHECK_EQ(resource->exported_count, 0); | 1765 DCHECK_EQ(resource->exported_count, 0); |
| 1790 DCHECK(!resource->image_id); | 1766 DCHECK(!resource->image_id); |
| 1791 | 1767 |
| 1792 *stride = 0; | 1768 *stride = 0; |
| 1793 DCHECK_EQ(RESOURCE_TYPE_GL_TEXTURE, resource->type); | 1769 DCHECK_EQ(GLTexture, resource->type); |
| 1794 GLES2Interface* gl = ContextGL(); | 1770 GLES2Interface* gl = ContextGL(); |
| 1795 DCHECK(gl); | 1771 DCHECK(gl); |
| 1796 DCHECK(resource->gl_pixel_buffer_id); | 1772 DCHECK(resource->gl_pixel_buffer_id); |
| 1797 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1773 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| 1798 resource->gl_pixel_buffer_id); | 1774 resource->gl_pixel_buffer_id); |
| 1799 uint8_t* image = static_cast<uint8_t*>(gl->MapBufferCHROMIUM( | 1775 uint8_t* image = static_cast<uint8_t*>(gl->MapBufferCHROMIUM( |
| 1800 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, GL_WRITE_ONLY)); | 1776 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, GL_WRITE_ONLY)); |
| 1801 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | 1777 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
| 1802 // Buffer is required to be 4-byte aligned. | 1778 // Buffer is required to be 4-byte aligned. |
| 1803 CHECK(!(reinterpret_cast<intptr_t>(image) & 3)); | 1779 CHECK(!(reinterpret_cast<intptr_t>(image) & 3)); |
| 1804 return image; | 1780 return image; |
| 1805 } | 1781 } |
| 1806 | 1782 |
| 1807 void ResourceProvider::UnmapPixelBuffer(ResourceId id) { | 1783 void ResourceProvider::UnmapPixelBuffer(ResourceId id) { |
| 1808 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 1784 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
| 1809 "ResourceProvider::UnmapPixelBuffer"); | 1785 "ResourceProvider::UnmapPixelBuffer"); |
| 1810 | 1786 |
| 1811 Resource* resource = GetResource(id); | 1787 Resource* resource = GetResource(id); |
| 1812 DCHECK(resource->origin == Resource::INTERNAL); | 1788 DCHECK(resource->origin == Resource::Internal); |
| 1813 DCHECK_EQ(resource->exported_count, 0); | 1789 DCHECK_EQ(resource->exported_count, 0); |
| 1814 DCHECK(!resource->image_id); | 1790 DCHECK(!resource->image_id); |
| 1815 | 1791 |
| 1816 DCHECK_EQ(RESOURCE_TYPE_GL_TEXTURE, resource->type); | 1792 DCHECK_EQ(GLTexture, resource->type); |
| 1817 GLES2Interface* gl = ContextGL(); | 1793 GLES2Interface* gl = ContextGL(); |
| 1818 DCHECK(gl); | 1794 DCHECK(gl); |
| 1819 DCHECK(resource->gl_pixel_buffer_id); | 1795 DCHECK(resource->gl_pixel_buffer_id); |
| 1820 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1796 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| 1821 resource->gl_pixel_buffer_id); | 1797 resource->gl_pixel_buffer_id); |
| 1822 gl->UnmapBufferCHROMIUM(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM); | 1798 gl->UnmapBufferCHROMIUM(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM); |
| 1823 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | 1799 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
| 1824 } | 1800 } |
| 1825 | 1801 |
| 1826 GLenum ResourceProvider::BindForSampling(ResourceId resource_id, | 1802 GLenum ResourceProvider::BindForSampling(ResourceId resource_id, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1850 } | 1826 } |
| 1851 | 1827 |
| 1852 void ResourceProvider::BeginSetPixels(ResourceId id) { | 1828 void ResourceProvider::BeginSetPixels(ResourceId id) { |
| 1853 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 1829 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
| 1854 "ResourceProvider::BeginSetPixels"); | 1830 "ResourceProvider::BeginSetPixels"); |
| 1855 | 1831 |
| 1856 Resource* resource = GetResource(id); | 1832 Resource* resource = GetResource(id); |
| 1857 DCHECK(!resource->pending_set_pixels); | 1833 DCHECK(!resource->pending_set_pixels); |
| 1858 | 1834 |
| 1859 LazyCreate(resource); | 1835 LazyCreate(resource); |
| 1860 DCHECK(resource->origin == Resource::INTERNAL); | 1836 DCHECK(resource->origin == Resource::Internal); |
| 1861 DCHECK(resource->gl_id || resource->allocated); | 1837 DCHECK(resource->gl_id || resource->allocated); |
| 1862 DCHECK(ReadLockFenceHasPassed(resource)); | 1838 DCHECK(ReadLockFenceHasPassed(resource)); |
| 1863 DCHECK(!resource->image_id); | 1839 DCHECK(!resource->image_id); |
| 1864 | 1840 |
| 1865 bool allocate = !resource->allocated; | 1841 bool allocate = !resource->allocated; |
| 1866 resource->allocated = true; | 1842 resource->allocated = true; |
| 1867 LockForWrite(id); | 1843 LockForWrite(id); |
| 1868 | 1844 |
| 1869 DCHECK_EQ(RESOURCE_TYPE_GL_TEXTURE, resource->type); | 1845 DCHECK_EQ(GLTexture, resource->type); |
| 1870 DCHECK(resource->gl_id); | 1846 DCHECK(resource->gl_id); |
| 1871 GLES2Interface* gl = ContextGL(); | 1847 GLES2Interface* gl = ContextGL(); |
| 1872 DCHECK(gl); | 1848 DCHECK(gl); |
| 1873 DCHECK(resource->gl_pixel_buffer_id); | 1849 DCHECK(resource->gl_pixel_buffer_id); |
| 1874 DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D)); | 1850 DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D)); |
| 1875 gl->BindTexture(GL_TEXTURE_2D, resource->gl_id); | 1851 gl->BindTexture(GL_TEXTURE_2D, resource->gl_id); |
| 1876 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1852 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| 1877 resource->gl_pixel_buffer_id); | 1853 resource->gl_pixel_buffer_id); |
| 1878 if (!resource->gl_upload_query_id) | 1854 if (!resource->gl_upload_query_id) |
| 1879 gl->GenQueriesEXT(1, &resource->gl_upload_query_id); | 1855 gl->GenQueriesEXT(1, &resource->gl_upload_query_id); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1961 void ResourceProvider::CreateForTesting(ResourceId id) { | 1937 void ResourceProvider::CreateForTesting(ResourceId id) { |
| 1962 LazyCreate(GetResource(id)); | 1938 LazyCreate(GetResource(id)); |
| 1963 } | 1939 } |
| 1964 | 1940 |
| 1965 GLenum ResourceProvider::TargetForTesting(ResourceId id) { | 1941 GLenum ResourceProvider::TargetForTesting(ResourceId id) { |
| 1966 Resource* resource = GetResource(id); | 1942 Resource* resource = GetResource(id); |
| 1967 return resource->target; | 1943 return resource->target; |
| 1968 } | 1944 } |
| 1969 | 1945 |
| 1970 void ResourceProvider::LazyCreate(Resource* resource) { | 1946 void ResourceProvider::LazyCreate(Resource* resource) { |
| 1971 if (resource->type != RESOURCE_TYPE_GL_TEXTURE || | 1947 if (resource->type != GLTexture || resource->origin != Resource::Internal) |
| 1972 resource->origin != Resource::INTERNAL) | |
| 1973 return; | 1948 return; |
| 1974 | 1949 |
| 1975 if (resource->gl_id) | 1950 if (resource->gl_id) |
| 1976 return; | 1951 return; |
| 1977 | 1952 |
| 1978 DCHECK(resource->texture_pool); | 1953 DCHECK(resource->texture_pool); |
| 1979 DCHECK(resource->origin == Resource::INTERNAL); | 1954 DCHECK(resource->origin == Resource::Internal); |
| 1980 DCHECK(!resource->mailbox.IsValid()); | 1955 DCHECK(!resource->mailbox.IsValid()); |
| 1981 resource->gl_id = texture_id_allocator_->NextId(); | 1956 resource->gl_id = texture_id_allocator_->NextId(); |
| 1982 | 1957 |
| 1983 GLES2Interface* gl = ContextGL(); | 1958 GLES2Interface* gl = ContextGL(); |
| 1984 DCHECK(gl); | 1959 DCHECK(gl); |
| 1985 | 1960 |
| 1986 // Create and set texture properties. Allocation is delayed until needed. | 1961 // Create and set texture properties. Allocation is delayed until needed. |
| 1987 GLC(gl, gl->BindTexture(resource->target, resource->gl_id)); | 1962 GLC(gl, gl->BindTexture(resource->target, resource->gl_id)); |
| 1988 GLC(gl, | 1963 GLC(gl, |
| 1989 gl->TexParameteri( | 1964 gl->TexParameteri( |
| 1990 resource->target, GL_TEXTURE_MIN_FILTER, resource->original_filter)); | 1965 resource->target, GL_TEXTURE_MIN_FILTER, resource->original_filter)); |
| 1991 GLC(gl, | 1966 GLC(gl, |
| 1992 gl->TexParameteri( | 1967 gl->TexParameteri( |
| 1993 resource->target, GL_TEXTURE_MAG_FILTER, resource->original_filter)); | 1968 resource->target, GL_TEXTURE_MAG_FILTER, resource->original_filter)); |
| 1994 GLC(gl, | 1969 GLC(gl, |
| 1995 gl->TexParameteri( | 1970 gl->TexParameteri( |
| 1996 resource->target, GL_TEXTURE_WRAP_S, resource->wrap_mode)); | 1971 resource->target, GL_TEXTURE_WRAP_S, resource->wrap_mode)); |
| 1997 GLC(gl, | 1972 GLC(gl, |
| 1998 gl->TexParameteri( | 1973 gl->TexParameteri( |
| 1999 resource->target, GL_TEXTURE_WRAP_T, resource->wrap_mode)); | 1974 resource->target, GL_TEXTURE_WRAP_T, resource->wrap_mode)); |
| 2000 GLC(gl, | 1975 GLC(gl, |
| 2001 gl->TexParameteri( | 1976 gl->TexParameteri( |
| 2002 resource->target, GL_TEXTURE_POOL_CHROMIUM, resource->texture_pool)); | 1977 resource->target, GL_TEXTURE_POOL_CHROMIUM, resource->texture_pool)); |
| 2003 if (use_texture_usage_hint_ && (resource->hint & TEXTURE_HINT_FRAMEBUFFER)) { | 1978 if (use_texture_usage_hint_ && (resource->hint & TextureHintFramebuffer)) { |
| 2004 GLC(gl, | 1979 GLC(gl, |
| 2005 gl->TexParameteri(resource->target, | 1980 gl->TexParameteri(resource->target, |
| 2006 GL_TEXTURE_USAGE_ANGLE, | 1981 GL_TEXTURE_USAGE_ANGLE, |
| 2007 GL_FRAMEBUFFER_ATTACHMENT_ANGLE)); | 1982 GL_FRAMEBUFFER_ATTACHMENT_ANGLE)); |
| 2008 } | 1983 } |
| 2009 } | 1984 } |
| 2010 | 1985 |
| 2011 void ResourceProvider::AllocateForTesting(ResourceId id) { | 1986 void ResourceProvider::AllocateForTesting(ResourceId id) { |
| 2012 LazyAllocate(GetResource(id)); | 1987 LazyAllocate(GetResource(id)); |
| 2013 } | 1988 } |
| 2014 | 1989 |
| 2015 void ResourceProvider::LazyAllocate(Resource* resource) { | 1990 void ResourceProvider::LazyAllocate(Resource* resource) { |
| 2016 DCHECK(resource); | 1991 DCHECK(resource); |
| 2017 if (resource->allocated) | 1992 if (resource->allocated) |
| 2018 return; | 1993 return; |
| 2019 LazyCreate(resource); | 1994 LazyCreate(resource); |
| 2020 if (!resource->gl_id) | 1995 if (!resource->gl_id) |
| 2021 return; | 1996 return; |
| 2022 resource->allocated = true; | 1997 resource->allocated = true; |
| 2023 GLES2Interface* gl = ContextGL(); | 1998 GLES2Interface* gl = ContextGL(); |
| 2024 gfx::Size& size = resource->size; | 1999 gfx::Size& size = resource->size; |
| 2025 DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D)); | 2000 DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D)); |
| 2026 ResourceFormat format = resource->format; | 2001 ResourceFormat format = resource->format; |
| 2027 GLC(gl, gl->BindTexture(GL_TEXTURE_2D, resource->gl_id)); | 2002 GLC(gl, gl->BindTexture(GL_TEXTURE_2D, resource->gl_id)); |
| 2028 if (use_texture_storage_ext_ && | 2003 if (use_texture_storage_ext_ && |
| 2029 IsFormatSupportedForStorage(format, use_texture_format_bgra_) && | 2004 IsFormatSupportedForStorage(format, use_texture_format_bgra_) && |
| 2030 (resource->hint & TEXTURE_HINT_IMMUTABLE)) { | 2005 (resource->hint & TextureHintImmutable)) { |
| 2031 GLenum storage_format = TextureToStorageFormat(format); | 2006 GLenum storage_format = TextureToStorageFormat(format); |
| 2032 GLC(gl, | 2007 GLC(gl, |
| 2033 gl->TexStorage2DEXT( | 2008 gl->TexStorage2DEXT( |
| 2034 GL_TEXTURE_2D, 1, storage_format, size.width(), size.height())); | 2009 GL_TEXTURE_2D, 1, storage_format, size.width(), size.height())); |
| 2035 } else { | 2010 } else { |
| 2036 // ETC1 does not support preallocation. | 2011 // ETC1 does not support preallocation. |
| 2037 if (format != ETC1) { | 2012 if (format != ETC1) { |
| 2038 GLC(gl, | 2013 GLC(gl, |
| 2039 gl->TexImage2D(GL_TEXTURE_2D, | 2014 gl->TexImage2D(GL_TEXTURE_2D, |
| 2040 0, | 2015 0, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 2060 gl->BindTexImage2DCHROMIUM(resource->target, resource->image_id); | 2035 gl->BindTexImage2DCHROMIUM(resource->target, resource->image_id); |
| 2061 resource->bound_image_id = resource->image_id; | 2036 resource->bound_image_id = resource->image_id; |
| 2062 resource->dirty_image = false; | 2037 resource->dirty_image = false; |
| 2063 } | 2038 } |
| 2064 | 2039 |
| 2065 void ResourceProvider::CopyResource(ResourceId source_id, ResourceId dest_id) { | 2040 void ResourceProvider::CopyResource(ResourceId source_id, ResourceId dest_id) { |
| 2066 TRACE_EVENT0("cc", "ResourceProvider::CopyResource"); | 2041 TRACE_EVENT0("cc", "ResourceProvider::CopyResource"); |
| 2067 | 2042 |
| 2068 Resource* source_resource = GetResource(source_id); | 2043 Resource* source_resource = GetResource(source_id); |
| 2069 DCHECK(!source_resource->lock_for_read_count); | 2044 DCHECK(!source_resource->lock_for_read_count); |
| 2070 DCHECK(source_resource->origin == Resource::INTERNAL); | 2045 DCHECK(source_resource->origin == Resource::Internal); |
| 2071 DCHECK_EQ(source_resource->exported_count, 0); | 2046 DCHECK_EQ(source_resource->exported_count, 0); |
| 2072 DCHECK_EQ(RESOURCE_TYPE_GL_TEXTURE, source_resource->type); | 2047 DCHECK_EQ(GLTexture, source_resource->type); |
| 2073 DCHECK(source_resource->allocated); | 2048 DCHECK(source_resource->allocated); |
| 2074 LazyCreate(source_resource); | 2049 LazyCreate(source_resource); |
| 2075 | 2050 |
| 2076 Resource* dest_resource = GetResource(dest_id); | 2051 Resource* dest_resource = GetResource(dest_id); |
| 2077 DCHECK(!dest_resource->locked_for_write); | 2052 DCHECK(!dest_resource->locked_for_write); |
| 2078 DCHECK(!dest_resource->lock_for_read_count); | 2053 DCHECK(!dest_resource->lock_for_read_count); |
| 2079 DCHECK(dest_resource->origin == Resource::INTERNAL); | 2054 DCHECK(dest_resource->origin == Resource::Internal); |
| 2080 DCHECK_EQ(dest_resource->exported_count, 0); | 2055 DCHECK_EQ(dest_resource->exported_count, 0); |
| 2081 DCHECK_EQ(RESOURCE_TYPE_GL_TEXTURE, dest_resource->type); | 2056 DCHECK_EQ(GLTexture, dest_resource->type); |
| 2082 LazyAllocate(dest_resource); | 2057 LazyAllocate(dest_resource); |
| 2083 | 2058 |
| 2084 DCHECK_EQ(source_resource->type, dest_resource->type); | 2059 DCHECK_EQ(source_resource->type, dest_resource->type); |
| 2085 DCHECK_EQ(source_resource->format, dest_resource->format); | 2060 DCHECK_EQ(source_resource->format, dest_resource->format); |
| 2086 DCHECK(source_resource->size == dest_resource->size); | 2061 DCHECK(source_resource->size == dest_resource->size); |
| 2087 | 2062 |
| 2088 GLES2Interface* gl = ContextGL(); | 2063 GLES2Interface* gl = ContextGL(); |
| 2089 DCHECK(gl); | 2064 DCHECK(gl); |
| 2090 if (source_resource->image_id && source_resource->dirty_image) { | 2065 if (source_resource->image_id && source_resource->dirty_image) { |
| 2091 gl->BindTexture(source_resource->target, source_resource->gl_id); | 2066 gl->BindTexture(source_resource->target, source_resource->gl_id); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2132 synchronous_fence_ = make_scoped_refptr(new SynchronousFence(gl)); | 2107 synchronous_fence_ = make_scoped_refptr(new SynchronousFence(gl)); |
| 2133 source_resource->read_lock_fence = synchronous_fence_; | 2108 source_resource->read_lock_fence = synchronous_fence_; |
| 2134 source_resource->read_lock_fence->Set(); | 2109 source_resource->read_lock_fence->Set(); |
| 2135 } | 2110 } |
| 2136 } | 2111 } |
| 2137 | 2112 |
| 2138 void ResourceProvider::WaitSyncPointIfNeeded(ResourceId id) { | 2113 void ResourceProvider::WaitSyncPointIfNeeded(ResourceId id) { |
| 2139 Resource* resource = GetResource(id); | 2114 Resource* resource = GetResource(id); |
| 2140 DCHECK_EQ(resource->exported_count, 0); | 2115 DCHECK_EQ(resource->exported_count, 0); |
| 2141 DCHECK(resource->allocated); | 2116 DCHECK(resource->allocated); |
| 2142 if (resource->type != RESOURCE_TYPE_GL_TEXTURE || resource->gl_id) | 2117 if (resource->type != GLTexture || resource->gl_id) |
| 2143 return; | 2118 return; |
| 2144 if (!resource->mailbox.sync_point()) | 2119 if (!resource->mailbox.sync_point()) |
| 2145 return; | 2120 return; |
| 2146 DCHECK(resource->mailbox.IsValid()); | 2121 DCHECK(resource->mailbox.IsValid()); |
| 2147 GLES2Interface* gl = ContextGL(); | 2122 GLES2Interface* gl = ContextGL(); |
| 2148 DCHECK(gl); | 2123 DCHECK(gl); |
| 2149 GLC(gl, gl->WaitSyncPointCHROMIUM(resource->mailbox.sync_point())); | 2124 GLC(gl, gl->WaitSyncPointCHROMIUM(resource->mailbox.sync_point())); |
| 2150 resource->mailbox.set_sync_point(0); | 2125 resource->mailbox.set_sync_point(0); |
| 2151 } | 2126 } |
| 2152 | 2127 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2171 } | 2146 } |
| 2172 | 2147 |
| 2173 class GrContext* ResourceProvider::GrContext(bool worker_context) const { | 2148 class GrContext* ResourceProvider::GrContext(bool worker_context) const { |
| 2174 ContextProvider* context_provider = | 2149 ContextProvider* context_provider = |
| 2175 worker_context ? output_surface_->worker_context_provider() | 2150 worker_context ? output_surface_->worker_context_provider() |
| 2176 : output_surface_->context_provider(); | 2151 : output_surface_->context_provider(); |
| 2177 return context_provider ? context_provider->GrContext() : NULL; | 2152 return context_provider ? context_provider->GrContext() : NULL; |
| 2178 } | 2153 } |
| 2179 | 2154 |
| 2180 } // namespace cc | 2155 } // namespace cc |
| OLD | NEW |