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