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

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 reviews 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
« no previous file with comments | « cc/resources/resource_provider.h ('k') | cc/resources/resource_provider_unittest.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"
(...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(cc::ResourceProvider::Format 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 cc::ResourceProvider::RGBA_8888:
41 case cc::ResourceProvider::RGBA_4444:
42 case cc::ResourceProvider::LUMINANCE_8:
41 break; 43 break;
42 case GL_BGRA_EXT: 44 case cc::ResourceProvider::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(cc::ResourceProvider::Format format) {
54 return (format == GL_RGBA || format == GL_BGRA_EXT); 53 switch (format) {
54 case cc::ResourceProvider::RGBA_8888:
55 case cc::ResourceProvider::BGRA_8888:
56 return true;
57 case cc::ResourceProvider::RGBA_4444:
58 case cc::ResourceProvider::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 Format 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) {
183 scoped_ptr<ResourceProvider> resource_provider( 189 scoped_ptr<ResourceProvider> resource_provider(
184 new ResourceProvider(output_surface, highp_threshold_min)); 190 new ResourceProvider(output_surface,
191 highp_threshold_min));
reveman 2013/09/13 20:24:31 nit: looks like this fits on one line
kaanb 2013/09/13 22:35:23 Done.
185 192
186 bool success = false; 193 bool success = false;
187 if (resource_provider->Context3d()) { 194 if (resource_provider->Context3d()) {
188 success = resource_provider->InitializeGL(); 195 success = resource_provider->InitializeGL();
189 } else { 196 } else {
190 resource_provider->InitializeSoftware(); 197 resource_provider->InitializeSoftware();
191 success = true; 198 success = true;
192 } 199 }
193 200
194 if (!success) 201 if (!success)
195 return scoped_ptr<ResourceProvider>(); 202 return scoped_ptr<ResourceProvider>();
196 203
197 DCHECK_NE(InvalidType, resource_provider->default_resource_type()); 204 DCHECK_NE(InvalidType, resource_provider->default_resource_type());
198 return resource_provider.Pass(); 205 return resource_provider.Pass();
199 } 206 }
200 207
201 ResourceProvider::~ResourceProvider() { 208 ResourceProvider::~ResourceProvider() {
202 while (!resources_.empty()) 209 while (!resources_.empty())
203 DeleteResourceInternal(resources_.begin(), ForShutdown); 210 DeleteResourceInternal(resources_.begin(), ForShutdown);
204 211
205 CleanUpGLIfNeeded(); 212 CleanUpGLIfNeeded();
206 } 213 }
207 214
208 bool ResourceProvider::InUseByConsumer(ResourceId id) { 215 bool ResourceProvider::InUseByConsumer(ResourceId id) {
209 Resource* resource = GetResource(id); 216 Resource* resource = GetResource(id);
210 return resource->lock_for_read_count > 0 || resource->exported_count > 0; 217 return resource->lock_for_read_count > 0 || resource->exported_count > 0;
211 } 218 }
212 219
213 ResourceProvider::ResourceId ResourceProvider::CreateResource( 220 ResourceProvider::ResourceId ResourceProvider::CreateResource(
214 gfx::Size size, GLenum format, GLint wrap_mode, TextureUsageHint hint) { 221 gfx::Size size,
222 GLint wrap_mode,
223 TextureUsageHint hint,
224 Format format) {
215 DCHECK(!size.IsEmpty()); 225 DCHECK(!size.IsEmpty());
216 switch (default_resource_type_) { 226 switch (default_resource_type_) {
217 case GLTexture: 227 case GLTexture:
218 return CreateGLTexture(size, format, GL_TEXTURE_POOL_UNMANAGED_CHROMIUM, 228 return CreateGLTexture(size,
219 wrap_mode, hint); 229 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM,
230 wrap_mode,
231 hint,
232 format);
220 case Bitmap: 233 case Bitmap:
221 // The only wrap_mode currently implemented in software mode is 234 DCHECK_EQ(RGBA_8888, format);
222 // GL_CLAMP_TO_EDGE.
223 // http://crbug.com/284796
224 DCHECK(format == GL_RGBA);
225 return CreateBitmap(size); 235 return CreateBitmap(size);
226 case InvalidType: 236 case InvalidType:
227 break; 237 break;
228 } 238 }
229 239
230 LOG(FATAL) << "Invalid default resource type."; 240 LOG(FATAL) << "Invalid default resource type.";
231 return 0; 241 return 0;
232 } 242 }
233 243
234 ResourceProvider::ResourceId ResourceProvider::CreateManagedResource( 244 ResourceProvider::ResourceId ResourceProvider::CreateManagedResource(
235 gfx::Size size, GLenum format, GLint wrap_mode, TextureUsageHint hint) { 245 gfx::Size size,
246 GLint wrap_mode,
247 TextureUsageHint hint,
248 Format format) {
236 DCHECK(!size.IsEmpty()); 249 DCHECK(!size.IsEmpty());
237 switch (default_resource_type_) { 250 switch (default_resource_type_) {
238 case GLTexture: 251 case GLTexture:
239 return CreateGLTexture(size, format, GL_TEXTURE_POOL_MANAGED_CHROMIUM, 252 return CreateGLTexture(size,
240 wrap_mode, hint); 253 GL_TEXTURE_POOL_MANAGED_CHROMIUM,
254 wrap_mode,
255 hint,
256 format);
241 case Bitmap: 257 case Bitmap:
242 DCHECK(format == GL_RGBA); 258 DCHECK_EQ(RGBA_8888, format);
243 return CreateBitmap(size); 259 return CreateBitmap(size);
244 case InvalidType: 260 case InvalidType:
245 break; 261 break;
246 } 262 }
247 263
248 LOG(FATAL) << "Invalid default resource type."; 264 LOG(FATAL) << "Invalid default resource type.";
249 return 0; 265 return 0;
250 } 266 }
251 267
252 ResourceProvider::ResourceId ResourceProvider::CreateGLTexture( 268 ResourceProvider::ResourceId ResourceProvider::CreateGLTexture(
253 gfx::Size size, 269 gfx::Size size,
254 GLenum format,
255 GLenum texture_pool, 270 GLenum texture_pool,
256 GLint wrap_mode, 271 GLint wrap_mode,
257 TextureUsageHint hint) { 272 TextureUsageHint hint,
273 Format format) {
258 DCHECK_LE(size.width(), max_texture_size_); 274 DCHECK_LE(size.width(), max_texture_size_);
259 DCHECK_LE(size.height(), max_texture_size_); 275 DCHECK_LE(size.height(), max_texture_size_);
260 DCHECK(thread_checker_.CalledOnValidThread()); 276 DCHECK(thread_checker_.CalledOnValidThread());
261 277
262 ResourceId id = next_id_++; 278 ResourceId id = next_id_++;
263 Resource resource(0, size, format, GL_LINEAR, texture_pool, wrap_mode, hint); 279 Resource resource(0, size, GL_LINEAR, texture_pool, wrap_mode, hint, format);
264 resource.allocated = false; 280 resource.allocated = false;
265 resources_[id] = resource; 281 resources_[id] = resource;
266 return id; 282 return id;
267 } 283 }
268 284
269 ResourceProvider::ResourceId ResourceProvider::CreateBitmap(gfx::Size size) { 285 ResourceProvider::ResourceId ResourceProvider::CreateBitmap(gfx::Size size) {
270 DCHECK(thread_checker_.CalledOnValidThread()); 286 DCHECK(thread_checker_.CalledOnValidThread());
271 287
272 uint8_t* pixels = new uint8_t[4 * size.GetArea()]; 288 uint8_t* pixels = new uint8_t[4 * size.GetArea()];
273 289
274 ResourceId id = next_id_++; 290 ResourceId id = next_id_++;
275 Resource resource(pixels, size, GL_RGBA, GL_LINEAR, GL_CLAMP_TO_EDGE); 291 Resource resource(pixels, size, GL_LINEAR, GL_CLAMP_TO_EDGE);
276 resource.allocated = true; 292 resource.allocated = true;
277 resources_[id] = resource; 293 resources_[id] = resource;
278 return id; 294 return id;
279 } 295 }
280 296
281 ResourceProvider::ResourceId 297 ResourceProvider::ResourceId
282 ResourceProvider::CreateResourceFromExternalTexture( 298 ResourceProvider::CreateResourceFromExternalTexture(
283 unsigned texture_target, 299 unsigned texture_target,
284 unsigned texture_id) { 300 unsigned texture_id) {
285 DCHECK(thread_checker_.CalledOnValidThread()); 301 DCHECK(thread_checker_.CalledOnValidThread());
286 302
287 WebGraphicsContext3D* context3d = Context3d(); 303 WebGraphicsContext3D* context3d = Context3d();
288 DCHECK(context3d); 304 DCHECK(context3d);
289 GLC(context3d, context3d->bindTexture(texture_target, texture_id)); 305 GLC(context3d, context3d->bindTexture(texture_target, texture_id));
290 GLC(context3d, context3d->texParameteri( 306 GLC(context3d, context3d->texParameteri(
291 texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); 307 texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
292 GLC(context3d, context3d->texParameteri( 308 GLC(context3d, context3d->texParameteri(
293 texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); 309 texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
294 GLC(context3d, context3d->texParameteri( 310 GLC(context3d, context3d->texParameteri(
295 texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); 311 texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
296 GLC(context3d, context3d->texParameteri( 312 GLC(context3d, context3d->texParameteri(
297 texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); 313 texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
298 314
299 ResourceId id = next_id_++; 315 ResourceId id = next_id_++;
300 Resource resource(texture_id, gfx::Size(), 0, GL_LINEAR, 0, GL_CLAMP_TO_EDGE, 316 Resource resource(texture_id,
301 TextureUsageAny); 317 gfx::Size(),
318 GL_LINEAR,
319 0,
320 GL_CLAMP_TO_EDGE,
321 TextureUsageAny,
322 RGBA_8888);
302 resource.external = true; 323 resource.external = true;
303 resource.allocated = true; 324 resource.allocated = true;
304 resources_[id] = resource; 325 resources_[id] = resource;
305 return id; 326 return id;
306 } 327 }
307 328
308 ResourceProvider::ResourceId ResourceProvider::CreateResourceFromTextureMailbox( 329 ResourceProvider::ResourceId ResourceProvider::CreateResourceFromTextureMailbox(
309 const TextureMailbox& mailbox) { 330 const TextureMailbox& mailbox) {
310 DCHECK(thread_checker_.CalledOnValidThread()); 331 DCHECK(thread_checker_.CalledOnValidThread());
311 // Just store the information. Mailbox will be consumed in LockForRead(). 332 // Just store the information. Mailbox will be consumed in LockForRead().
312 ResourceId id = next_id_++; 333 ResourceId id = next_id_++;
313 DCHECK(mailbox.IsValid()); 334 DCHECK(mailbox.IsValid());
314 Resource& resource = resources_[id]; 335 Resource& resource = resources_[id];
315 if (mailbox.IsTexture()) { 336 if (mailbox.IsTexture()) {
316 resource = Resource(0, gfx::Size(), 0, GL_LINEAR, 0, GL_CLAMP_TO_EDGE, 337 resource = Resource(0,
317 TextureUsageAny); 338 gfx::Size(),
339 GL_LINEAR,
340 0,
341 GL_CLAMP_TO_EDGE,
342 TextureUsageAny,
343 RGBA_8888);
318 } else { 344 } else {
319 DCHECK(mailbox.IsSharedMemory()); 345 DCHECK(mailbox.IsSharedMemory());
320 base::SharedMemory* shared_memory = mailbox.shared_memory(); 346 base::SharedMemory* shared_memory = mailbox.shared_memory();
321 DCHECK(shared_memory->memory()); 347 DCHECK(shared_memory->memory());
322 uint8_t* pixels = reinterpret_cast<uint8_t*>(shared_memory->memory()); 348 uint8_t* pixels = reinterpret_cast<uint8_t*>(shared_memory->memory());
323 resource = Resource(pixels, mailbox.shared_memory_size(), 349 resource = Resource(
324 GL_RGBA, GL_LINEAR, GL_CLAMP_TO_EDGE); 350 pixels, mailbox.shared_memory_size(), GL_LINEAR, GL_CLAMP_TO_EDGE);
325 } 351 }
326 resource.external = true; 352 resource.external = true;
327 resource.allocated = true; 353 resource.allocated = true;
328 resource.mailbox = mailbox; 354 resource.mailbox = mailbox;
329 return id; 355 return id;
330 } 356 }
331 357
332 void ResourceProvider::DeleteResource(ResourceId id) { 358 void ResourceProvider::DeleteResource(ResourceId id) {
333 DCHECK(thread_checker_.CalledOnValidThread()); 359 DCHECK(thread_checker_.CalledOnValidThread());
334 ResourceMap::iterator it = resources_.find(id); 360 ResourceMap::iterator it = resources_.find(id);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 texture_uploader_->Upload(image, 457 texture_uploader_->Upload(image,
432 image_rect, 458 image_rect,
433 source_rect, 459 source_rect,
434 dest_offset, 460 dest_offset,
435 resource->format, 461 resource->format,
436 resource->size); 462 resource->size);
437 } 463 }
438 464
439 if (resource->pixels) { 465 if (resource->pixels) {
440 DCHECK(resource->allocated); 466 DCHECK(resource->allocated);
441 DCHECK(resource->format == GL_RGBA); 467 DCHECK_EQ(RGBA_8888, resource->format);
442 SkBitmap src_full; 468 SkBitmap src_full;
443 src_full.setConfig( 469 src_full.setConfig(
444 SkBitmap::kARGB_8888_Config, image_rect.width(), image_rect.height()); 470 SkBitmap::kARGB_8888_Config, image_rect.width(), image_rect.height());
445 src_full.setPixels(const_cast<uint8_t*>(image)); 471 src_full.setPixels(const_cast<uint8_t*>(image));
446 SkBitmap src_subset; 472 SkBitmap src_subset;
447 SkIRect sk_source_rect = SkIRect::MakeXYWH(source_rect.x(), 473 SkIRect sk_source_rect = SkIRect::MakeXYWH(source_rect.x(),
448 source_rect.y(), 474 source_rect.y(),
449 source_rect.width(), 475 source_rect.width(),
450 source_rect.height()); 476 source_rect.height());
451 sk_source_rect.offset(-image_rect.x(), -image_rect.y()); 477 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_); 681 DCHECK(texture_id_);
656 } 682 }
657 683
658 ResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() { 684 ResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() {
659 resource_provider_->UnlockForWrite(resource_id_); 685 resource_provider_->UnlockForWrite(resource_id_);
660 } 686 }
661 687
662 void ResourceProvider::PopulateSkBitmapWithResource( 688 void ResourceProvider::PopulateSkBitmapWithResource(
663 SkBitmap* sk_bitmap, const Resource* resource) { 689 SkBitmap* sk_bitmap, const Resource* resource) {
664 DCHECK(resource->pixels); 690 DCHECK(resource->pixels);
665 DCHECK(resource->format == GL_RGBA); 691 DCHECK_EQ(RGBA_8888, resource->format);
666 sk_bitmap->setConfig(SkBitmap::kARGB_8888_Config, 692 sk_bitmap->setConfig(SkBitmap::kARGB_8888_Config,
667 resource->size.width(), 693 resource->size.width(),
668 resource->size.height()); 694 resource->size.height());
669 sk_bitmap->setPixels(resource->pixels); 695 sk_bitmap->setPixels(resource->pixels);
670 } 696 }
671 697
672 ResourceProvider::ScopedReadLockSoftware::ScopedReadLockSoftware( 698 ResourceProvider::ScopedReadLockSoftware::ScopedReadLockSoftware(
673 ResourceProvider* resource_provider, 699 ResourceProvider* resource_provider,
674 ResourceProvider::ResourceId resource_id) 700 ResourceProvider::ResourceId resource_id)
675 : resource_provider_(resource_provider), 701 : resource_provider_(resource_provider),
(...skipping 25 matching lines...) Expand all
701 : output_surface_(output_surface), 727 : output_surface_(output_surface),
702 lost_output_surface_(false), 728 lost_output_surface_(false),
703 highp_threshold_min_(highp_threshold_min), 729 highp_threshold_min_(highp_threshold_min),
704 next_id_(1), 730 next_id_(1),
705 next_child_(1), 731 next_child_(1),
706 default_resource_type_(InvalidType), 732 default_resource_type_(InvalidType),
707 use_texture_storage_ext_(false), 733 use_texture_storage_ext_(false),
708 use_texture_usage_hint_(false), 734 use_texture_usage_hint_(false),
709 use_shallow_flush_(false), 735 use_shallow_flush_(false),
710 max_texture_size_(0), 736 max_texture_size_(0),
711 best_texture_format_(0) { 737 best_texture_format_(RGBA_8888) {
712 DCHECK(output_surface_->HasClient()); 738 DCHECK(output_surface_->HasClient());
713 } 739 }
714 740
715 void ResourceProvider::InitializeSoftware() { 741 void ResourceProvider::InitializeSoftware() {
716 DCHECK(thread_checker_.CalledOnValidThread()); 742 DCHECK(thread_checker_.CalledOnValidThread());
717 DCHECK_NE(Bitmap, default_resource_type_); 743 DCHECK_NE(Bitmap, default_resource_type_);
718 744
719 CleanUpGLIfNeeded(); 745 CleanUpGLIfNeeded();
720 746
721 default_resource_type_ = Bitmap; 747 default_resource_type_ = Bitmap;
722 max_texture_size_ = INT_MAX / 2; 748 max_texture_size_ = INT_MAX / 2;
723 best_texture_format_ = GL_RGBA; 749 best_texture_format_ = RGBA_8888;
724 } 750 }
725 751
726 bool ResourceProvider::InitializeGL() { 752 bool ResourceProvider::InitializeGL() {
727 DCHECK(thread_checker_.CalledOnValidThread()); 753 DCHECK(thread_checker_.CalledOnValidThread());
728 DCHECK(!texture_uploader_); 754 DCHECK(!texture_uploader_);
729 DCHECK_NE(GLTexture, default_resource_type_); 755 DCHECK_NE(GLTexture, default_resource_type_);
730 756
731 WebGraphicsContext3D* context3d = Context3d(); 757 WebGraphicsContext3D* context3d = Context3d();
732 DCHECK(context3d); 758 DCHECK(context3d);
733 759
734 if (!context3d->makeContextCurrent()) 760 if (!context3d->makeContextCurrent())
735 return false; 761 return false;
736 762
737 default_resource_type_ = GLTexture; 763 default_resource_type_ = GLTexture;
738 764
739 const ContextProvider::Capabilities& caps = 765 const ContextProvider::Capabilities& caps =
740 output_surface_->context_provider()->ContextCapabilities(); 766 output_surface_->context_provider()->ContextCapabilities();
741 767
742 bool use_map_sub = caps.map_sub; 768 bool use_map_sub = caps.map_sub;
743 bool use_bgra = caps.texture_format_bgra8888; 769 bool use_bgra = caps.texture_format_bgra8888;
744 use_texture_storage_ext_ = caps.texture_storage; 770 use_texture_storage_ext_ = caps.texture_storage;
745 use_shallow_flush_ = caps.shallow_flush; 771 use_shallow_flush_ = caps.shallow_flush;
746 use_texture_usage_hint_ = caps.texture_usage; 772 use_texture_usage_hint_ = caps.texture_usage;
747 773
748 texture_uploader_ = 774 texture_uploader_ =
749 TextureUploader::Create(context3d, use_map_sub, use_shallow_flush_); 775 TextureUploader::Create(context3d,
776 use_map_sub,
777 use_shallow_flush_);
750 GLC(context3d, context3d->getIntegerv(GL_MAX_TEXTURE_SIZE, 778 GLC(context3d, context3d->getIntegerv(GL_MAX_TEXTURE_SIZE,
751 &max_texture_size_)); 779 &max_texture_size_));
752 best_texture_format_ = PlatformColor::BestTextureFormat(use_bgra); 780 best_texture_format_ = PlatformColor::BestTextureFormat(use_bgra);
753 781
754 return true; 782 return true;
755 } 783 }
756 784
757 void ResourceProvider::CleanUpGLIfNeeded() { 785 void ResourceProvider::CleanUpGLIfNeeded() {
758 WebGraphicsContext3D* context3d = Context3d(); 786 WebGraphicsContext3D* context3d = Context3d();
759 if (default_resource_type_ != GLTexture) { 787 if (default_resource_type_ != GLTexture) {
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
902 // deadlocks and/or security issues. The caller is responsible for 930 // deadlocks and/or security issues. The caller is responsible for
903 // waiting asynchronously, and resetting sync_point before calling this. 931 // 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 932 // However if the parent is a renderer (e.g. browser tag), it may be ok
905 // (and is simpler) to wait. 933 // (and is simpler) to wait.
906 if (it->sync_point) 934 if (it->sync_point)
907 GLC(context3d, context3d->waitSyncPoint(it->sync_point)); 935 GLC(context3d, context3d->waitSyncPoint(it->sync_point));
908 GLC(context3d, texture_id = context3d->createTexture()); 936 GLC(context3d, texture_id = context3d->createTexture());
909 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, texture_id)); 937 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, texture_id));
910 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, 938 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D,
911 it->mailbox.name)); 939 it->mailbox.name));
940 // TODO(kaanb): change TransferableResource to use the Format enum.
941 Format format = RGBA_8888;
942 switch (it->format) {
943 case RGBA_8888:
944 case RGBA_4444:
945 case BGRA_8888:
946 case LUMINANCE_8:
947 format = static_cast<Format>(it->format);
948 break;
949 default:
950 NOTREACHED();
reveman 2013/09/13 20:24:31 As piman already pointed out, we can't use NOTREAC
kaanb 2013/09/13 22:35:23 We don't need the switch statement anymore as Tran
951 }
952
912 ResourceId id = next_id_++; 953 ResourceId id = next_id_++;
913 Resource resource( 954 Resource resource(
914 texture_id, it->size, it->format, it->filter, 0, GL_CLAMP_TO_EDGE, 955 texture_id,
915 TextureUsageAny); 956 it->size,
957 it->filter,
958 0,
959 GL_CLAMP_TO_EDGE,
960 TextureUsageAny,
961 format);
916 resource.mailbox.SetName(it->mailbox); 962 resource.mailbox.SetName(it->mailbox);
917 // Don't allocate a texture for a child. 963 // Don't allocate a texture for a child.
918 resource.allocated = true; 964 resource.allocated = true;
919 resource.imported_count = 1; 965 resource.imported_count = 1;
920 resources_[id] = resource; 966 resources_[id] = resource;
921 child_info.parent_to_child_map[id] = it->id; 967 child_info.parent_to_child_map[id] = it->id;
922 child_info.child_to_parent_map[it->id] = id; 968 child_info.child_to_parent_map[it->id] = id;
923 } 969 }
924 } 970 }
925 971
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
957 1003
958 void ResourceProvider::TransferResource(WebGraphicsContext3D* context, 1004 void ResourceProvider::TransferResource(WebGraphicsContext3D* context,
959 ResourceId id, 1005 ResourceId id,
960 TransferableResource* resource) { 1006 TransferableResource* resource) {
961 Resource* source = GetResource(id); 1007 Resource* source = GetResource(id);
962 DCHECK(!source->locked_for_write); 1008 DCHECK(!source->locked_for_write);
963 DCHECK(!source->lock_for_read_count); 1009 DCHECK(!source->lock_for_read_count);
964 DCHECK(!source->external || (source->external && source->mailbox.IsValid())); 1010 DCHECK(!source->external || (source->external && source->mailbox.IsValid()));
965 DCHECK(source->allocated); 1011 DCHECK(source->allocated);
966 resource->id = id; 1012 resource->id = id;
967 resource->format = source->format;
968 resource->filter = source->filter; 1013 resource->filter = source->filter;
969 resource->size = source->size; 1014 resource->size = source->size;
1015 resource->format = source->format;
970 1016
971 // TODO(skaslev) Implement this path for shared memory resources. 1017 // TODO(skaslev) Implement this path for shared memory resources.
972 DCHECK(!source->mailbox.IsSharedMemory()); 1018 DCHECK(!source->mailbox.IsSharedMemory());
973 1019
974 if (!source->mailbox.IsTexture()) { 1020 if (!source->mailbox.IsTexture()) {
975 // This is a resource allocated by the compositor, we need to produce it. 1021 // This is a resource allocated by the compositor, we need to produce it.
976 // Don't set a sync point, the caller will do it. 1022 // Don't set a sync point, the caller will do it.
977 DCHECK(source->gl_id); 1023 DCHECK(source->gl_id);
978 GLC(context, context->bindTexture(GL_TEXTURE_2D, source->gl_id)); 1024 GLC(context, context->bindTexture(GL_TEXTURE_2D, source->gl_id));
979 GLC(context, context->genMailboxCHROMIUM(resource->mailbox.name)); 1025 GLC(context, context->genMailboxCHROMIUM(resource->mailbox.name));
(...skipping 16 matching lines...) Expand all
996 DCHECK(!resource->image_id); 1042 DCHECK(!resource->image_id);
997 1043
998 if (resource->type == GLTexture) { 1044 if (resource->type == GLTexture) {
999 WebGraphicsContext3D* context3d = Context3d(); 1045 WebGraphicsContext3D* context3d = Context3d();
1000 DCHECK(context3d); 1046 DCHECK(context3d);
1001 if (!resource->gl_pixel_buffer_id) 1047 if (!resource->gl_pixel_buffer_id)
1002 resource->gl_pixel_buffer_id = context3d->createBuffer(); 1048 resource->gl_pixel_buffer_id = context3d->createBuffer();
1003 context3d->bindBuffer( 1049 context3d->bindBuffer(
1004 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 1050 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
1005 resource->gl_pixel_buffer_id); 1051 resource->gl_pixel_buffer_id);
1052 size_t bytes_per_pixel = BytesPerPixel(resource->format);
1006 context3d->bufferData( 1053 context3d->bufferData(
1007 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 1054 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
1008 4 * resource->size.GetArea(), 1055 bytes_per_pixel * resource->size.GetArea(),
1009 NULL, 1056 NULL,
1010 GL_DYNAMIC_DRAW); 1057 GL_DYNAMIC_DRAW);
1011 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); 1058 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0);
1012 } 1059 }
1013 1060
1014 if (resource->pixels) { 1061 if (resource->pixels) {
1015 if (resource->pixel_buffer) 1062 if (resource->pixel_buffer)
1016 return; 1063 return;
1017 1064
1018 resource->pixel_buffer = new uint8_t[4 * resource->size.GetArea()]; 1065 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); 1216 DCHECK(resource->gl_pixel_buffer_id);
1170 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id); 1217 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id);
1171 context3d->bindBuffer( 1218 context3d->bindBuffer(
1172 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 1219 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
1173 resource->gl_pixel_buffer_id); 1220 resource->gl_pixel_buffer_id);
1174 if (!resource->gl_upload_query_id) 1221 if (!resource->gl_upload_query_id)
1175 resource->gl_upload_query_id = context3d->createQueryEXT(); 1222 resource->gl_upload_query_id = context3d->createQueryEXT();
1176 context3d->beginQueryEXT( 1223 context3d->beginQueryEXT(
1177 GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM, 1224 GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM,
1178 resource->gl_upload_query_id); 1225 resource->gl_upload_query_id);
1226 DCHECK(resource->format != RGBA_4444 ||
reveman 2013/09/13 20:24:31 Can we avoid this format specific check? Shouldn't
kaanb 2013/09/13 22:35:23 There are unittests that upload 13x13 textures in
1227 (resource->size.width() % 2) == 0);
1179 if (allocate) { 1228 if (allocate) {
1180 context3d->asyncTexImage2DCHROMIUM(GL_TEXTURE_2D, 1229 context3d->asyncTexImage2DCHROMIUM(
1181 0, /* level */ 1230 GL_TEXTURE_2D,
1182 resource->format, 1231 0, /* level */
1183 resource->size.width(), 1232 GetGLInternalFormat(resource->format),
1184 resource->size.height(), 1233 resource->size.width(),
1185 0, /* border */ 1234 resource->size.height(),
1186 resource->format, 1235 0, /* border */
1187 GL_UNSIGNED_BYTE, 1236 GetGLDataFormat(resource->format),
1188 NULL); 1237 GetGLDataType(resource->format),
1238 NULL);
1189 } else { 1239 } else {
1190 context3d->asyncTexSubImage2DCHROMIUM(GL_TEXTURE_2D, 1240 context3d->asyncTexSubImage2DCHROMIUM(
1191 0, /* level */ 1241 GL_TEXTURE_2D,
1192 0, /* x */ 1242 0, /* level */
1193 0, /* y */ 1243 0, /* x */
1194 resource->size.width(), 1244 0, /* y */
1195 resource->size.height(), 1245 resource->size.width(),
1196 resource->format, 1246 resource->size.height(),
1197 GL_UNSIGNED_BYTE, 1247 GetGLDataFormat(resource->format),
1198 NULL); 1248 GetGLDataType(resource->format),
1249 NULL);
1199 } 1250 }
1200 context3d->endQueryEXT(GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM); 1251 context3d->endQueryEXT(GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM);
1201 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); 1252 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0);
1202 } 1253 }
1203 1254
1204 if (resource->pixels) { 1255 if (resource->pixels) {
1205 DCHECK(!resource->mailbox.IsValid()); 1256 DCHECK(!resource->mailbox.IsValid());
1206 DCHECK(resource->pixel_buffer); 1257 DCHECK(resource->pixel_buffer);
1207 DCHECK(resource->format == GL_RGBA); 1258 DCHECK_EQ(RGBA_8888, resource->format);
1208 1259
1209 std::swap(resource->pixels, resource->pixel_buffer); 1260 std::swap(resource->pixels, resource->pixel_buffer);
1210 delete[] resource->pixel_buffer; 1261 delete[] resource->pixel_buffer;
1211 resource->pixel_buffer = NULL; 1262 resource->pixel_buffer = NULL;
1212 } 1263 }
1213 1264
1214 resource->pending_set_pixels = true; 1265 resource->pending_set_pixels = true;
1215 resource->set_pixels_completion_forced = false; 1266 resource->set_pixels_completion_forced = false;
1216 } 1267 }
1217 1268
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1303 void ResourceProvider::LazyAllocate(Resource* resource) { 1354 void ResourceProvider::LazyAllocate(Resource* resource) {
1304 DCHECK(resource); 1355 DCHECK(resource);
1305 LazyCreate(resource); 1356 LazyCreate(resource);
1306 1357
1307 DCHECK(resource->gl_id || resource->allocated); 1358 DCHECK(resource->gl_id || resource->allocated);
1308 if (resource->allocated || !resource->gl_id) 1359 if (resource->allocated || !resource->gl_id)
1309 return; 1360 return;
1310 resource->allocated = true; 1361 resource->allocated = true;
1311 WebGraphicsContext3D* context3d = Context3d(); 1362 WebGraphicsContext3D* context3d = Context3d();
1312 gfx::Size& size = resource->size; 1363 gfx::Size& size = resource->size;
1313 GLenum format = resource->format; 1364 Format format = resource->format;
1314 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id)); 1365 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id));
1315 if (use_texture_storage_ext_ && IsTextureFormatSupportedForStorage(format)) { 1366 if (use_texture_storage_ext_ && IsFormatSupportedForStorage(format)) {
1316 GLenum storage_format = TextureToStorageFormat(format); 1367 GLenum storage_format = TextureToStorageFormat(format);
1317 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, 1368 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D,
1318 1, 1369 1,
1319 storage_format, 1370 storage_format,
1320 size.width(), 1371 size.width(),
1321 size.height())); 1372 size.height()));
1322 } else { 1373 } else {
1323 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, 1374 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D,
1324 0, 1375 0,
1325 format, 1376 GetGLInternalFormat(format),
1326 size.width(), 1377 size.width(),
1327 size.height(), 1378 size.height(),
1328 0, 1379 0,
1329 format, 1380 GetGLDataFormat(format),
1330 GL_UNSIGNED_BYTE, 1381 GetGLDataType(format),
1331 NULL)); 1382 NULL));
1332 } 1383 }
1333 } 1384 }
1334 1385
1335 void ResourceProvider::EnableReadLockFences(ResourceProvider::ResourceId id, 1386 void ResourceProvider::EnableReadLockFences(ResourceProvider::ResourceId id,
1336 bool enable) { 1387 bool enable) {
1337 Resource* resource = GetResource(id); 1388 Resource* resource = GetResource(id);
1338 resource->enable_read_lock_fences = enable; 1389 resource->enable_read_lock_fences = enable;
1339 } 1390 }
1340 1391
1341 void ResourceProvider::AcquireImage(ResourceId id) { 1392 void ResourceProvider::AcquireImage(ResourceId id) {
1342 Resource* resource = GetResource(id); 1393 Resource* resource = GetResource(id);
1343 DCHECK(!resource->external); 1394 DCHECK(!resource->external);
1344 DCHECK_EQ(resource->exported_count, 0); 1395 DCHECK_EQ(resource->exported_count, 0);
1345 1396
1346 if (resource->type != GLTexture) 1397 if (resource->type != GLTexture)
1347 return; 1398 return;
1348 1399
1349 if (resource->image_id) 1400 if (resource->image_id)
1350 return; 1401 return;
1351 1402
1352 resource->allocated = true; 1403 resource->allocated = true;
1353 WebGraphicsContext3D* context3d = Context3d(); 1404 WebGraphicsContext3D* context3d = Context3d();
1354 DCHECK(context3d); 1405 DCHECK(context3d);
1355 DCHECK_EQ(static_cast<GLenum>(GL_RGBA), resource->format); 1406 DCHECK_EQ(RGBA_8888, resource->format);
1356 resource->image_id = context3d->createImageCHROMIUM( 1407 resource->image_id = context3d->createImageCHROMIUM(
1357 resource->size.width(), resource->size.height(), GL_RGBA8_OES); 1408 resource->size.width(), resource->size.height(), GL_RGBA8_OES);
1358 DCHECK(resource->image_id); 1409 DCHECK(resource->image_id);
1359 } 1410 }
1360 1411
1361 void ResourceProvider::ReleaseImage(ResourceId id) { 1412 void ResourceProvider::ReleaseImage(ResourceId id) {
1362 Resource* resource = GetResource(id); 1413 Resource* resource = GetResource(id);
1363 DCHECK(!resource->external); 1414 DCHECK(!resource->external);
1364 DCHECK_EQ(resource->exported_count, 0); 1415 DCHECK_EQ(resource->exported_count, 0);
1365 1416
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1425 GLint active_unit = 0; 1476 GLint active_unit = 0;
1426 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit); 1477 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit);
1427 return active_unit; 1478 return active_unit;
1428 } 1479 }
1429 1480
1430 WebKit::WebGraphicsContext3D* ResourceProvider::Context3d() const { 1481 WebKit::WebGraphicsContext3D* ResourceProvider::Context3d() const {
1431 ContextProvider* context_provider = output_surface_->context_provider(); 1482 ContextProvider* context_provider = output_surface_->context_provider();
1432 return context_provider ? context_provider->Context3d() : NULL; 1483 return context_provider ? context_provider->Context3d() : NULL;
1433 } 1484 }
1434 1485
1486 size_t ResourceProvider::BytesPerPixel(Format format) {
1487 size_t components_per_pixel = 0;
1488 switch (format) {
1489 case RGBA_8888:
1490 case RGBA_4444:
1491 case BGRA_8888:
1492 components_per_pixel = 4;
1493 break;
1494 case LUMINANCE_8:
1495 components_per_pixel = 1;
1496 break;
1497 }
1498 size_t bits_per_component = 0;
1499 switch (format) {
1500 case RGBA_8888:
1501 case BGRA_8888:
1502 case LUMINANCE_8:
1503 bits_per_component = 8;
1504 break;
1505 case RGBA_4444:
1506 bits_per_component = 4;
1507 break;
1508 }
1509 const size_t kBitsPerByte = 8;
1510 return (components_per_pixel * bits_per_component) / kBitsPerByte;
1511 }
1512
1513 GLenum ResourceProvider::GetGLDataType(Format format) {
1514 switch (format) {
1515 case RGBA_4444:
1516 return GL_UNSIGNED_SHORT_4_4_4_4;
1517 case RGBA_8888:
1518 case BGRA_8888:
1519 case LUMINANCE_8:
1520 return GL_UNSIGNED_BYTE;
1521 }
1522 return GL_UNSIGNED_BYTE;
reveman 2013/09/13 20:24:31 I think you can add a NOTREACHED() above this line
kaanb 2013/09/13 22:35:23 Done.
1523 }
1524
1525 GLenum ResourceProvider::GetGLDataFormat(Format format) {
1526 switch (format) {
1527 case RGBA_8888:
1528 case RGBA_4444:
1529 return GL_RGBA;
1530 case BGRA_8888:
1531 return GL_BGRA_EXT;
1532 case LUMINANCE_8:
1533 return GL_LUMINANCE;
1534 }
1535 return GL_RGBA;
reveman 2013/09/13 20:24:31 and NOTREACHED() here too.
kaanb 2013/09/13 22:35:23 Done.
1536 }
1537
1538 GLenum ResourceProvider::GetGLInternalFormat(Format format) {
1539 return GetGLDataFormat(format);
1540 }
1541
1435 } // namespace cc 1542 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/resource_provider.h ('k') | cc/resources/resource_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698