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

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

Issue 14409006: cc: Changes to use GL API for GpuMemoryBuffers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@glapi
Patch Set: Created 7 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
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 <limits.h> 7 #include <limits.h>
8 8
9 #include "base/debug/alias.h" 9 #include "base/debug/alias.h"
10 #include "base/hash_tables.h" 10 #include "base/hash_tables.h"
11 #include "base/stl_util.h" 11 #include "base/stl_util.h"
12 #include "base/string_util.h" 12 #include "base/string_util.h"
13 #include "base/strings/string_split.h" 13 #include "base/strings/string_split.h"
14 #include "cc/output/gl_renderer.h" // For the GLC() macro. 14 #include "cc/output/gl_renderer.h" // For the GLC() macro.
15 #include "cc/resources/platform_color.h" 15 #include "cc/resources/platform_color.h"
16 #include "cc/resources/transferable_resource.h" 16 #include "cc/resources/transferable_resource.h"
17 #include "cc/scheduler/texture_uploader.h" 17 #include "cc/scheduler/texture_uploader.h"
18 #include "gpu/GLES2/gl2extchromium.h" 18 #include "gpu/GLES2/gl2extchromium.h"
19 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3 D.h" 19 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3 D.h"
20 #include "third_party/khronos/GLES2/gl2.h" 20 #include "third_party/khronos/GLES2/gl2.h"
21 #include "third_party/khronos/GLES2/gl2ext.h" 21 #include "third_party/khronos/GLES2/gl2ext.h"
22 #include "ui/gfx/rect.h" 22 #include "ui/gfx/rect.h"
23 #include "ui/gfx/vector2d.h" 23 #include "ui/gfx/vector2d.h"
24 #include "webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h"
24 25
25 using WebKit::WebGraphicsContext3D; 26 using WebKit::WebGraphicsContext3D;
26 27
27 namespace cc { 28 namespace cc {
28 29
29 static GLenum TextureToStorageFormat(GLenum texture_format) { 30 static GLenum TextureToStorageFormat(GLenum texture_format) {
30 GLenum storage_format = GL_RGBA8_OES; 31 GLenum storage_format = GL_RGBA8_OES;
31 switch (texture_format) { 32 switch (texture_format) {
32 case GL_RGBA: 33 case GL_RGBA:
33 break; 34 break;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 exported(false), 74 exported(false),
74 marked_for_deletion(false), 75 marked_for_deletion(false),
75 pending_set_pixels(false), 76 pending_set_pixels(false),
76 set_pixels_completion_forced(false), 77 set_pixels_completion_forced(false),
77 allocated(false), 78 allocated(false),
78 enable_read_lock_fences(false), 79 enable_read_lock_fences(false),
79 read_lock_fence(NULL), 80 read_lock_fence(NULL),
80 size(), 81 size(),
81 format(0), 82 format(0),
82 filter(0), 83 filter(0),
83 type(static_cast<ResourceType>(0)) {} 84 type(static_cast<ResourceType>(0)),
85 use_gpu_memory_buffer(false) {}
84 86
85 ResourceProvider::Resource::~Resource() {} 87 ResourceProvider::Resource::~Resource() {}
86 88
87 ResourceProvider::Resource::Resource( 89 ResourceProvider::Resource::Resource(
88 unsigned texture_id, gfx::Size size, GLenum format, GLenum filter) 90 unsigned texture_id, gfx::Size size,
91 GLenum format, GLenum filter, bool gpu_memory_buffer)
89 : gl_id(texture_id), 92 : gl_id(texture_id),
90 gl_pixel_buffer_id(0), 93 gl_pixel_buffer_id(0),
91 gl_upload_query_id(0), 94 gl_upload_query_id(0),
92 pixels(NULL), 95 pixels(NULL),
93 pixel_buffer(NULL), 96 pixel_buffer(NULL),
94 lock_for_read_count(0), 97 lock_for_read_count(0),
95 locked_for_write(false), 98 locked_for_write(false),
96 external(false), 99 external(false),
97 exported(false), 100 exported(false),
98 marked_for_deletion(false), 101 marked_for_deletion(false),
99 pending_set_pixels(false), 102 pending_set_pixels(false),
100 set_pixels_completion_forced(false), 103 set_pixels_completion_forced(false),
101 allocated(false), 104 allocated(false),
102 enable_read_lock_fences(false), 105 enable_read_lock_fences(false),
103 read_lock_fence(NULL), 106 read_lock_fence(NULL),
104 size(size), 107 size(size),
105 format(format), 108 format(format),
106 filter(filter), 109 filter(filter),
107 type(GLTexture) {} 110 type(GLTexture),
111 use_gpu_memory_buffer(gpu_memory_buffer) {}
108 112
109 ResourceProvider::Resource::Resource( 113 ResourceProvider::Resource::Resource(
110 uint8_t* pixels, gfx::Size size, GLenum format, GLenum filter) 114 uint8_t* pixels, gfx::Size size, GLenum format, GLenum filter)
111 : gl_id(0), 115 : gl_id(0),
112 gl_pixel_buffer_id(0), 116 gl_pixel_buffer_id(0),
113 gl_upload_query_id(0), 117 gl_upload_query_id(0),
114 pixels(pixels), 118 pixels(pixels),
115 pixel_buffer(NULL), 119 pixel_buffer(NULL),
116 lock_for_read_count(0), 120 lock_for_read_count(0),
117 locked_for_write(false), 121 locked_for_write(false),
118 external(false), 122 external(false),
119 exported(false), 123 exported(false),
120 marked_for_deletion(false), 124 marked_for_deletion(false),
121 pending_set_pixels(false), 125 pending_set_pixels(false),
122 set_pixels_completion_forced(false), 126 set_pixels_completion_forced(false),
123 allocated(false), 127 allocated(false),
124 enable_read_lock_fences(false), 128 enable_read_lock_fences(false),
125 read_lock_fence(NULL), 129 read_lock_fence(NULL),
126 size(size), 130 size(size),
127 format(format), 131 format(format),
128 filter(filter), 132 filter(filter),
129 type(Bitmap) {} 133 type(Bitmap),
134 use_gpu_memory_buffer(false) {}
130 135
131 ResourceProvider::Child::Child() {} 136 ResourceProvider::Child::Child() {}
132 137
133 ResourceProvider::Child::~Child() {} 138 ResourceProvider::Child::~Child() {}
134 139
135 scoped_ptr<ResourceProvider> ResourceProvider::Create( 140 scoped_ptr<ResourceProvider> ResourceProvider::Create(
136 OutputSurface* output_surface, 141 OutputSurface* output_surface,
137 int highp_threshold_min) { 142 int highp_threshold_min) {
138 scoped_ptr<ResourceProvider> resource_provider( 143 scoped_ptr<ResourceProvider> resource_provider(
139 new ResourceProvider(output_surface)); 144 new ResourceProvider(output_surface));
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, 215 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D,
211 GL_TEXTURE_POOL_CHROMIUM, 216 GL_TEXTURE_POOL_CHROMIUM,
212 texture_pool)); 217 texture_pool));
213 if (use_texture_usage_hint_ && hint == TextureUsageFramebuffer) { 218 if (use_texture_usage_hint_ && hint == TextureUsageFramebuffer) {
214 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, 219 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D,
215 GL_TEXTURE_USAGE_ANGLE, 220 GL_TEXTURE_USAGE_ANGLE,
216 GL_FRAMEBUFFER_ATTACHMENT_ANGLE)); 221 GL_FRAMEBUFFER_ATTACHMENT_ANGLE));
217 } 222 }
218 223
219 ResourceId id = next_id_++; 224 ResourceId id = next_id_++;
220 Resource resource(texture_id, size, format, GL_LINEAR); 225 Resource resource(texture_id, size, format, GL_LINEAR,
226 use_gpu_memory_buffers_);
221 resource.allocated = false; 227 resource.allocated = false;
222 resources_[id] = resource; 228 resources_[id] = resource;
223 return id; 229 return id;
224 } 230 }
225 231
226 ResourceProvider::ResourceId ResourceProvider::CreateBitmap(gfx::Size size) { 232 ResourceProvider::ResourceId ResourceProvider::CreateBitmap(gfx::Size size) {
227 DCHECK(thread_checker_.CalledOnValidThread()); 233 DCHECK(thread_checker_.CalledOnValidThread());
228 234
229 uint8_t* pixels = new uint8_t[size.width() * size.height() * 4]; 235 uint8_t* pixels = new uint8_t[size.width() * size.height() * 4];
230 236
(...skipping 16 matching lines...) Expand all
247 GLC(context3d, context3d->texParameteri( 253 GLC(context3d, context3d->texParameteri(
248 texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); 254 texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
249 GLC(context3d, context3d->texParameteri( 255 GLC(context3d, context3d->texParameteri(
250 texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); 256 texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
251 GLC(context3d, context3d->texParameteri( 257 GLC(context3d, context3d->texParameteri(
252 texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); 258 texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
253 GLC(context3d, context3d->texParameteri( 259 GLC(context3d, context3d->texParameteri(
254 texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); 260 texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
255 261
256 ResourceId id = next_id_++; 262 ResourceId id = next_id_++;
257 Resource resource(texture_id, gfx::Size(), 0, GL_LINEAR); 263 Resource resource(texture_id, gfx::Size(), 0, GL_LINEAR, false);
258 resource.external = true; 264 resource.external = true;
259 resource.allocated = true; 265 resource.allocated = true;
260 resources_[id] = resource; 266 resources_[id] = resource;
261 return id; 267 return id;
262 } 268 }
263 269
264 ResourceProvider::ResourceId ResourceProvider::CreateResourceFromTextureMailbox( 270 ResourceProvider::ResourceId ResourceProvider::CreateResourceFromTextureMailbox(
265 const TextureMailbox& mailbox) { 271 const TextureMailbox& mailbox) {
266 DCHECK(thread_checker_.CalledOnValidThread()); 272 DCHECK(thread_checker_.CalledOnValidThread());
267 // Just store the information. Mailbox will be consumed in LockForRead(). 273 // Just store the information. Mailbox will be consumed in LockForRead().
268 ResourceId id = next_id_++; 274 ResourceId id = next_id_++;
269 unsigned texture_id = 0; 275 unsigned texture_id = 0;
270 Resource resource(texture_id, gfx::Size(), 0, GL_LINEAR); 276 Resource resource(texture_id, gfx::Size(), 0, GL_LINEAR, false);
271 resource.external = true; 277 resource.external = true;
272 resource.allocated = true; 278 resource.allocated = true;
273 resource.mailbox = mailbox; 279 resource.mailbox = mailbox;
274 resources_[id] = resource; 280 resources_[id] = resource;
275 return id; 281 return id;
276 } 282 }
277 283
278 void ResourceProvider::DeleteResource(ResourceId id) { 284 void ResourceProvider::DeleteResource(ResourceId id) {
279 DCHECK(thread_checker_.CalledOnValidThread()); 285 DCHECK(thread_checker_.CalledOnValidThread());
280 ResourceMap::iterator it = resources_.find(id); 286 ResourceMap::iterator it = resources_.find(id);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 gfx::Rect source_rect, 360 gfx::Rect source_rect,
355 gfx::Vector2d dest_offset) { 361 gfx::Vector2d dest_offset) {
356 DCHECK(thread_checker_.CalledOnValidThread()); 362 DCHECK(thread_checker_.CalledOnValidThread());
357 ResourceMap::iterator it = resources_.find(id); 363 ResourceMap::iterator it = resources_.find(id);
358 CHECK(it != resources_.end()); 364 CHECK(it != resources_.end());
359 Resource* resource = &it->second; 365 Resource* resource = &it->second;
360 DCHECK(!resource->locked_for_write); 366 DCHECK(!resource->locked_for_write);
361 DCHECK(!resource->lock_for_read_count); 367 DCHECK(!resource->lock_for_read_count);
362 DCHECK(!resource->external); 368 DCHECK(!resource->external);
363 DCHECK(!resource->exported); 369 DCHECK(!resource->exported);
370 DCHECK(!resource->use_gpu_memory_buffer);
364 DCHECK(ReadLockFenceHasPassed(resource)); 371 DCHECK(ReadLockFenceHasPassed(resource));
365 LazyAllocate(resource); 372 LazyAllocate(resource);
366 373
367 if (resource->gl_id) { 374 if (resource->gl_id) {
368 DCHECK(!resource->pending_set_pixels); 375 DCHECK(!resource->pending_set_pixels);
369 WebGraphicsContext3D* context3d = output_surface_->context3d(); 376 WebGraphicsContext3D* context3d = output_surface_->context3d();
370 DCHECK(context3d); 377 DCHECK(context3d);
371 DCHECK(texture_uploader_.get()); 378 DCHECK(texture_uploader_.get());
372 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id); 379 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id);
373 texture_uploader_->Upload(image, 380 texture_uploader_->Upload(image,
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 ResourceProvider::ResourceProvider(OutputSurface* output_surface) 614 ResourceProvider::ResourceProvider(OutputSurface* output_surface)
608 : output_surface_(output_surface), 615 : output_surface_(output_surface),
609 lost_output_surface_(false), 616 lost_output_surface_(false),
610 next_id_(1), 617 next_id_(1),
611 next_child_(1), 618 next_child_(1),
612 default_resource_type_(GLTexture), 619 default_resource_type_(GLTexture),
613 use_texture_storage_ext_(false), 620 use_texture_storage_ext_(false),
614 use_texture_usage_hint_(false), 621 use_texture_usage_hint_(false),
615 use_shallow_flush_(false), 622 use_shallow_flush_(false),
616 max_texture_size_(0), 623 max_texture_size_(0),
617 best_texture_format_(0) {} 624 best_texture_format_(0),
625 use_gpu_memory_buffers_(false) {}
618 626
619 bool ResourceProvider::Initialize(int highp_threshold_min) { 627 bool ResourceProvider::Initialize(int highp_threshold_min) {
620 DCHECK(thread_checker_.CalledOnValidThread()); 628 DCHECK(thread_checker_.CalledOnValidThread());
621 WebGraphicsContext3D* context3d = output_surface_->context3d(); 629 WebGraphicsContext3D* context3d = output_surface_->context3d();
622 if (!context3d) { 630 if (!context3d) {
623 max_texture_size_ = INT_MAX / 2; 631 max_texture_size_ = INT_MAX / 2;
624 best_texture_format_ = GL_RGBA; 632 best_texture_format_ = GL_RGBA;
625 return true; 633 return true;
626 } 634 }
627 if (!context3d->makeContextCurrent()) 635 if (!context3d->makeContextCurrent())
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 // waiting asynchronously, and resetting sync_point before calling this. 787 // waiting asynchronously, and resetting sync_point before calling this.
780 // However if the parent is a renderer (e.g. browser tag), it may be ok 788 // However if the parent is a renderer (e.g. browser tag), it may be ok
781 // (and is simpler) to wait. 789 // (and is simpler) to wait.
782 if (it->sync_point) 790 if (it->sync_point)
783 GLC(context3d, context3d->waitSyncPoint(it->sync_point)); 791 GLC(context3d, context3d->waitSyncPoint(it->sync_point));
784 GLC(context3d, texture_id = context3d->createTexture()); 792 GLC(context3d, texture_id = context3d->createTexture());
785 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, texture_id)); 793 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, texture_id));
786 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, 794 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D,
787 it->mailbox.name)); 795 it->mailbox.name));
788 ResourceId id = next_id_++; 796 ResourceId id = next_id_++;
789 Resource resource(texture_id, it->size, it->format, it->filter); 797 Resource resource(texture_id, it->size, it->format, it->filter, false);
790 resource.mailbox.SetName(it->mailbox); 798 resource.mailbox.SetName(it->mailbox);
791 // Don't allocate a texture for a child. 799 // Don't allocate a texture for a child.
792 resource.allocated = true; 800 resource.allocated = true;
793 resources_[id] = resource; 801 resources_[id] = resource;
794 child_info.parent_to_child_map[id] = it->id; 802 child_info.parent_to_child_map[id] = it->id;
795 child_info.child_to_parent_map[it->id] = id; 803 child_info.child_to_parent_map[it->id] = id;
796 } 804 }
797 } 805 }
798 806
799 void ResourceProvider::ReceiveFromParent( 807 void ResourceProvider::ReceiveFromParent(
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
873 CHECK(it != resources_.end()); 881 CHECK(it != resources_.end());
874 Resource* resource = &it->second; 882 Resource* resource = &it->second;
875 DCHECK(!resource->external); 883 DCHECK(!resource->external);
876 DCHECK(!resource->exported); 884 DCHECK(!resource->exported);
877 885
878 if (resource->gl_id) { 886 if (resource->gl_id) {
879 WebGraphicsContext3D* context3d = output_surface_->context3d(); 887 WebGraphicsContext3D* context3d = output_surface_->context3d();
880 DCHECK(context3d); 888 DCHECK(context3d);
881 if (!resource->gl_pixel_buffer_id) 889 if (!resource->gl_pixel_buffer_id)
882 resource->gl_pixel_buffer_id = context3d->createBuffer(); 890 resource->gl_pixel_buffer_id = context3d->createBuffer();
883 context3d->bindBuffer( 891 WGC3Denum target = GetTargetGivenResource(resource);
884 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 892 context3d->bindBuffer(target, resource->gl_pixel_buffer_id);
885 resource->gl_pixel_buffer_id); 893 if (resource->use_gpu_memory_buffer) {
886 context3d->bufferData( 894 typedef webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl
887 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 895 Context3DImpl;
888 resource->size.width() * resource->size.height() * 4, 896 Context3DImpl* in_process_context =
889 NULL, 897 static_cast<Context3DImpl*>(context3d);
jamesr 2013/04/25 22:28:56 you shouldn't be downcasting like this. it means t
kaanb1 2013/04/25 22:43:29 This feature is currently only used for Android We
no sievers 2013/04/25 23:28:14 Keep in mind that ChromeOS might implement 0-copy
kaanb1 2013/04/25 23:55:05 Done.
890 GL_DYNAMIC_DRAW); 898 in_process_context->imageBufferDataCHROMIUM(
891 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); 899 target,
900 resource->size.width(),
901 resource->size.height());
902 } else {
903 context3d->bufferData(
904 target,
905 resource->size.width() * resource->size.height() * 4,
906 NULL,
907 GL_DYNAMIC_DRAW);
908 }
909 context3d->bindBuffer(target, 0);
892 } 910 }
893 911
894 if (resource->pixels) { 912 if (resource->pixels) {
895 if (resource->pixel_buffer) 913 if (resource->pixel_buffer)
896 return; 914 return;
897 915
898 resource->pixel_buffer = new uint8_t[ 916 resource->pixel_buffer = new uint8_t[
899 resource->size.width() * resource->size.height() * 4]; 917 resource->size.width() * resource->size.height() * 4];
900 } 918 }
901 } 919 }
902 920
903 void ResourceProvider::ReleasePixelBuffer(ResourceId id) { 921 void ResourceProvider::ReleasePixelBuffer(ResourceId id) {
904 DCHECK(thread_checker_.CalledOnValidThread()); 922 DCHECK(thread_checker_.CalledOnValidThread());
905 ResourceMap::iterator it = resources_.find(id); 923 ResourceMap::iterator it = resources_.find(id);
906 CHECK(it != resources_.end()); 924 CHECK(it != resources_.end());
907 Resource* resource = &it->second; 925 Resource* resource = &it->second;
908 DCHECK(!resource->external); 926 DCHECK(!resource->external);
909 DCHECK(!resource->exported); 927 DCHECK(!resource->exported);
910 928
911 if (resource->gl_id) { 929 if (resource->gl_id) {
912 DCHECK(resource->gl_pixel_buffer_id); 930 DCHECK(resource->gl_pixel_buffer_id);
913 WebGraphicsContext3D* context3d = output_surface_->context3d(); 931 WebGraphicsContext3D* context3d = output_surface_->context3d();
932 WGC3Denum target = GetTargetGivenResource(resource);
914 DCHECK(context3d); 933 DCHECK(context3d);
915 context3d->bindBuffer( 934 context3d->bindBuffer(target, resource->gl_pixel_buffer_id);
916 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 935 if (resource->use_gpu_memory_buffer) {
917 resource->gl_pixel_buffer_id); 936 typedef webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl
918 context3d->bufferData( 937 Context3DImpl;
919 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 938 Context3DImpl* in_process_context =
920 0, 939 static_cast<Context3DImpl*>(context3d);
921 NULL, 940 in_process_context->imageBufferDataCHROMIUM(target, 0, 0);
922 GL_DYNAMIC_DRAW); 941 } else {
923 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); 942 context3d->bufferData(target, 0, NULL, GL_DYNAMIC_DRAW);
943 }
944 context3d->bindBuffer(target, 0);
924 } 945 }
925 946
926 if (resource->pixels) { 947 if (resource->pixels) {
927 if (!resource->pixel_buffer) 948 if (!resource->pixel_buffer)
928 return; 949 return;
929 delete[] resource->pixel_buffer; 950 delete[] resource->pixel_buffer;
930 resource->pixel_buffer = NULL; 951 resource->pixel_buffer = NULL;
931 } 952 }
932 } 953 }
933 954
934 uint8_t* ResourceProvider::MapPixelBuffer(ResourceId id) { 955 uint8_t* ResourceProvider::MapPixelBuffer(ResourceId id) {
935 DCHECK(thread_checker_.CalledOnValidThread()); 956 DCHECK(thread_checker_.CalledOnValidThread());
936 ResourceMap::iterator it = resources_.find(id); 957 ResourceMap::iterator it = resources_.find(id);
937 CHECK(it != resources_.end()); 958 CHECK(it != resources_.end());
938 Resource* resource = &it->second; 959 Resource* resource = &it->second;
939 DCHECK(!resource->external); 960 DCHECK(!resource->external);
940 DCHECK(!resource->exported); 961 DCHECK(!resource->exported);
941 962
942 if (resource->gl_id) { 963 if (resource->gl_id) {
943 WebGraphicsContext3D* context3d = output_surface_->context3d(); 964 WebGraphicsContext3D* context3d = output_surface_->context3d();
944 DCHECK(context3d); 965 DCHECK(context3d);
945 DCHECK(resource->gl_pixel_buffer_id); 966 DCHECK(resource->gl_pixel_buffer_id);
946 context3d->bindBuffer( 967 WGC3Denum target = GetTargetGivenResource(resource);
947 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 968 context3d->bindBuffer(target, resource->gl_pixel_buffer_id);
948 resource->gl_pixel_buffer_id);
949 uint8_t* image = static_cast<uint8_t*>( 969 uint8_t* image = static_cast<uint8_t*>(
950 context3d->mapBufferCHROMIUM( 970 context3d->mapBufferCHROMIUM(target, GL_WRITE_ONLY));
951 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, GL_WRITE_ONLY)); 971 context3d->bindBuffer(target, 0);
952 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0);
953 DCHECK(image); 972 DCHECK(image);
954 return image; 973 return image;
955 } 974 }
956 975
957 if (resource->pixels) 976 if (resource->pixels)
958 return resource->pixel_buffer; 977 return resource->pixel_buffer;
959 978
960 return NULL; 979 return NULL;
961 } 980 }
962 981
963 void ResourceProvider::UnmapPixelBuffer(ResourceId id) { 982 void ResourceProvider::UnmapPixelBuffer(ResourceId id) {
964 DCHECK(thread_checker_.CalledOnValidThread()); 983 DCHECK(thread_checker_.CalledOnValidThread());
965 ResourceMap::iterator it = resources_.find(id); 984 ResourceMap::iterator it = resources_.find(id);
966 CHECK(it != resources_.end()); 985 CHECK(it != resources_.end());
967 Resource* resource = &it->second; 986 Resource* resource = &it->second;
968 DCHECK(!resource->external); 987 DCHECK(!resource->external);
969 DCHECK(!resource->exported); 988 DCHECK(!resource->exported);
970 989
971 if (resource->gl_id) { 990 if (resource->gl_id) {
972 WebGraphicsContext3D* context3d = output_surface_->context3d(); 991 WebGraphicsContext3D* context3d = output_surface_->context3d();
973 DCHECK(context3d); 992 DCHECK(context3d);
974 DCHECK(resource->gl_pixel_buffer_id); 993 DCHECK(resource->gl_pixel_buffer_id);
975 context3d->bindBuffer( 994 WGC3Denum target = GetTargetGivenResource(resource);
976 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 995 context3d->bindBuffer(target, resource->gl_pixel_buffer_id);
977 resource->gl_pixel_buffer_id); 996 context3d->unmapBufferCHROMIUM(target);
978 context3d->unmapBufferCHROMIUM( 997 context3d->bindBuffer(target, 0);
979 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM);
980 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0);
981 } 998 }
982 } 999 }
983 1000
984 void ResourceProvider::SetPixelsFromBuffer(ResourceId id) { 1001 void ResourceProvider::SetPixelsFromBuffer(ResourceId id) {
985 DCHECK(thread_checker_.CalledOnValidThread()); 1002 DCHECK(thread_checker_.CalledOnValidThread());
986 ResourceMap::iterator it = resources_.find(id); 1003 ResourceMap::iterator it = resources_.find(id);
987 CHECK(it != resources_.end()); 1004 CHECK(it != resources_.end());
988 Resource* resource = &it->second; 1005 Resource* resource = &it->second;
989 DCHECK(!resource->locked_for_write); 1006 DCHECK(!resource->locked_for_write);
990 DCHECK(!resource->lock_for_read_count); 1007 DCHECK(!resource->lock_for_read_count);
991 DCHECK(!resource->external); 1008 DCHECK(!resource->external);
992 DCHECK(!resource->exported); 1009 DCHECK(!resource->exported);
993 DCHECK(ReadLockFenceHasPassed(resource)); 1010 DCHECK(ReadLockFenceHasPassed(resource));
1011 DCHECK(!resource->use_gpu_memory_buffer);
994 LazyAllocate(resource); 1012 LazyAllocate(resource);
995 1013
996 if (resource->gl_id) { 1014 if (resource->gl_id) {
997 WebGraphicsContext3D* context3d = output_surface_->context3d(); 1015 WebGraphicsContext3D* context3d = output_surface_->context3d();
998 DCHECK(context3d); 1016 DCHECK(context3d);
999 DCHECK(resource->gl_pixel_buffer_id); 1017 DCHECK(resource->gl_pixel_buffer_id);
1000 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id); 1018 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id);
1001 context3d->bindBuffer( 1019 context3d->bindBuffer(
1002 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 1020 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
1003 resource->gl_pixel_buffer_id); 1021 resource->gl_pixel_buffer_id);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1061 1079
1062 bool allocate = !resource->allocated; 1080 bool allocate = !resource->allocated;
1063 resource->allocated = true; 1081 resource->allocated = true;
1064 LockForWrite(id); 1082 LockForWrite(id);
1065 1083
1066 if (resource->gl_id) { 1084 if (resource->gl_id) {
1067 WebGraphicsContext3D* context3d = output_surface_->context3d(); 1085 WebGraphicsContext3D* context3d = output_surface_->context3d();
1068 DCHECK(context3d); 1086 DCHECK(context3d);
1069 DCHECK(resource->gl_pixel_buffer_id); 1087 DCHECK(resource->gl_pixel_buffer_id);
1070 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id); 1088 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id);
1071 context3d->bindBuffer( 1089 if (resource->use_gpu_memory_buffer) {
1072 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 1090 context3d->bindTexImage2DCHROMIUM(
1073 resource->gl_pixel_buffer_id); 1091 GL_TEXTURE_2D, resource->gl_pixel_buffer_id);
1074 if (!resource->gl_upload_query_id)
1075 resource->gl_upload_query_id = context3d->createQueryEXT();
1076 context3d->beginQueryEXT(
1077 GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM,
1078 resource->gl_upload_query_id);
1079 if (allocate) {
1080 context3d->asyncTexImage2DCHROMIUM(GL_TEXTURE_2D,
1081 0, /* level */
1082 resource->format,
1083 resource->size.width(),
1084 resource->size.height(),
1085 0, /* border */
1086 resource->format,
1087 GL_UNSIGNED_BYTE,
1088 NULL);
1089 } else { 1092 } else {
1090 context3d->asyncTexSubImage2DCHROMIUM(GL_TEXTURE_2D, 1093 context3d->bindBuffer(
1091 0, /* level */ 1094 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
1092 0, /* x */ 1095 resource->gl_pixel_buffer_id);
1093 0, /* y */ 1096 if (!resource->gl_upload_query_id)
1094 resource->size.width(), 1097 resource->gl_upload_query_id = context3d->createQueryEXT();
1095 resource->size.height(), 1098 context3d->beginQueryEXT(
1096 resource->format, 1099 GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM,
1097 GL_UNSIGNED_BYTE, 1100 resource->gl_upload_query_id);
1098 NULL); 1101 if (allocate) {
1102 context3d->asyncTexImage2DCHROMIUM(GL_TEXTURE_2D,
1103 0, /* level */
1104 resource->format,
1105 resource->size.width(),
1106 resource->size.height(),
1107 0, /* border */
1108 resource->format,
1109 GL_UNSIGNED_BYTE,
1110 NULL);
1111 } else {
1112 context3d->asyncTexSubImage2DCHROMIUM(GL_TEXTURE_2D,
1113 0, /* level */
1114 0, /* x */
1115 0, /* y */
1116 resource->size.width(),
1117 resource->size.height(),
1118 resource->format,
1119 GL_UNSIGNED_BYTE,
1120 NULL);
1121 }
1122 context3d->endQueryEXT(GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM);
1123 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0);
1099 } 1124 }
1100 context3d->endQueryEXT(GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM);
1101 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0);
1102 } 1125 }
1103 1126
1104 if (resource->pixels) 1127 if (resource->pixels)
1105 SetPixelsFromBuffer(id); 1128 SetPixelsFromBuffer(id);
1106 1129
1107 resource->pending_set_pixels = true; 1130 resource->pending_set_pixels = true;
1108 resource->set_pixels_completion_forced = false; 1131 resource->set_pixels_completion_forced = false;
1109 } 1132 }
1110 1133
1111 void ResourceProvider::ForceSetPixelsToComplete(ResourceId id) { 1134 void ResourceProvider::ForceSetPixelsToComplete(ResourceId id) {
1112 DCHECK(thread_checker_.CalledOnValidThread()); 1135 DCHECK(thread_checker_.CalledOnValidThread());
1113 ResourceMap::iterator it = resources_.find(id); 1136 ResourceMap::iterator it = resources_.find(id);
1114 CHECK(it != resources_.end()); 1137 CHECK(it != resources_.end());
1115 Resource* resource = &it->second; 1138 Resource* resource = &it->second;
1116 DCHECK(resource->locked_for_write); 1139 DCHECK(resource->locked_for_write);
1117 DCHECK(resource->pending_set_pixels); 1140 DCHECK(resource->pending_set_pixels);
1118 DCHECK(!resource->set_pixels_completion_forced); 1141 DCHECK(!resource->set_pixels_completion_forced);
1142 DCHECK(!resource->use_gpu_memory_buffer);
1119 1143
1120 if (resource->gl_id) { 1144 if (resource->gl_id) {
1121 WebGraphicsContext3D* context3d = output_surface_->context3d(); 1145 WebGraphicsContext3D* context3d = output_surface_->context3d();
1122 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id)); 1146 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id));
1123 GLC(context3d, context3d->waitAsyncTexImage2DCHROMIUM(GL_TEXTURE_2D)); 1147 GLC(context3d, context3d->waitAsyncTexImage2DCHROMIUM(GL_TEXTURE_2D));
1124 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, 0)); 1148 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, 0));
1125 } 1149 }
1126 1150
1127 resource->set_pixels_completion_forced = true; 1151 resource->set_pixels_completion_forced = true;
1128 } 1152 }
1129 1153
1130 bool ResourceProvider::DidSetPixelsComplete(ResourceId id) { 1154 bool ResourceProvider::DidSetPixelsComplete(ResourceId id) {
1131 DCHECK(thread_checker_.CalledOnValidThread()); 1155 DCHECK(thread_checker_.CalledOnValidThread());
1132 ResourceMap::iterator it = resources_.find(id); 1156 ResourceMap::iterator it = resources_.find(id);
1133 CHECK(it != resources_.end()); 1157 CHECK(it != resources_.end());
1134 Resource* resource = &it->second; 1158 Resource* resource = &it->second;
1135 DCHECK(resource->locked_for_write); 1159 DCHECK(resource->locked_for_write);
1136 DCHECK(resource->pending_set_pixels); 1160 DCHECK(resource->pending_set_pixels);
1161 DCHECK(!resource->use_gpu_memory_buffer);
1137 1162
1138 if (resource->gl_id) { 1163 if (resource->gl_id) {
1139 WebGraphicsContext3D* context3d = output_surface_->context3d(); 1164 WebGraphicsContext3D* context3d = output_surface_->context3d();
1140 DCHECK(context3d); 1165 DCHECK(context3d);
1141 DCHECK(resource->gl_upload_query_id); 1166 DCHECK(resource->gl_upload_query_id);
1142 unsigned complete = 1; 1167 unsigned complete = 1;
1143 context3d->getQueryObjectuivEXT( 1168 context3d->getQueryObjectuivEXT(
1144 resource->gl_upload_query_id, 1169 resource->gl_upload_query_id,
1145 GL_QUERY_RESULT_AVAILABLE_EXT, 1170 GL_QUERY_RESULT_AVAILABLE_EXT,
1146 &complete); 1171 &complete);
1147 if (!complete) 1172 if (!complete)
1148 return false; 1173 return false;
1149 } 1174 }
1150 1175
1151 resource->pending_set_pixels = false; 1176 resource->pending_set_pixels = false;
1152 UnlockForWrite(id); 1177 UnlockForWrite(id);
1153 1178
1154 return true; 1179 return true;
1155 } 1180 }
1156 1181
1157 void ResourceProvider::AbortSetPixels(ResourceId id) { 1182 void ResourceProvider::AbortSetPixels(ResourceId id) {
1158 DCHECK(thread_checker_.CalledOnValidThread()); 1183 DCHECK(thread_checker_.CalledOnValidThread());
1159 ResourceMap::iterator it = resources_.find(id); 1184 ResourceMap::iterator it = resources_.find(id);
1160 CHECK(it != resources_.end()); 1185 CHECK(it != resources_.end());
1161 Resource* resource = &it->second; 1186 Resource* resource = &it->second;
1162 DCHECK(resource->locked_for_write); 1187 DCHECK(resource->locked_for_write);
1163 DCHECK(resource->pending_set_pixels); 1188 DCHECK(resource->pending_set_pixels);
1189 DCHECK(!resource->use_gpu_memory_buffer);
1164 1190
1165 if (resource->gl_id) { 1191 if (resource->gl_id) {
1166 WebGraphicsContext3D* context3d = output_surface_->context3d(); 1192 WebGraphicsContext3D* context3d = output_surface_->context3d();
1167 DCHECK(context3d); 1193 DCHECK(context3d);
1168 DCHECK(resource->gl_upload_query_id); 1194 DCHECK(resource->gl_upload_query_id);
1169 // CHROMIUM_async_pixel_transfers currently doesn't have a way to 1195 // CHROMIUM_async_pixel_transfers currently doesn't have a way to
1170 // abort an upload. The best we can do is delete the query and 1196 // abort an upload. The best we can do is delete the query and
1171 // the texture. 1197 // the texture.
1172 context3d->deleteQueryEXT(resource->gl_upload_query_id); 1198 context3d->deleteQueryEXT(resource->gl_upload_query_id);
1173 resource->gl_upload_query_id = 0; 1199 resource->gl_upload_query_id = 0;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1220 1246
1221 void ResourceProvider::EnableReadLockFences(ResourceProvider::ResourceId id, 1247 void ResourceProvider::EnableReadLockFences(ResourceProvider::ResourceId id,
1222 bool enable) { 1248 bool enable) {
1223 DCHECK(thread_checker_.CalledOnValidThread()); 1249 DCHECK(thread_checker_.CalledOnValidThread());
1224 ResourceMap::iterator it = resources_.find(id); 1250 ResourceMap::iterator it = resources_.find(id);
1225 CHECK(it != resources_.end()); 1251 CHECK(it != resources_.end());
1226 Resource* resource = &it->second; 1252 Resource* resource = &it->second;
1227 resource->enable_read_lock_fences = enable; 1253 resource->enable_read_lock_fences = enable;
1228 } 1254 }
1229 1255
1256 void ResourceProvider::SetUseGpuMemoryBuffers(bool use_gpu_memory_buffers) {
1257 use_gpu_memory_buffers_ = use_gpu_memory_buffers;
1258 }
1259
1260 GLenum ResourceProvider::GetTargetGivenResource(Resource* resource) {
1261 return resource->use_gpu_memory_buffer
1262 ? GL_IMAGE_BUFFER_CHROMIUM
1263 : GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM;
1264 }
1265
1230 } // namespace cc 1266 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698