Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(455)

Side by Side Diff: cc/resources/resource_provider.cc

Issue 1065463002: cc: Remove GLC macro (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/output/static_geometry_binding.cc ('k') | cc/resources/video_resource_updater.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "base/strings/string_split.h" 13 #include "base/strings/string_split.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "base/trace_event/trace_event.h" 15 #include "base/trace_event/trace_event.h"
16 #include "cc/base/util.h" 16 #include "cc/base/util.h"
17 #include "cc/output/gl_renderer.h" // For the GLC() macro.
18 #include "cc/resources/platform_color.h" 17 #include "cc/resources/platform_color.h"
19 #include "cc/resources/returned_resource.h" 18 #include "cc/resources/returned_resource.h"
20 #include "cc/resources/shared_bitmap_manager.h" 19 #include "cc/resources/shared_bitmap_manager.h"
21 #include "cc/resources/texture_uploader.h" 20 #include "cc/resources/texture_uploader.h"
22 #include "cc/resources/transferable_resource.h" 21 #include "cc/resources/transferable_resource.h"
23 #include "gpu/GLES2/gl2extchromium.h" 22 #include "gpu/GLES2/gl2extchromium.h"
24 #include "gpu/command_buffer/client/gles2_interface.h" 23 #include "gpu/command_buffer/client/gles2_interface.h"
25 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" 24 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h"
26 #include "third_party/khronos/GLES2/gl2.h" 25 #include "third_party/khronos/GLES2/gl2.h"
27 #include "third_party/khronos/GLES2/gl2ext.h" 26 #include "third_party/khronos/GLES2/gl2ext.h"
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 return gfx::GpuMemoryBuffer::Format::RGBA_8888; 133 return gfx::GpuMemoryBuffer::Format::RGBA_8888;
135 } 134 }
136 135
137 class ScopedSetActiveTexture { 136 class ScopedSetActiveTexture {
138 public: 137 public:
139 ScopedSetActiveTexture(GLES2Interface* gl, GLenum unit) 138 ScopedSetActiveTexture(GLES2Interface* gl, GLenum unit)
140 : gl_(gl), unit_(unit) { 139 : gl_(gl), unit_(unit) {
141 DCHECK_EQ(GL_TEXTURE0, ResourceProvider::GetActiveTextureUnit(gl_)); 140 DCHECK_EQ(GL_TEXTURE0, ResourceProvider::GetActiveTextureUnit(gl_));
142 141
143 if (unit_ != GL_TEXTURE0) 142 if (unit_ != GL_TEXTURE0)
144 GLC(gl_, gl_->ActiveTexture(unit_)); 143 gl_->ActiveTexture(unit_);
145 } 144 }
146 145
147 ~ScopedSetActiveTexture() { 146 ~ScopedSetActiveTexture() {
148 // Active unit being GL_TEXTURE0 is effectively the ground state. 147 // Active unit being GL_TEXTURE0 is effectively the ground state.
149 if (unit_ != GL_TEXTURE0) 148 if (unit_ != GL_TEXTURE0)
150 GLC(gl_, gl_->ActiveTexture(GL_TEXTURE0)); 149 gl_->ActiveTexture(GL_TEXTURE0);
151 } 150 }
152 151
153 private: 152 private:
154 GLES2Interface* gl_; 153 GLES2Interface* gl_;
155 GLenum unit_; 154 GLenum unit_;
156 }; 155 };
157 156
158 class TextureIdAllocator : public IdAllocator { 157 class TextureIdAllocator : public IdAllocator {
159 public: 158 public:
160 TextureIdAllocator(GLES2Interface* gl, 159 TextureIdAllocator(GLES2Interface* gl,
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 bool lost_resource = resource->lost; 634 bool lost_resource = resource->lost;
636 635
637 DCHECK(resource->exported_count == 0 || style != NORMAL); 636 DCHECK(resource->exported_count == 0 || style != NORMAL);
638 if (style == FOR_SHUTDOWN && resource->exported_count > 0) 637 if (style == FOR_SHUTDOWN && resource->exported_count > 0)
639 lost_resource = true; 638 lost_resource = true;
640 639
641 if (resource->image_id) { 640 if (resource->image_id) {
642 DCHECK(resource->origin == Resource::INTERNAL); 641 DCHECK(resource->origin == Resource::INTERNAL);
643 GLES2Interface* gl = ContextGL(); 642 GLES2Interface* gl = ContextGL();
644 DCHECK(gl); 643 DCHECK(gl);
645 GLC(gl, gl->DestroyImageCHROMIUM(resource->image_id)); 644 gl->DestroyImageCHROMIUM(resource->image_id);
646 } 645 }
647 if (resource->gl_upload_query_id) { 646 if (resource->gl_upload_query_id) {
648 DCHECK(resource->origin == Resource::INTERNAL); 647 DCHECK(resource->origin == Resource::INTERNAL);
649 GLES2Interface* gl = ContextGL(); 648 GLES2Interface* gl = ContextGL();
650 DCHECK(gl); 649 DCHECK(gl);
651 GLC(gl, gl->DeleteQueriesEXT(1, &resource->gl_upload_query_id)); 650 gl->DeleteQueriesEXT(1, &resource->gl_upload_query_id);
652 } 651 }
653 if (resource->gl_read_lock_query_id) { 652 if (resource->gl_read_lock_query_id) {
654 DCHECK(resource->origin == Resource::INTERNAL); 653 DCHECK(resource->origin == Resource::INTERNAL);
655 GLES2Interface* gl = ContextGL(); 654 GLES2Interface* gl = ContextGL();
656 DCHECK(gl); 655 DCHECK(gl);
657 GLC(gl, gl->DeleteQueriesEXT(1, &resource->gl_read_lock_query_id)); 656 gl->DeleteQueriesEXT(1, &resource->gl_read_lock_query_id);
658 } 657 }
659 if (resource->gl_pixel_buffer_id) { 658 if (resource->gl_pixel_buffer_id) {
660 DCHECK(resource->origin == Resource::INTERNAL); 659 DCHECK(resource->origin == Resource::INTERNAL);
661 GLES2Interface* gl = ContextGL(); 660 GLES2Interface* gl = ContextGL();
662 DCHECK(gl); 661 DCHECK(gl);
663 GLC(gl, gl->DeleteBuffers(1, &resource->gl_pixel_buffer_id)); 662 gl->DeleteBuffers(1, &resource->gl_pixel_buffer_id);
664 } 663 }
665 if (resource->origin == Resource::EXTERNAL) { 664 if (resource->origin == Resource::EXTERNAL) {
666 DCHECK(resource->mailbox.IsValid()); 665 DCHECK(resource->mailbox.IsValid());
667 GLuint sync_point = resource->mailbox.sync_point(); 666 GLuint sync_point = resource->mailbox.sync_point();
668 if (resource->type == RESOURCE_TYPE_GL_TEXTURE) { 667 if (resource->type == RESOURCE_TYPE_GL_TEXTURE) {
669 DCHECK(resource->mailbox.IsTexture()); 668 DCHECK(resource->mailbox.IsTexture());
670 lost_resource |= lost_output_surface_; 669 lost_resource |= lost_output_surface_;
671 GLES2Interface* gl = ContextGL(); 670 GLES2Interface* gl = ContextGL();
672 DCHECK(gl); 671 DCHECK(gl);
673 if (resource->gl_id) { 672 if (resource->gl_id) {
674 GLC(gl, gl->DeleteTextures(1, &resource->gl_id)); 673 gl->DeleteTextures(1, &resource->gl_id);
675 resource->gl_id = 0; 674 resource->gl_id = 0;
676 if (!lost_resource) 675 if (!lost_resource)
677 sync_point = gl->InsertSyncPointCHROMIUM(); 676 sync_point = gl->InsertSyncPointCHROMIUM();
678 } 677 }
679 } else { 678 } else {
680 DCHECK(resource->mailbox.IsSharedMemory()); 679 DCHECK(resource->mailbox.IsSharedMemory());
681 resource->shared_bitmap = nullptr; 680 resource->shared_bitmap = nullptr;
682 resource->pixels = nullptr; 681 resource->pixels = nullptr;
683 } 682 }
684 resource->release_callback_impl.Run( 683 resource->release_callback_impl.Run(
685 sync_point, lost_resource, blocking_main_thread_task_runner_); 684 sync_point, lost_resource, blocking_main_thread_task_runner_);
686 } 685 }
687 if (resource->gl_id) { 686 if (resource->gl_id) {
688 GLES2Interface* gl = ContextGL(); 687 GLES2Interface* gl = ContextGL();
689 DCHECK(gl); 688 DCHECK(gl);
690 GLC(gl, gl->DeleteTextures(1, &resource->gl_id)); 689 gl->DeleteTextures(1, &resource->gl_id);
691 resource->gl_id = 0; 690 resource->gl_id = 0;
692 } 691 }
693 if (resource->shared_bitmap) { 692 if (resource->shared_bitmap) {
694 DCHECK(resource->origin != Resource::EXTERNAL); 693 DCHECK(resource->origin != Resource::EXTERNAL);
695 DCHECK_EQ(RESOURCE_TYPE_BITMAP, resource->type); 694 DCHECK_EQ(RESOURCE_TYPE_BITMAP, resource->type);
696 delete resource->shared_bitmap; 695 delete resource->shared_bitmap;
697 resource->pixels = NULL; 696 resource->pixels = NULL;
698 } 697 }
699 if (resource->pixels) { 698 if (resource->pixels) {
700 DCHECK(resource->origin == Resource::INTERNAL); 699 DCHECK(resource->origin == Resource::INTERNAL);
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 if (resource->type == RESOURCE_TYPE_GL_TEXTURE && !resource->gl_id) { 890 if (resource->type == RESOURCE_TYPE_GL_TEXTURE && !resource->gl_id) {
892 DCHECK(resource->origin != Resource::INTERNAL); 891 DCHECK(resource->origin != Resource::INTERNAL);
893 DCHECK(resource->mailbox.IsTexture()); 892 DCHECK(resource->mailbox.IsTexture());
894 893
895 // Mailbox sync_points must be processed by a call to 894 // Mailbox sync_points must be processed by a call to
896 // WaitSyncPointIfNeeded() prior to calling LockForRead(). 895 // WaitSyncPointIfNeeded() prior to calling LockForRead().
897 DCHECK(!resource->mailbox.sync_point()); 896 DCHECK(!resource->mailbox.sync_point());
898 897
899 GLES2Interface* gl = ContextGL(); 898 GLES2Interface* gl = ContextGL();
900 DCHECK(gl); 899 DCHECK(gl);
901 resource->gl_id = 900 resource->gl_id = gl->CreateAndConsumeTextureCHROMIUM(
902 GLC(gl, gl->CreateAndConsumeTextureCHROMIUM(resource->mailbox.target(), 901 resource->mailbox.target(), resource->mailbox.name());
903 resource->mailbox.name()));
904 } 902 }
905 903
906 if (!resource->pixels && resource->has_shared_bitmap_id && 904 if (!resource->pixels && resource->has_shared_bitmap_id &&
907 shared_bitmap_manager_) { 905 shared_bitmap_manager_) {
908 scoped_ptr<SharedBitmap> bitmap = 906 scoped_ptr<SharedBitmap> bitmap =
909 shared_bitmap_manager_->GetSharedBitmapFromId( 907 shared_bitmap_manager_->GetSharedBitmapFromId(
910 resource->size, resource->shared_bitmap_id); 908 resource->size, resource->shared_bitmap_id);
911 if (bitmap) { 909 if (bitmap) {
912 resource->shared_bitmap = bitmap.release(); 910 resource->shared_bitmap = bitmap.release();
913 resource->pixels = resource->shared_bitmap->pixels(); 911 resource->pixels = resource->shared_bitmap->pixels();
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
1260 use_texture_usage_hint_ = caps.gpu.texture_usage; 1258 use_texture_usage_hint_ = caps.gpu.texture_usage;
1261 use_compressed_texture_etc1_ = caps.gpu.texture_format_etc1; 1259 use_compressed_texture_etc1_ = caps.gpu.texture_format_etc1;
1262 yuv_resource_format_ = caps.gpu.texture_rg ? RED_8 : LUMINANCE_8; 1260 yuv_resource_format_ = caps.gpu.texture_rg ? RED_8 : LUMINANCE_8;
1263 use_sync_query_ = caps.gpu.sync_query; 1261 use_sync_query_ = caps.gpu.sync_query;
1264 1262
1265 GLES2Interface* gl = ContextGL(); 1263 GLES2Interface* gl = ContextGL();
1266 DCHECK(gl); 1264 DCHECK(gl);
1267 1265
1268 texture_uploader_ = TextureUploader::Create(gl); 1266 texture_uploader_ = TextureUploader::Create(gl);
1269 max_texture_size_ = 0; // Context expects cleared value. 1267 max_texture_size_ = 0; // Context expects cleared value.
1270 GLC(gl, gl->GetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size_)); 1268 gl->GetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size_);
1271 best_texture_format_ = PlatformColor::BestTextureFormat(use_bgra); 1269 best_texture_format_ = PlatformColor::BestTextureFormat(use_bgra);
1272 1270
1273 texture_id_allocator_.reset( 1271 texture_id_allocator_.reset(
1274 new TextureIdAllocator(gl, id_allocation_chunk_size_)); 1272 new TextureIdAllocator(gl, id_allocation_chunk_size_));
1275 buffer_id_allocator_.reset( 1273 buffer_id_allocator_.reset(
1276 new BufferIdAllocator(gl, id_allocation_chunk_size_)); 1274 new BufferIdAllocator(gl, id_allocation_chunk_size_));
1277 } 1275 }
1278 1276
1279 void ResourceProvider::CleanUpGLIfNeeded() { 1277 void ResourceProvider::CleanUpGLIfNeeded() {
1280 GLES2Interface* gl = ContextGL(); 1278 GLES2Interface* gl = ContextGL();
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
1521 if (resource->read_lock_fences_enabled) { 1519 if (resource->read_lock_fences_enabled) {
1522 if (current_read_lock_fence_.get()) 1520 if (current_read_lock_fence_.get())
1523 current_read_lock_fence_->Set(); 1521 current_read_lock_fence_->Set();
1524 resource->read_lock_fence = current_read_lock_fence_; 1522 resource->read_lock_fence = current_read_lock_fence_;
1525 } 1523 }
1526 1524
1527 if (returned.sync_point) { 1525 if (returned.sync_point) {
1528 DCHECK(!resource->has_shared_bitmap_id); 1526 DCHECK(!resource->has_shared_bitmap_id);
1529 if (resource->origin == Resource::INTERNAL) { 1527 if (resource->origin == Resource::INTERNAL) {
1530 DCHECK(resource->gl_id); 1528 DCHECK(resource->gl_id);
1531 GLC(gl, gl->WaitSyncPointCHROMIUM(returned.sync_point)); 1529 gl->WaitSyncPointCHROMIUM(returned.sync_point);
1532 } else { 1530 } else {
1533 DCHECK(!resource->gl_id); 1531 DCHECK(!resource->gl_id);
1534 resource->mailbox.set_sync_point(returned.sync_point); 1532 resource->mailbox.set_sync_point(returned.sync_point);
1535 } 1533 }
1536 } 1534 }
1537 1535
1538 if (!resource->marked_for_deletion) 1536 if (!resource->marked_for_deletion)
1539 continue; 1537 continue;
1540 1538
1541 if (!resource->child_id) { 1539 if (!resource->child_id) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1592 } else if (!source->mailbox.IsValid()) { 1590 } else if (!source->mailbox.IsValid()) {
1593 LazyCreate(source); 1591 LazyCreate(source);
1594 DCHECK(source->gl_id); 1592 DCHECK(source->gl_id);
1595 DCHECK(source->origin == Resource::INTERNAL); 1593 DCHECK(source->origin == Resource::INTERNAL);
1596 if (source->image_id) { 1594 if (source->image_id) {
1597 DCHECK(source->dirty_image); 1595 DCHECK(source->dirty_image);
1598 BindImageForSampling(source); 1596 BindImageForSampling(source);
1599 } 1597 }
1600 // This is a resource allocated by the compositor, we need to produce it. 1598 // This is a resource allocated by the compositor, we need to produce it.
1601 // Don't set a sync point, the caller will do it. 1599 // Don't set a sync point, the caller will do it.
1602 GLC(gl, gl->GenMailboxCHROMIUM(resource->mailbox_holder.mailbox.name)); 1600 gl->GenMailboxCHROMIUM(resource->mailbox_holder.mailbox.name);
1603 GLC(gl, gl->ProduceTextureDirectCHROMIUM( 1601 gl->ProduceTextureDirectCHROMIUM(source->gl_id,
1604 source->gl_id, resource->mailbox_holder.texture_target, 1602 resource->mailbox_holder.texture_target,
1605 resource->mailbox_holder.mailbox.name)); 1603 resource->mailbox_holder.mailbox.name);
1606 1604
1607 source->mailbox = TextureMailbox(resource->mailbox_holder); 1605 source->mailbox = TextureMailbox(resource->mailbox_holder);
1608 } else { 1606 } else {
1609 DCHECK(source->mailbox.IsTexture()); 1607 DCHECK(source->mailbox.IsTexture());
1610 if (source->image_id && source->dirty_image) { 1608 if (source->image_id && source->dirty_image) {
1611 DCHECK(source->gl_id); 1609 DCHECK(source->gl_id);
1612 DCHECK(source->origin == Resource::INTERNAL); 1610 DCHECK(source->origin == Resource::INTERNAL);
1613 GLC(gl, 1611 gl->BindTexture(resource->mailbox_holder.texture_target, source->gl_id);
1614 gl->BindTexture(resource->mailbox_holder.texture_target,
1615 source->gl_id));
1616 BindImageForSampling(source); 1612 BindImageForSampling(source);
1617 } 1613 }
1618 // This is either an external resource, or a compositor resource that we 1614 // This is either an external resource, or a compositor resource that we
1619 // already exported. Make sure to forward the sync point that we were given. 1615 // already exported. Make sure to forward the sync point that we were given.
1620 resource->mailbox_holder.mailbox = source->mailbox.mailbox(); 1616 resource->mailbox_holder.mailbox = source->mailbox.mailbox();
1621 resource->mailbox_holder.texture_target = source->mailbox.target(); 1617 resource->mailbox_holder.texture_target = source->mailbox.target();
1622 resource->mailbox_holder.sync_point = source->mailbox.sync_point(); 1618 resource->mailbox_holder.sync_point = source->mailbox.sync_point();
1623 source->mailbox.set_sync_point(0); 1619 source->mailbox.set_sync_point(0);
1624 } 1620 }
1625 } 1621 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1665 } 1661 }
1666 1662
1667 // We still have an exported_count, so we'll have to lose it. 1663 // We still have an exported_count, so we'll have to lose it.
1668 is_lost = true; 1664 is_lost = true;
1669 } 1665 }
1670 1666
1671 if (gl && resource.filter != resource.original_filter) { 1667 if (gl && resource.filter != resource.original_filter) {
1672 DCHECK(resource.target); 1668 DCHECK(resource.target);
1673 DCHECK(resource.gl_id); 1669 DCHECK(resource.gl_id);
1674 1670
1675 GLC(gl, gl->BindTexture(resource.target, resource.gl_id)); 1671 gl->BindTexture(resource.target, resource.gl_id);
1676 GLC(gl, 1672 gl->TexParameteri(resource.target, GL_TEXTURE_MIN_FILTER,
1677 gl->TexParameteri(resource.target, 1673 resource.original_filter);
1678 GL_TEXTURE_MIN_FILTER, 1674 gl->TexParameteri(resource.target, GL_TEXTURE_MAG_FILTER,
1679 resource.original_filter)); 1675 resource.original_filter);
1680 GLC(gl,
1681 gl->TexParameteri(resource.target,
1682 GL_TEXTURE_MAG_FILTER,
1683 resource.original_filter));
1684 } 1676 }
1685 1677
1686 ReturnedResource returned; 1678 ReturnedResource returned;
1687 returned.id = child_id; 1679 returned.id = child_id;
1688 returned.sync_point = resource.mailbox.sync_point(); 1680 returned.sync_point = resource.mailbox.sync_point();
1689 if (!returned.sync_point && resource.type == RESOURCE_TYPE_GL_TEXTURE) 1681 if (!returned.sync_point && resource.type == RESOURCE_TYPE_GL_TEXTURE)
1690 need_sync_point = true; 1682 need_sync_point = true;
1691 returned.count = resource.imported_count; 1683 returned.count = resource.imported_count;
1692 returned.lost = is_lost; 1684 returned.lost = is_lost;
1693 to_return.push_back(returned); 1685 to_return.push_back(returned);
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1825 DCHECK(thread_checker_.CalledOnValidThread()); 1817 DCHECK(thread_checker_.CalledOnValidThread());
1826 GLES2Interface* gl = ContextGL(); 1818 GLES2Interface* gl = ContextGL();
1827 ResourceMap::iterator it = resources_.find(resource_id); 1819 ResourceMap::iterator it = resources_.find(resource_id);
1828 DCHECK(it != resources_.end()); 1820 DCHECK(it != resources_.end());
1829 Resource* resource = &it->second; 1821 Resource* resource = &it->second;
1830 DCHECK(resource->lock_for_read_count); 1822 DCHECK(resource->lock_for_read_count);
1831 DCHECK(!resource->locked_for_write || resource->set_pixels_completion_forced); 1823 DCHECK(!resource->locked_for_write || resource->set_pixels_completion_forced);
1832 1824
1833 ScopedSetActiveTexture scoped_active_tex(gl, unit); 1825 ScopedSetActiveTexture scoped_active_tex(gl, unit);
1834 GLenum target = resource->target; 1826 GLenum target = resource->target;
1835 GLC(gl, gl->BindTexture(target, resource->gl_id)); 1827 gl->BindTexture(target, resource->gl_id);
1836 if (filter != resource->filter) { 1828 if (filter != resource->filter) {
1837 GLC(gl, gl->TexParameteri(target, GL_TEXTURE_MIN_FILTER, filter)); 1829 gl->TexParameteri(target, GL_TEXTURE_MIN_FILTER, filter);
1838 GLC(gl, gl->TexParameteri(target, GL_TEXTURE_MAG_FILTER, filter)); 1830 gl->TexParameteri(target, GL_TEXTURE_MAG_FILTER, filter);
1839 resource->filter = filter; 1831 resource->filter = filter;
1840 } 1832 }
1841 1833
1842 if (resource->image_id && resource->dirty_image) 1834 if (resource->image_id && resource->dirty_image)
1843 BindImageForSampling(resource); 1835 BindImageForSampling(resource);
1844 1836
1845 return target; 1837 return target;
1846 } 1838 }
1847 1839
1848 void ResourceProvider::BeginSetPixels(ResourceId id) { 1840 void ResourceProvider::BeginSetPixels(ResourceId id) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1908 "ResourceProvider::ForceSetPixelsToComplete"); 1900 "ResourceProvider::ForceSetPixelsToComplete");
1909 1901
1910 Resource* resource = GetResource(id); 1902 Resource* resource = GetResource(id);
1911 1903
1912 DCHECK(resource->locked_for_write); 1904 DCHECK(resource->locked_for_write);
1913 DCHECK(resource->pending_set_pixels); 1905 DCHECK(resource->pending_set_pixels);
1914 DCHECK(!resource->set_pixels_completion_forced); 1906 DCHECK(!resource->set_pixels_completion_forced);
1915 1907
1916 if (resource->gl_id) { 1908 if (resource->gl_id) {
1917 GLES2Interface* gl = ContextGL(); 1909 GLES2Interface* gl = ContextGL();
1918 GLC(gl, gl->BindTexture(GL_TEXTURE_2D, resource->gl_id)); 1910 gl->BindTexture(GL_TEXTURE_2D, resource->gl_id);
1919 GLC(gl, gl->WaitAsyncTexImage2DCHROMIUM(GL_TEXTURE_2D)); 1911 gl->WaitAsyncTexImage2DCHROMIUM(GL_TEXTURE_2D);
1920 GLC(gl, gl->BindTexture(GL_TEXTURE_2D, 0)); 1912 gl->BindTexture(GL_TEXTURE_2D, 0);
1921 } 1913 }
1922 1914
1923 resource->set_pixels_completion_forced = true; 1915 resource->set_pixels_completion_forced = true;
1924 } 1916 }
1925 1917
1926 bool ResourceProvider::DidSetPixelsComplete(ResourceId id) { 1918 bool ResourceProvider::DidSetPixelsComplete(ResourceId id) {
1927 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), 1919 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"),
1928 "ResourceProvider::DidSetPixelsComplete"); 1920 "ResourceProvider::DidSetPixelsComplete");
1929 1921
1930 Resource* resource = GetResource(id); 1922 Resource* resource = GetResource(id);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1973 1965
1974 DCHECK(resource->texture_pool); 1966 DCHECK(resource->texture_pool);
1975 DCHECK(resource->origin == Resource::INTERNAL); 1967 DCHECK(resource->origin == Resource::INTERNAL);
1976 DCHECK(!resource->mailbox.IsValid()); 1968 DCHECK(!resource->mailbox.IsValid());
1977 resource->gl_id = texture_id_allocator_->NextId(); 1969 resource->gl_id = texture_id_allocator_->NextId();
1978 1970
1979 GLES2Interface* gl = ContextGL(); 1971 GLES2Interface* gl = ContextGL();
1980 DCHECK(gl); 1972 DCHECK(gl);
1981 1973
1982 // Create and set texture properties. Allocation is delayed until needed. 1974 // Create and set texture properties. Allocation is delayed until needed.
1983 GLC(gl, gl->BindTexture(resource->target, resource->gl_id)); 1975 gl->BindTexture(resource->target, resource->gl_id);
1984 GLC(gl, 1976 gl->TexParameteri(resource->target, GL_TEXTURE_MIN_FILTER,
1985 gl->TexParameteri( 1977 resource->original_filter);
1986 resource->target, GL_TEXTURE_MIN_FILTER, resource->original_filter)); 1978 gl->TexParameteri(resource->target, GL_TEXTURE_MAG_FILTER,
1987 GLC(gl, 1979 resource->original_filter);
1988 gl->TexParameteri( 1980 gl->TexParameteri(resource->target, GL_TEXTURE_WRAP_S, resource->wrap_mode);
1989 resource->target, GL_TEXTURE_MAG_FILTER, resource->original_filter)); 1981 gl->TexParameteri(resource->target, GL_TEXTURE_WRAP_T, resource->wrap_mode);
1990 GLC(gl, 1982 gl->TexParameteri(resource->target, GL_TEXTURE_POOL_CHROMIUM,
1991 gl->TexParameteri( 1983 resource->texture_pool);
1992 resource->target, GL_TEXTURE_WRAP_S, resource->wrap_mode));
1993 GLC(gl,
1994 gl->TexParameteri(
1995 resource->target, GL_TEXTURE_WRAP_T, resource->wrap_mode));
1996 GLC(gl,
1997 gl->TexParameteri(
1998 resource->target, GL_TEXTURE_POOL_CHROMIUM, resource->texture_pool));
1999 if (use_texture_usage_hint_ && (resource->hint & TEXTURE_HINT_FRAMEBUFFER)) { 1984 if (use_texture_usage_hint_ && (resource->hint & TEXTURE_HINT_FRAMEBUFFER)) {
2000 GLC(gl, 1985 gl->TexParameteri(resource->target, GL_TEXTURE_USAGE_ANGLE,
2001 gl->TexParameteri(resource->target, 1986 GL_FRAMEBUFFER_ATTACHMENT_ANGLE);
2002 GL_TEXTURE_USAGE_ANGLE,
2003 GL_FRAMEBUFFER_ATTACHMENT_ANGLE));
2004 } 1987 }
2005 } 1988 }
2006 1989
2007 void ResourceProvider::AllocateForTesting(ResourceId id) { 1990 void ResourceProvider::AllocateForTesting(ResourceId id) {
2008 LazyAllocate(GetResource(id)); 1991 LazyAllocate(GetResource(id));
2009 } 1992 }
2010 1993
2011 void ResourceProvider::LazyAllocate(Resource* resource) { 1994 void ResourceProvider::LazyAllocate(Resource* resource) {
2012 DCHECK(resource); 1995 DCHECK(resource);
2013 if (resource->allocated) 1996 if (resource->allocated)
2014 return; 1997 return;
2015 LazyCreate(resource); 1998 LazyCreate(resource);
2016 if (!resource->gl_id) 1999 if (!resource->gl_id)
2017 return; 2000 return;
2018 resource->allocated = true; 2001 resource->allocated = true;
2019 GLES2Interface* gl = ContextGL(); 2002 GLES2Interface* gl = ContextGL();
2020 gfx::Size& size = resource->size; 2003 gfx::Size& size = resource->size;
2021 DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D)); 2004 DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D));
2022 ResourceFormat format = resource->format; 2005 ResourceFormat format = resource->format;
2023 GLC(gl, gl->BindTexture(GL_TEXTURE_2D, resource->gl_id)); 2006 gl->BindTexture(GL_TEXTURE_2D, resource->gl_id);
2024 if (use_texture_storage_ext_ && 2007 if (use_texture_storage_ext_ &&
2025 IsFormatSupportedForStorage(format, use_texture_format_bgra_) && 2008 IsFormatSupportedForStorage(format, use_texture_format_bgra_) &&
2026 (resource->hint & TEXTURE_HINT_IMMUTABLE)) { 2009 (resource->hint & TEXTURE_HINT_IMMUTABLE)) {
2027 GLenum storage_format = TextureToStorageFormat(format); 2010 GLenum storage_format = TextureToStorageFormat(format);
2028 GLC(gl, 2011 gl->TexStorage2DEXT(GL_TEXTURE_2D, 1, storage_format, size.width(),
2029 gl->TexStorage2DEXT( 2012 size.height());
2030 GL_TEXTURE_2D, 1, storage_format, size.width(), size.height()));
2031 } else { 2013 } else {
2032 // ETC1 does not support preallocation. 2014 // ETC1 does not support preallocation.
2033 if (format != ETC1) { 2015 if (format != ETC1) {
2034 GLC(gl, 2016 gl->TexImage2D(GL_TEXTURE_2D, 0, GLInternalFormat(format), size.width(),
2035 gl->TexImage2D(GL_TEXTURE_2D, 2017 size.height(), 0, GLDataFormat(format), GLDataType(format),
2036 0, 2018 NULL);
2037 GLInternalFormat(format),
2038 size.width(),
2039 size.height(),
2040 0,
2041 GLDataFormat(format),
2042 GLDataType(format),
2043 NULL));
2044 } 2019 }
2045 } 2020 }
2046 } 2021 }
2047 2022
2048 void ResourceProvider::BindImageForSampling(Resource* resource) { 2023 void ResourceProvider::BindImageForSampling(Resource* resource) {
2049 GLES2Interface* gl = ContextGL(); 2024 GLES2Interface* gl = ContextGL();
2050 DCHECK(resource->gl_id); 2025 DCHECK(resource->gl_id);
2051 DCHECK(resource->image_id); 2026 DCHECK(resource->image_id);
2052 2027
2053 // Release image currently bound to texture. 2028 // Release image currently bound to texture.
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
2131 Resource* resource = GetResource(id); 2106 Resource* resource = GetResource(id);
2132 DCHECK_EQ(resource->exported_count, 0); 2107 DCHECK_EQ(resource->exported_count, 0);
2133 DCHECK(resource->allocated); 2108 DCHECK(resource->allocated);
2134 if (resource->type != RESOURCE_TYPE_GL_TEXTURE || resource->gl_id) 2109 if (resource->type != RESOURCE_TYPE_GL_TEXTURE || resource->gl_id)
2135 return; 2110 return;
2136 if (!resource->mailbox.sync_point()) 2111 if (!resource->mailbox.sync_point())
2137 return; 2112 return;
2138 DCHECK(resource->mailbox.IsValid()); 2113 DCHECK(resource->mailbox.IsValid());
2139 GLES2Interface* gl = ContextGL(); 2114 GLES2Interface* gl = ContextGL();
2140 DCHECK(gl); 2115 DCHECK(gl);
2141 GLC(gl, gl->WaitSyncPointCHROMIUM(resource->mailbox.sync_point())); 2116 gl->WaitSyncPointCHROMIUM(resource->mailbox.sync_point());
2142 resource->mailbox.set_sync_point(0); 2117 resource->mailbox.set_sync_point(0);
2143 } 2118 }
2144 2119
2145 void ResourceProvider::WaitReadLockIfNeeded(ResourceId id) { 2120 void ResourceProvider::WaitReadLockIfNeeded(ResourceId id) {
2146 Resource* resource = GetResource(id); 2121 Resource* resource = GetResource(id);
2147 DCHECK_EQ(resource->exported_count, 0); 2122 DCHECK_EQ(resource->exported_count, 0);
2148 if (!resource->read_lock_fence.get()) 2123 if (!resource->read_lock_fence.get())
2149 return; 2124 return;
2150 2125
2151 resource->read_lock_fence->Wait(); 2126 resource->read_lock_fence->Wait();
(...skipping 11 matching lines...) Expand all
2163 } 2138 }
2164 2139
2165 class GrContext* ResourceProvider::GrContext(bool worker_context) const { 2140 class GrContext* ResourceProvider::GrContext(bool worker_context) const {
2166 ContextProvider* context_provider = 2141 ContextProvider* context_provider =
2167 worker_context ? output_surface_->worker_context_provider() 2142 worker_context ? output_surface_->worker_context_provider()
2168 : output_surface_->context_provider(); 2143 : output_surface_->context_provider();
2169 return context_provider ? context_provider->GrContext() : NULL; 2144 return context_provider ? context_provider->GrContext() : NULL;
2170 } 2145 }
2171 2146
2172 } // namespace cc 2147 } // namespace cc
OLDNEW
« no previous file with comments | « cc/output/static_geometry_binding.cc ('k') | cc/resources/video_resource_updater.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698