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

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

Issue 21159007: cc: Adding support for RGBA_4444 tile textures (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Code review feedback Created 7 years, 3 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 <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 16 matching lines...) Expand all
27 using WebKit::WebGraphicsContext3D; 27 using WebKit::WebGraphicsContext3D;
28 28
29 namespace cc { 29 namespace cc {
30 30
31 namespace { 31 namespace {
32 32
33 // Measured in seconds. 33 // Measured in seconds.
34 const double kSoftwareUploadTickRate = 0.000250; 34 const double kSoftwareUploadTickRate = 0.000250;
35 const double kTextureUploadTickRate = 0.004; 35 const double kTextureUploadTickRate = 0.004;
36 36
37 GLenum TextureToStorageFormat(GLenum texture_format) { 37 GLenum TextureToStorageFormat(ResourceFormat format) {
38 GLenum storage_format = GL_RGBA8_OES; 38 GLenum storage_format = GL_RGBA8_OES;
39 switch (texture_format) { 39 switch (format) {
40 case GL_RGBA: 40 case RGBA_8888:
41 case RGBA_4444:
42 case LUMINANCE_8:
41 break; 43 break;
42 case GL_BGRA_EXT: 44 case BGRA_8888:
43 storage_format = GL_BGRA8_EXT; 45 storage_format = GL_BGRA8_EXT;
44 break; 46 break;
45 default:
46 NOTREACHED();
47 break;
48 } 47 }
49 48
50 return storage_format; 49 return storage_format;
51 } 50 }
52 51
53 bool IsTextureFormatSupportedForStorage(GLenum format) { 52 bool IsFormatSupportedForStorage(ResourceFormat format) {
54 return (format == GL_RGBA || format == GL_BGRA_EXT); 53 switch (format) {
54 case RGBA_8888:
55 case BGRA_8888:
56 return true;
57 case RGBA_4444:
58 case LUMINANCE_8:
59 return false;
60 }
61 return false;
55 } 62 }
56 63
57 class ScopedSetActiveTexture { 64 class ScopedSetActiveTexture {
58 public: 65 public:
59 ScopedSetActiveTexture(WebGraphicsContext3D* context3d, GLenum unit) 66 ScopedSetActiveTexture(WebGraphicsContext3D* context3d, GLenum unit)
60 : context3d_(context3d), unit_(unit) { 67 : context3d_(context3d), unit_(unit) {
61 DCHECK_EQ(GL_TEXTURE0, ResourceProvider::GetActiveTextureUnit(context3d_)); 68 DCHECK_EQ(GL_TEXTURE0, ResourceProvider::GetActiveTextureUnit(context3d_));
62 69
63 if (unit_ != GL_TEXTURE0) 70 if (unit_ != GL_TEXTURE0)
64 GLC(context3d_, context3d_->activeTexture(unit_)); 71 GLC(context3d_, context3d_->activeTexture(unit_));
(...skipping 23 matching lines...) Expand all
88 exported_count(0), 95 exported_count(0),
89 locked_for_write(false), 96 locked_for_write(false),
90 external(false), 97 external(false),
91 marked_for_deletion(false), 98 marked_for_deletion(false),
92 pending_set_pixels(false), 99 pending_set_pixels(false),
93 set_pixels_completion_forced(false), 100 set_pixels_completion_forced(false),
94 allocated(false), 101 allocated(false),
95 enable_read_lock_fences(false), 102 enable_read_lock_fences(false),
96 read_lock_fence(NULL), 103 read_lock_fence(NULL),
97 size(), 104 size(),
98 format(0),
99 filter(0), 105 filter(0),
100 image_id(0), 106 image_id(0),
101 texture_pool(0), 107 texture_pool(0),
102 wrap_mode(0), 108 wrap_mode(0),
103 hint(TextureUsageAny), 109 hint(TextureUsageAny),
104 type(static_cast<ResourceType>(0)) {} 110 type(static_cast<ResourceType>(0)),
111 format(RGBA_8888) {}
105 112
106 ResourceProvider::Resource::~Resource() {} 113 ResourceProvider::Resource::~Resource() {}
107 114
108 ResourceProvider::Resource::Resource( 115 ResourceProvider::Resource::Resource(
109 unsigned texture_id, 116 unsigned texture_id,
110 gfx::Size size, 117 gfx::Size size,
111 GLenum format,
112 GLenum filter, 118 GLenum filter,
113 GLenum texture_pool, 119 GLenum texture_pool,
114 GLint wrap_mode, 120 GLint wrap_mode,
115 TextureUsageHint hint) 121 TextureUsageHint hint,
122 ResourceFormat format)
116 : gl_id(texture_id), 123 : gl_id(texture_id),
117 gl_pixel_buffer_id(0), 124 gl_pixel_buffer_id(0),
118 gl_upload_query_id(0), 125 gl_upload_query_id(0),
119 pixels(NULL), 126 pixels(NULL),
120 pixel_buffer(NULL), 127 pixel_buffer(NULL),
121 lock_for_read_count(0), 128 lock_for_read_count(0),
122 imported_count(0), 129 imported_count(0),
123 exported_count(0), 130 exported_count(0),
124 locked_for_write(false), 131 locked_for_write(false),
125 external(false), 132 external(false),
126 marked_for_deletion(false), 133 marked_for_deletion(false),
127 pending_set_pixels(false), 134 pending_set_pixels(false),
128 set_pixels_completion_forced(false), 135 set_pixels_completion_forced(false),
129 allocated(false), 136 allocated(false),
130 enable_read_lock_fences(false), 137 enable_read_lock_fences(false),
131 read_lock_fence(NULL), 138 read_lock_fence(NULL),
132 size(size), 139 size(size),
133 format(format),
134 filter(filter), 140 filter(filter),
135 image_id(0), 141 image_id(0),
136 texture_pool(texture_pool), 142 texture_pool(texture_pool),
137 wrap_mode(wrap_mode), 143 wrap_mode(wrap_mode),
138 hint(hint), 144 hint(hint),
139 type(GLTexture) { 145 type(GLTexture),
146 format(format) {
140 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); 147 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT);
141 } 148 }
142 149
143 ResourceProvider::Resource::Resource( 150 ResourceProvider::Resource::Resource(
144 uint8_t* pixels, 151 uint8_t* pixels,
145 gfx::Size size, 152 gfx::Size size,
146 GLenum format,
147 GLenum filter, 153 GLenum filter,
148 GLint wrap_mode) 154 GLint wrap_mode)
149 : gl_id(0), 155 : gl_id(0),
150 gl_pixel_buffer_id(0), 156 gl_pixel_buffer_id(0),
151 gl_upload_query_id(0), 157 gl_upload_query_id(0),
152 pixels(pixels), 158 pixels(pixels),
153 pixel_buffer(NULL), 159 pixel_buffer(NULL),
154 lock_for_read_count(0), 160 lock_for_read_count(0),
155 imported_count(0), 161 imported_count(0),
156 exported_count(0), 162 exported_count(0),
157 locked_for_write(false), 163 locked_for_write(false),
158 external(false), 164 external(false),
159 marked_for_deletion(false), 165 marked_for_deletion(false),
160 pending_set_pixels(false), 166 pending_set_pixels(false),
161 set_pixels_completion_forced(false), 167 set_pixels_completion_forced(false),
162 allocated(false), 168 allocated(false),
163 enable_read_lock_fences(false), 169 enable_read_lock_fences(false),
164 read_lock_fence(NULL), 170 read_lock_fence(NULL),
165 size(size), 171 size(size),
166 format(format),
167 filter(filter), 172 filter(filter),
168 image_id(0), 173 image_id(0),
169 texture_pool(0), 174 texture_pool(0),
170 wrap_mode(wrap_mode), 175 wrap_mode(wrap_mode),
171 hint(TextureUsageAny), 176 hint(TextureUsageAny),
172 type(Bitmap) { 177 type(Bitmap),
178 format(RGBA_8888) {
173 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); 179 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT);
174 } 180 }
175 181
176 ResourceProvider::Child::Child() {} 182 ResourceProvider::Child::Child() {}
177 183
178 ResourceProvider::Child::~Child() {} 184 ResourceProvider::Child::~Child() {}
179 185
180 scoped_ptr<ResourceProvider> ResourceProvider::Create( 186 scoped_ptr<ResourceProvider> ResourceProvider::Create(
181 OutputSurface* output_surface, 187 OutputSurface* output_surface,
182 int highp_threshold_min) { 188 int highp_threshold_min) {
(...skipping 21 matching lines...) Expand all
204 210
205 CleanUpGLIfNeeded(); 211 CleanUpGLIfNeeded();
206 } 212 }
207 213
208 bool ResourceProvider::InUseByConsumer(ResourceId id) { 214 bool ResourceProvider::InUseByConsumer(ResourceId id) {
209 Resource* resource = GetResource(id); 215 Resource* resource = GetResource(id);
210 return resource->lock_for_read_count > 0 || resource->exported_count > 0; 216 return resource->lock_for_read_count > 0 || resource->exported_count > 0;
211 } 217 }
212 218
213 ResourceProvider::ResourceId ResourceProvider::CreateResource( 219 ResourceProvider::ResourceId ResourceProvider::CreateResource(
214 gfx::Size size, GLenum format, GLint wrap_mode, TextureUsageHint hint) { 220 gfx::Size size,
221 GLint wrap_mode,
222 TextureUsageHint hint,
223 ResourceFormat format) {
215 DCHECK(!size.IsEmpty()); 224 DCHECK(!size.IsEmpty());
216 switch (default_resource_type_) { 225 switch (default_resource_type_) {
217 case GLTexture: 226 case GLTexture:
218 return CreateGLTexture(size, format, GL_TEXTURE_POOL_UNMANAGED_CHROMIUM, 227 return CreateGLTexture(size,
219 wrap_mode, hint); 228 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM,
229 wrap_mode,
230 hint,
231 format);
220 case Bitmap: 232 case Bitmap:
221 // The only wrap_mode currently implemented in software mode is 233 DCHECK_EQ(RGBA_8888, format);
222 // GL_CLAMP_TO_EDGE.
223 // http://crbug.com/284796
224 DCHECK(format == GL_RGBA);
225 return CreateBitmap(size); 234 return CreateBitmap(size);
226 case InvalidType: 235 case InvalidType:
227 break; 236 break;
228 } 237 }
229 238
230 LOG(FATAL) << "Invalid default resource type."; 239 LOG(FATAL) << "Invalid default resource type.";
231 return 0; 240 return 0;
232 } 241 }
233 242
234 ResourceProvider::ResourceId ResourceProvider::CreateManagedResource( 243 ResourceProvider::ResourceId ResourceProvider::CreateManagedResource(
235 gfx::Size size, GLenum format, GLint wrap_mode, TextureUsageHint hint) { 244 gfx::Size size,
245 GLint wrap_mode,
246 TextureUsageHint hint,
247 ResourceFormat format) {
236 DCHECK(!size.IsEmpty()); 248 DCHECK(!size.IsEmpty());
237 switch (default_resource_type_) { 249 switch (default_resource_type_) {
238 case GLTexture: 250 case GLTexture:
239 return CreateGLTexture(size, format, GL_TEXTURE_POOL_MANAGED_CHROMIUM, 251 return CreateGLTexture(size,
240 wrap_mode, hint); 252 GL_TEXTURE_POOL_MANAGED_CHROMIUM,
253 wrap_mode,
254 hint,
255 format);
241 case Bitmap: 256 case Bitmap:
242 DCHECK(format == GL_RGBA); 257 DCHECK_EQ(RGBA_8888, format);
243 return CreateBitmap(size); 258 return CreateBitmap(size);
244 case InvalidType: 259 case InvalidType:
245 break; 260 break;
246 } 261 }
247 262
248 LOG(FATAL) << "Invalid default resource type."; 263 LOG(FATAL) << "Invalid default resource type.";
249 return 0; 264 return 0;
250 } 265 }
251 266
252 ResourceProvider::ResourceId ResourceProvider::CreateGLTexture( 267 ResourceProvider::ResourceId ResourceProvider::CreateGLTexture(
253 gfx::Size size, 268 gfx::Size size,
254 GLenum format,
255 GLenum texture_pool, 269 GLenum texture_pool,
256 GLint wrap_mode, 270 GLint wrap_mode,
257 TextureUsageHint hint) { 271 TextureUsageHint hint,
272 ResourceFormat format) {
258 DCHECK_LE(size.width(), max_texture_size_); 273 DCHECK_LE(size.width(), max_texture_size_);
259 DCHECK_LE(size.height(), max_texture_size_); 274 DCHECK_LE(size.height(), max_texture_size_);
260 DCHECK(thread_checker_.CalledOnValidThread()); 275 DCHECK(thread_checker_.CalledOnValidThread());
261 276
262 ResourceId id = next_id_++; 277 ResourceId id = next_id_++;
263 Resource resource(0, size, format, GL_LINEAR, texture_pool, wrap_mode, hint); 278 Resource resource(0, size, GL_LINEAR, texture_pool, wrap_mode, hint, format);
264 resource.allocated = false; 279 resource.allocated = false;
265 resources_[id] = resource; 280 resources_[id] = resource;
266 return id; 281 return id;
267 } 282 }
268 283
269 ResourceProvider::ResourceId ResourceProvider::CreateBitmap(gfx::Size size) { 284 ResourceProvider::ResourceId ResourceProvider::CreateBitmap(gfx::Size size) {
270 DCHECK(thread_checker_.CalledOnValidThread()); 285 DCHECK(thread_checker_.CalledOnValidThread());
271 286
272 uint8_t* pixels = new uint8_t[4 * size.GetArea()]; 287 uint8_t* pixels = new uint8_t[4 * size.GetArea()];
273 288
274 ResourceId id = next_id_++; 289 ResourceId id = next_id_++;
275 Resource resource(pixels, size, GL_RGBA, GL_LINEAR, GL_CLAMP_TO_EDGE); 290 Resource resource(pixels, size, GL_LINEAR, GL_CLAMP_TO_EDGE);
276 resource.allocated = true; 291 resource.allocated = true;
277 resources_[id] = resource; 292 resources_[id] = resource;
278 return id; 293 return id;
279 } 294 }
280 295
281 ResourceProvider::ResourceId 296 ResourceProvider::ResourceId
282 ResourceProvider::CreateResourceFromExternalTexture( 297 ResourceProvider::CreateResourceFromExternalTexture(
283 unsigned texture_target, 298 unsigned texture_target,
284 unsigned texture_id) { 299 unsigned texture_id) {
285 DCHECK(thread_checker_.CalledOnValidThread()); 300 DCHECK(thread_checker_.CalledOnValidThread());
286 301
287 WebGraphicsContext3D* context3d = Context3d(); 302 WebGraphicsContext3D* context3d = Context3d();
288 DCHECK(context3d); 303 DCHECK(context3d);
289 GLC(context3d, context3d->bindTexture(texture_target, texture_id)); 304 GLC(context3d, context3d->bindTexture(texture_target, texture_id));
290 GLC(context3d, context3d->texParameteri( 305 GLC(context3d, context3d->texParameteri(
291 texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); 306 texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
292 GLC(context3d, context3d->texParameteri( 307 GLC(context3d, context3d->texParameteri(
293 texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); 308 texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
294 GLC(context3d, context3d->texParameteri( 309 GLC(context3d, context3d->texParameteri(
295 texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); 310 texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
296 GLC(context3d, context3d->texParameteri( 311 GLC(context3d, context3d->texParameteri(
297 texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); 312 texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
298 313
299 ResourceId id = next_id_++; 314 ResourceId id = next_id_++;
300 Resource resource(texture_id, gfx::Size(), 0, GL_LINEAR, 0, GL_CLAMP_TO_EDGE, 315 Resource resource(texture_id,
301 TextureUsageAny); 316 gfx::Size(),
317 GL_LINEAR,
318 0,
319 GL_CLAMP_TO_EDGE,
320 TextureUsageAny,
321 RGBA_8888);
302 resource.external = true; 322 resource.external = true;
303 resource.allocated = true; 323 resource.allocated = true;
304 resources_[id] = resource; 324 resources_[id] = resource;
305 return id; 325 return id;
306 } 326 }
307 327
308 ResourceProvider::ResourceId ResourceProvider::CreateResourceFromTextureMailbox( 328 ResourceProvider::ResourceId ResourceProvider::CreateResourceFromTextureMailbox(
309 const TextureMailbox& mailbox) { 329 const TextureMailbox& mailbox) {
310 DCHECK(thread_checker_.CalledOnValidThread()); 330 DCHECK(thread_checker_.CalledOnValidThread());
311 // Just store the information. Mailbox will be consumed in LockForRead(). 331 // Just store the information. Mailbox will be consumed in LockForRead().
312 ResourceId id = next_id_++; 332 ResourceId id = next_id_++;
313 DCHECK(mailbox.IsValid()); 333 DCHECK(mailbox.IsValid());
314 Resource& resource = resources_[id]; 334 Resource& resource = resources_[id];
315 if (mailbox.IsTexture()) { 335 if (mailbox.IsTexture()) {
316 resource = Resource(0, gfx::Size(), 0, GL_LINEAR, 0, GL_CLAMP_TO_EDGE, 336 resource = Resource(0,
317 TextureUsageAny); 337 gfx::Size(),
338 GL_LINEAR,
339 0,
340 GL_CLAMP_TO_EDGE,
341 TextureUsageAny,
342 RGBA_8888);
318 } else { 343 } else {
319 DCHECK(mailbox.IsSharedMemory()); 344 DCHECK(mailbox.IsSharedMemory());
320 base::SharedMemory* shared_memory = mailbox.shared_memory(); 345 base::SharedMemory* shared_memory = mailbox.shared_memory();
321 DCHECK(shared_memory->memory()); 346 DCHECK(shared_memory->memory());
322 uint8_t* pixels = reinterpret_cast<uint8_t*>(shared_memory->memory()); 347 uint8_t* pixels = reinterpret_cast<uint8_t*>(shared_memory->memory());
323 resource = Resource(pixels, mailbox.shared_memory_size(), 348 resource = Resource(
324 GL_RGBA, GL_LINEAR, GL_CLAMP_TO_EDGE); 349 pixels, mailbox.shared_memory_size(), GL_LINEAR, GL_CLAMP_TO_EDGE);
325 } 350 }
326 resource.external = true; 351 resource.external = true;
327 resource.allocated = true; 352 resource.allocated = true;
328 resource.mailbox = mailbox; 353 resource.mailbox = mailbox;
329 return id; 354 return id;
330 } 355 }
331 356
332 void ResourceProvider::DeleteResource(ResourceId id) { 357 void ResourceProvider::DeleteResource(ResourceId id) {
333 DCHECK(thread_checker_.CalledOnValidThread()); 358 DCHECK(thread_checker_.CalledOnValidThread());
334 ResourceMap::iterator it = resources_.find(id); 359 ResourceMap::iterator it = resources_.find(id);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 texture_uploader_->Upload(image, 456 texture_uploader_->Upload(image,
432 image_rect, 457 image_rect,
433 source_rect, 458 source_rect,
434 dest_offset, 459 dest_offset,
435 resource->format, 460 resource->format,
436 resource->size); 461 resource->size);
437 } 462 }
438 463
439 if (resource->pixels) { 464 if (resource->pixels) {
440 DCHECK(resource->allocated); 465 DCHECK(resource->allocated);
441 DCHECK(resource->format == GL_RGBA); 466 DCHECK_EQ(RGBA_8888, resource->format);
442 SkBitmap src_full; 467 SkBitmap src_full;
443 src_full.setConfig( 468 src_full.setConfig(
444 SkBitmap::kARGB_8888_Config, image_rect.width(), image_rect.height()); 469 SkBitmap::kARGB_8888_Config, image_rect.width(), image_rect.height());
445 src_full.setPixels(const_cast<uint8_t*>(image)); 470 src_full.setPixels(const_cast<uint8_t*>(image));
446 SkBitmap src_subset; 471 SkBitmap src_subset;
447 SkIRect sk_source_rect = SkIRect::MakeXYWH(source_rect.x(), 472 SkIRect sk_source_rect = SkIRect::MakeXYWH(source_rect.x(),
448 source_rect.y(), 473 source_rect.y(),
449 source_rect.width(), 474 source_rect.width(),
450 source_rect.height()); 475 source_rect.height());
451 sk_source_rect.offset(-image_rect.x(), -image_rect.y()); 476 sk_source_rect.offset(-image_rect.x(), -image_rect.y());
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 DCHECK(texture_id_); 680 DCHECK(texture_id_);
656 } 681 }
657 682
658 ResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() { 683 ResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() {
659 resource_provider_->UnlockForWrite(resource_id_); 684 resource_provider_->UnlockForWrite(resource_id_);
660 } 685 }
661 686
662 void ResourceProvider::PopulateSkBitmapWithResource( 687 void ResourceProvider::PopulateSkBitmapWithResource(
663 SkBitmap* sk_bitmap, const Resource* resource) { 688 SkBitmap* sk_bitmap, const Resource* resource) {
664 DCHECK(resource->pixels); 689 DCHECK(resource->pixels);
665 DCHECK(resource->format == GL_RGBA); 690 DCHECK_EQ(RGBA_8888, resource->format);
666 sk_bitmap->setConfig(SkBitmap::kARGB_8888_Config, 691 sk_bitmap->setConfig(SkBitmap::kARGB_8888_Config,
667 resource->size.width(), 692 resource->size.width(),
668 resource->size.height()); 693 resource->size.height());
669 sk_bitmap->setPixels(resource->pixels); 694 sk_bitmap->setPixels(resource->pixels);
670 } 695 }
671 696
672 ResourceProvider::ScopedReadLockSoftware::ScopedReadLockSoftware( 697 ResourceProvider::ScopedReadLockSoftware::ScopedReadLockSoftware(
673 ResourceProvider* resource_provider, 698 ResourceProvider* resource_provider,
674 ResourceProvider::ResourceId resource_id) 699 ResourceProvider::ResourceId resource_id)
675 : resource_provider_(resource_provider), 700 : resource_provider_(resource_provider),
(...skipping 25 matching lines...) Expand all
701 : output_surface_(output_surface), 726 : output_surface_(output_surface),
702 lost_output_surface_(false), 727 lost_output_surface_(false),
703 highp_threshold_min_(highp_threshold_min), 728 highp_threshold_min_(highp_threshold_min),
704 next_id_(1), 729 next_id_(1),
705 next_child_(1), 730 next_child_(1),
706 default_resource_type_(InvalidType), 731 default_resource_type_(InvalidType),
707 use_texture_storage_ext_(false), 732 use_texture_storage_ext_(false),
708 use_texture_usage_hint_(false), 733 use_texture_usage_hint_(false),
709 use_shallow_flush_(false), 734 use_shallow_flush_(false),
710 max_texture_size_(0), 735 max_texture_size_(0),
711 best_texture_format_(0) { 736 best_texture_format_(RGBA_8888) {
712 DCHECK(output_surface_->HasClient()); 737 DCHECK(output_surface_->HasClient());
713 } 738 }
714 739
715 void ResourceProvider::InitializeSoftware() { 740 void ResourceProvider::InitializeSoftware() {
716 DCHECK(thread_checker_.CalledOnValidThread()); 741 DCHECK(thread_checker_.CalledOnValidThread());
717 DCHECK_NE(Bitmap, default_resource_type_); 742 DCHECK_NE(Bitmap, default_resource_type_);
718 743
719 CleanUpGLIfNeeded(); 744 CleanUpGLIfNeeded();
720 745
721 default_resource_type_ = Bitmap; 746 default_resource_type_ = Bitmap;
722 max_texture_size_ = INT_MAX / 2; 747 max_texture_size_ = INT_MAX / 2;
723 best_texture_format_ = GL_RGBA; 748 best_texture_format_ = RGBA_8888;
724 } 749 }
725 750
726 bool ResourceProvider::InitializeGL() { 751 bool ResourceProvider::InitializeGL() {
727 DCHECK(thread_checker_.CalledOnValidThread()); 752 DCHECK(thread_checker_.CalledOnValidThread());
728 DCHECK(!texture_uploader_); 753 DCHECK(!texture_uploader_);
729 DCHECK_NE(GLTexture, default_resource_type_); 754 DCHECK_NE(GLTexture, default_resource_type_);
730 755
731 WebGraphicsContext3D* context3d = Context3d(); 756 WebGraphicsContext3D* context3d = Context3d();
732 DCHECK(context3d); 757 DCHECK(context3d);
733 758
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
902 // deadlocks and/or security issues. The caller is responsible for 927 // deadlocks and/or security issues. The caller is responsible for
903 // waiting asynchronously, and resetting sync_point before calling this. 928 // waiting asynchronously, and resetting sync_point before calling this.
904 // However if the parent is a renderer (e.g. browser tag), it may be ok 929 // However if the parent is a renderer (e.g. browser tag), it may be ok
905 // (and is simpler) to wait. 930 // (and is simpler) to wait.
906 if (it->sync_point) 931 if (it->sync_point)
907 GLC(context3d, context3d->waitSyncPoint(it->sync_point)); 932 GLC(context3d, context3d->waitSyncPoint(it->sync_point));
908 GLC(context3d, texture_id = context3d->createTexture()); 933 GLC(context3d, texture_id = context3d->createTexture());
909 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, texture_id)); 934 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, texture_id));
910 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, 935 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D,
911 it->mailbox.name)); 936 it->mailbox.name));
937
912 ResourceId id = next_id_++; 938 ResourceId id = next_id_++;
913 Resource resource( 939 Resource resource(
914 texture_id, it->size, it->format, it->filter, 0, GL_CLAMP_TO_EDGE, 940 texture_id,
915 TextureUsageAny); 941 it->size,
942 it->filter,
943 0,
944 GL_CLAMP_TO_EDGE,
945 TextureUsageAny,
946 it->format);
916 resource.mailbox.SetName(it->mailbox); 947 resource.mailbox.SetName(it->mailbox);
917 // Don't allocate a texture for a child. 948 // Don't allocate a texture for a child.
918 resource.allocated = true; 949 resource.allocated = true;
919 resource.imported_count = 1; 950 resource.imported_count = 1;
920 resources_[id] = resource; 951 resources_[id] = resource;
921 child_info.parent_to_child_map[id] = it->id; 952 child_info.parent_to_child_map[id] = it->id;
922 child_info.child_to_parent_map[it->id] = id; 953 child_info.child_to_parent_map[it->id] = id;
923 } 954 }
924 } 955 }
925 956
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
996 DCHECK(!resource->image_id); 1027 DCHECK(!resource->image_id);
997 1028
998 if (resource->type == GLTexture) { 1029 if (resource->type == GLTexture) {
999 WebGraphicsContext3D* context3d = Context3d(); 1030 WebGraphicsContext3D* context3d = Context3d();
1000 DCHECK(context3d); 1031 DCHECK(context3d);
1001 if (!resource->gl_pixel_buffer_id) 1032 if (!resource->gl_pixel_buffer_id)
1002 resource->gl_pixel_buffer_id = context3d->createBuffer(); 1033 resource->gl_pixel_buffer_id = context3d->createBuffer();
1003 context3d->bindBuffer( 1034 context3d->bindBuffer(
1004 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 1035 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
1005 resource->gl_pixel_buffer_id); 1036 resource->gl_pixel_buffer_id);
1037 size_t bytes_per_pixel = BytesPerPixel(resource->format);
1006 context3d->bufferData( 1038 context3d->bufferData(
1007 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 1039 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
1008 4 * resource->size.GetArea(), 1040 bytes_per_pixel * resource->size.GetArea(),
1009 NULL, 1041 NULL,
1010 GL_DYNAMIC_DRAW); 1042 GL_DYNAMIC_DRAW);
1011 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); 1043 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0);
1012 } 1044 }
1013 1045
1014 if (resource->pixels) { 1046 if (resource->pixels) {
1015 if (resource->pixel_buffer) 1047 if (resource->pixel_buffer)
1016 return; 1048 return;
1017 1049
1018 resource->pixel_buffer = new uint8_t[4 * resource->size.GetArea()]; 1050 resource->pixel_buffer = new uint8_t[4 * resource->size.GetArea()];
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
1169 DCHECK(resource->gl_pixel_buffer_id); 1201 DCHECK(resource->gl_pixel_buffer_id);
1170 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id); 1202 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id);
1171 context3d->bindBuffer( 1203 context3d->bindBuffer(
1172 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 1204 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
1173 resource->gl_pixel_buffer_id); 1205 resource->gl_pixel_buffer_id);
1174 if (!resource->gl_upload_query_id) 1206 if (!resource->gl_upload_query_id)
1175 resource->gl_upload_query_id = context3d->createQueryEXT(); 1207 resource->gl_upload_query_id = context3d->createQueryEXT();
1176 context3d->beginQueryEXT( 1208 context3d->beginQueryEXT(
1177 GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM, 1209 GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM,
1178 resource->gl_upload_query_id); 1210 resource->gl_upload_query_id);
1211 DCHECK(resource->format != RGBA_4444 ||
1212 (resource->size.width() % 2) == 0);
1179 if (allocate) { 1213 if (allocate) {
1180 context3d->asyncTexImage2DCHROMIUM(GL_TEXTURE_2D, 1214 context3d->asyncTexImage2DCHROMIUM(
1181 0, /* level */ 1215 GL_TEXTURE_2D,
1182 resource->format, 1216 0, /* level */
1183 resource->size.width(), 1217 GetGLInternalFormat(resource->format),
1184 resource->size.height(), 1218 resource->size.width(),
1185 0, /* border */ 1219 resource->size.height(),
1186 resource->format, 1220 0, /* border */
1187 GL_UNSIGNED_BYTE, 1221 GetGLDataFormat(resource->format),
1188 NULL); 1222 GetGLDataType(resource->format),
1223 NULL);
1189 } else { 1224 } else {
1190 context3d->asyncTexSubImage2DCHROMIUM(GL_TEXTURE_2D, 1225 context3d->asyncTexSubImage2DCHROMIUM(
1191 0, /* level */ 1226 GL_TEXTURE_2D,
1192 0, /* x */ 1227 0, /* level */
1193 0, /* y */ 1228 0, /* x */
1194 resource->size.width(), 1229 0, /* y */
1195 resource->size.height(), 1230 resource->size.width(),
1196 resource->format, 1231 resource->size.height(),
1197 GL_UNSIGNED_BYTE, 1232 GetGLDataFormat(resource->format),
1198 NULL); 1233 GetGLDataType(resource->format),
1234 NULL);
1199 } 1235 }
1200 context3d->endQueryEXT(GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM); 1236 context3d->endQueryEXT(GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM);
1201 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); 1237 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0);
1202 } 1238 }
1203 1239
1204 if (resource->pixels) { 1240 if (resource->pixels) {
1205 DCHECK(!resource->mailbox.IsValid()); 1241 DCHECK(!resource->mailbox.IsValid());
1206 DCHECK(resource->pixel_buffer); 1242 DCHECK(resource->pixel_buffer);
1207 DCHECK(resource->format == GL_RGBA); 1243 DCHECK_EQ(RGBA_8888, resource->format);
1208 1244
1209 std::swap(resource->pixels, resource->pixel_buffer); 1245 std::swap(resource->pixels, resource->pixel_buffer);
1210 delete[] resource->pixel_buffer; 1246 delete[] resource->pixel_buffer;
1211 resource->pixel_buffer = NULL; 1247 resource->pixel_buffer = NULL;
1212 } 1248 }
1213 1249
1214 resource->pending_set_pixels = true; 1250 resource->pending_set_pixels = true;
1215 resource->set_pixels_completion_forced = false; 1251 resource->set_pixels_completion_forced = false;
1216 } 1252 }
1217 1253
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1303 void ResourceProvider::LazyAllocate(Resource* resource) { 1339 void ResourceProvider::LazyAllocate(Resource* resource) {
1304 DCHECK(resource); 1340 DCHECK(resource);
1305 LazyCreate(resource); 1341 LazyCreate(resource);
1306 1342
1307 DCHECK(resource->gl_id || resource->allocated); 1343 DCHECK(resource->gl_id || resource->allocated);
1308 if (resource->allocated || !resource->gl_id) 1344 if (resource->allocated || !resource->gl_id)
1309 return; 1345 return;
1310 resource->allocated = true; 1346 resource->allocated = true;
1311 WebGraphicsContext3D* context3d = Context3d(); 1347 WebGraphicsContext3D* context3d = Context3d();
1312 gfx::Size& size = resource->size; 1348 gfx::Size& size = resource->size;
1313 GLenum format = resource->format; 1349 ResourceFormat format = resource->format;
1314 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id)); 1350 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id));
1315 if (use_texture_storage_ext_ && IsTextureFormatSupportedForStorage(format)) { 1351 if (use_texture_storage_ext_ && IsFormatSupportedForStorage(format)) {
1316 GLenum storage_format = TextureToStorageFormat(format); 1352 GLenum storage_format = TextureToStorageFormat(format);
1317 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, 1353 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D,
1318 1, 1354 1,
1319 storage_format, 1355 storage_format,
1320 size.width(), 1356 size.width(),
1321 size.height())); 1357 size.height()));
1322 } else { 1358 } else {
1323 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, 1359 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D,
1324 0, 1360 0,
1325 format, 1361 GetGLInternalFormat(format),
1326 size.width(), 1362 size.width(),
1327 size.height(), 1363 size.height(),
1328 0, 1364 0,
1329 format, 1365 GetGLDataFormat(format),
1330 GL_UNSIGNED_BYTE, 1366 GetGLDataType(format),
1331 NULL)); 1367 NULL));
1332 } 1368 }
1333 } 1369 }
1334 1370
1335 void ResourceProvider::EnableReadLockFences(ResourceProvider::ResourceId id, 1371 void ResourceProvider::EnableReadLockFences(ResourceProvider::ResourceId id,
1336 bool enable) { 1372 bool enable) {
1337 Resource* resource = GetResource(id); 1373 Resource* resource = GetResource(id);
1338 resource->enable_read_lock_fences = enable; 1374 resource->enable_read_lock_fences = enable;
1339 } 1375 }
1340 1376
1341 void ResourceProvider::AcquireImage(ResourceId id) { 1377 void ResourceProvider::AcquireImage(ResourceId id) {
1342 Resource* resource = GetResource(id); 1378 Resource* resource = GetResource(id);
1343 DCHECK(!resource->external); 1379 DCHECK(!resource->external);
1344 DCHECK_EQ(resource->exported_count, 0); 1380 DCHECK_EQ(resource->exported_count, 0);
1345 1381
1346 if (resource->type != GLTexture) 1382 if (resource->type != GLTexture)
1347 return; 1383 return;
1348 1384
1349 if (resource->image_id) 1385 if (resource->image_id)
1350 return; 1386 return;
1351 1387
1352 resource->allocated = true; 1388 resource->allocated = true;
1353 WebGraphicsContext3D* context3d = Context3d(); 1389 WebGraphicsContext3D* context3d = Context3d();
1354 DCHECK(context3d); 1390 DCHECK(context3d);
1355 DCHECK_EQ(static_cast<GLenum>(GL_RGBA), resource->format); 1391 DCHECK_EQ(RGBA_8888, resource->format);
1356 resource->image_id = context3d->createImageCHROMIUM( 1392 resource->image_id = context3d->createImageCHROMIUM(
1357 resource->size.width(), resource->size.height(), GL_RGBA8_OES); 1393 resource->size.width(), resource->size.height(), GL_RGBA8_OES);
1358 DCHECK(resource->image_id); 1394 DCHECK(resource->image_id);
1359 } 1395 }
1360 1396
1361 void ResourceProvider::ReleaseImage(ResourceId id) { 1397 void ResourceProvider::ReleaseImage(ResourceId id) {
1362 Resource* resource = GetResource(id); 1398 Resource* resource = GetResource(id);
1363 DCHECK(!resource->external); 1399 DCHECK(!resource->external);
1364 DCHECK_EQ(resource->exported_count, 0); 1400 DCHECK_EQ(resource->exported_count, 0);
1365 1401
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1425 GLint active_unit = 0; 1461 GLint active_unit = 0;
1426 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit); 1462 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit);
1427 return active_unit; 1463 return active_unit;
1428 } 1464 }
1429 1465
1430 WebKit::WebGraphicsContext3D* ResourceProvider::Context3d() const { 1466 WebKit::WebGraphicsContext3D* ResourceProvider::Context3d() const {
1431 ContextProvider* context_provider = output_surface_->context_provider(); 1467 ContextProvider* context_provider = output_surface_->context_provider();
1432 return context_provider ? context_provider->Context3d() : NULL; 1468 return context_provider ? context_provider->Context3d() : NULL;
1433 } 1469 }
1434 1470
1471 size_t ResourceProvider::BytesPerPixel(ResourceFormat format) {
1472 size_t components_per_pixel = 0;
1473 switch (format) {
1474 case RGBA_8888:
1475 case RGBA_4444:
1476 case BGRA_8888:
1477 components_per_pixel = 4;
1478 break;
1479 case LUMINANCE_8:
1480 components_per_pixel = 1;
1481 break;
1482 }
1483 size_t bits_per_component = 0;
1484 switch (format) {
1485 case RGBA_8888:
1486 case BGRA_8888:
1487 case LUMINANCE_8:
1488 bits_per_component = 8;
1489 break;
1490 case RGBA_4444:
1491 bits_per_component = 4;
1492 break;
1493 }
1494 const size_t kBitsPerByte = 8;
1495 return (components_per_pixel * bits_per_component) / kBitsPerByte;
1496 }
1497
1498 GLenum ResourceProvider::GetGLDataType(ResourceFormat format) {
1499 switch (format) {
1500 case RGBA_4444:
1501 return GL_UNSIGNED_SHORT_4_4_4_4;
1502 case RGBA_8888:
1503 case BGRA_8888:
1504 case LUMINANCE_8:
1505 return GL_UNSIGNED_BYTE;
1506 }
1507 NOTREACHED();
1508 return GL_UNSIGNED_BYTE;
1509 }
1510
1511 GLenum ResourceProvider::GetGLDataFormat(ResourceFormat format) {
1512 switch (format) {
1513 case RGBA_8888:
1514 case RGBA_4444:
1515 return GL_RGBA;
1516 case BGRA_8888:
1517 return GL_BGRA_EXT;
1518 case LUMINANCE_8:
1519 return GL_LUMINANCE;
1520 }
1521 NOTREACHED();
1522 return GL_RGBA;
1523 }
1524
1525 GLenum ResourceProvider::GetGLInternalFormat(ResourceFormat format) {
1526 return GetGLDataFormat(format);
1527 }
1528
1435 } // namespace cc 1529 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698