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

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, fix unittests, add a flag to disable the feature 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(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(
54 return (format == GL_RGBA || format == GL_BGRA_EXT); 53 cc::ResourceProvider::Format format) {
54 switch (format) {
55 case cc::ResourceProvider::RGBA_8888:
56 case cc::ResourceProvider::BGRA_8888:
57 return true;
58 case cc::ResourceProvider::RGBA_4444:
59 case cc::ResourceProvider::LUMINANCE_8:
60 return false;
61 }
62 return false;
55 } 63 }
56 64
57 class ScopedSetActiveTexture { 65 class ScopedSetActiveTexture {
58 public: 66 public:
59 ScopedSetActiveTexture(WebGraphicsContext3D* context3d, GLenum unit) 67 ScopedSetActiveTexture(WebGraphicsContext3D* context3d, GLenum unit)
60 : context3d_(context3d), unit_(unit) { 68 : context3d_(context3d), unit_(unit) {
61 DCHECK_EQ(GL_TEXTURE0, ResourceProvider::GetActiveTextureUnit(context3d_)); 69 DCHECK_EQ(GL_TEXTURE0, ResourceProvider::GetActiveTextureUnit(context3d_));
62 70
63 if (unit_ != GL_TEXTURE0) 71 if (unit_ != GL_TEXTURE0)
64 GLC(context3d_, context3d_->activeTexture(unit_)); 72 GLC(context3d_, context3d_->activeTexture(unit_));
(...skipping 23 matching lines...) Expand all
88 exported_count(0), 96 exported_count(0),
89 locked_for_write(false), 97 locked_for_write(false),
90 external(false), 98 external(false),
91 marked_for_deletion(false), 99 marked_for_deletion(false),
92 pending_set_pixels(false), 100 pending_set_pixels(false),
93 set_pixels_completion_forced(false), 101 set_pixels_completion_forced(false),
94 allocated(false), 102 allocated(false),
95 enable_read_lock_fences(false), 103 enable_read_lock_fences(false),
96 read_lock_fence(NULL), 104 read_lock_fence(NULL),
97 size(), 105 size(),
98 format(0),
99 filter(0), 106 filter(0),
100 image_id(0), 107 image_id(0),
101 texture_pool(0), 108 texture_pool(0),
102 wrap_mode(0), 109 wrap_mode(0),
103 hint(TextureUsageAny), 110 hint(TextureUsageAny),
104 type(static_cast<ResourceType>(0)) {} 111 type(static_cast<ResourceType>(0)),
112 texture_format(RGBA_8888) {}
105 113
106 ResourceProvider::Resource::~Resource() {} 114 ResourceProvider::Resource::~Resource() {}
107 115
108 ResourceProvider::Resource::Resource( 116 ResourceProvider::Resource::Resource(
109 unsigned texture_id, 117 unsigned texture_id,
110 gfx::Size size, 118 gfx::Size size,
111 GLenum format,
112 GLenum filter, 119 GLenum filter,
113 GLenum texture_pool, 120 GLenum texture_pool,
114 GLint wrap_mode, 121 GLint wrap_mode,
115 TextureUsageHint hint) 122 TextureUsageHint hint,
123 Format texture_format)
116 : gl_id(texture_id), 124 : gl_id(texture_id),
117 gl_pixel_buffer_id(0), 125 gl_pixel_buffer_id(0),
118 gl_upload_query_id(0), 126 gl_upload_query_id(0),
119 pixels(NULL), 127 pixels(NULL),
120 pixel_buffer(NULL), 128 pixel_buffer(NULL),
121 lock_for_read_count(0), 129 lock_for_read_count(0),
122 imported_count(0), 130 imported_count(0),
123 exported_count(0), 131 exported_count(0),
124 locked_for_write(false), 132 locked_for_write(false),
125 external(false), 133 external(false),
126 marked_for_deletion(false), 134 marked_for_deletion(false),
127 pending_set_pixels(false), 135 pending_set_pixels(false),
128 set_pixels_completion_forced(false), 136 set_pixels_completion_forced(false),
129 allocated(false), 137 allocated(false),
130 enable_read_lock_fences(false), 138 enable_read_lock_fences(false),
131 read_lock_fence(NULL), 139 read_lock_fence(NULL),
132 size(size), 140 size(size),
133 format(format),
134 filter(filter), 141 filter(filter),
135 image_id(0), 142 image_id(0),
136 texture_pool(texture_pool), 143 texture_pool(texture_pool),
137 wrap_mode(wrap_mode), 144 wrap_mode(wrap_mode),
138 hint(hint), 145 hint(hint),
139 type(GLTexture) { 146 type(GLTexture),
147 texture_format(texture_format) {
140 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); 148 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT);
141 } 149 }
142 150
143 ResourceProvider::Resource::Resource( 151 ResourceProvider::Resource::Resource(
144 uint8_t* pixels, 152 uint8_t* pixels,
145 gfx::Size size, 153 gfx::Size size,
146 GLenum format,
147 GLenum filter, 154 GLenum filter,
148 GLint wrap_mode) 155 GLint wrap_mode)
149 : gl_id(0), 156 : gl_id(0),
150 gl_pixel_buffer_id(0), 157 gl_pixel_buffer_id(0),
151 gl_upload_query_id(0), 158 gl_upload_query_id(0),
152 pixels(pixels), 159 pixels(pixels),
153 pixel_buffer(NULL), 160 pixel_buffer(NULL),
154 lock_for_read_count(0), 161 lock_for_read_count(0),
155 imported_count(0), 162 imported_count(0),
156 exported_count(0), 163 exported_count(0),
157 locked_for_write(false), 164 locked_for_write(false),
158 external(false), 165 external(false),
159 marked_for_deletion(false), 166 marked_for_deletion(false),
160 pending_set_pixels(false), 167 pending_set_pixels(false),
161 set_pixels_completion_forced(false), 168 set_pixels_completion_forced(false),
162 allocated(false), 169 allocated(false),
163 enable_read_lock_fences(false), 170 enable_read_lock_fences(false),
164 read_lock_fence(NULL), 171 read_lock_fence(NULL),
165 size(size), 172 size(size),
166 format(format),
167 filter(filter), 173 filter(filter),
168 image_id(0), 174 image_id(0),
169 texture_pool(0), 175 texture_pool(0),
170 wrap_mode(wrap_mode), 176 wrap_mode(wrap_mode),
171 hint(TextureUsageAny), 177 hint(TextureUsageAny),
172 type(Bitmap) { 178 type(Bitmap),
179 texture_format(RGBA_8888) {
173 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); 180 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT);
174 } 181 }
175 182
176 ResourceProvider::Child::Child() {} 183 ResourceProvider::Child::Child() {}
177 184
178 ResourceProvider::Child::~Child() {} 185 ResourceProvider::Child::~Child() {}
179 186
180 scoped_ptr<ResourceProvider> ResourceProvider::Create( 187 scoped_ptr<ResourceProvider> ResourceProvider::Create(
181 OutputSurface* output_surface, 188 OutputSurface* output_surface,
182 int highp_threshold_min) { 189 int highp_threshold_min) {
183 scoped_ptr<ResourceProvider> resource_provider( 190 scoped_ptr<ResourceProvider> resource_provider(
184 new ResourceProvider(output_surface, highp_threshold_min)); 191 new ResourceProvider(output_surface,
192 highp_threshold_min));
185 193
186 bool success = false; 194 bool success = false;
187 if (resource_provider->Context3d()) { 195 if (resource_provider->Context3d()) {
188 success = resource_provider->InitializeGL(); 196 success = resource_provider->InitializeGL();
189 } else { 197 } else {
190 resource_provider->InitializeSoftware(); 198 resource_provider->InitializeSoftware();
191 success = true; 199 success = true;
192 } 200 }
193 201
194 if (!success) 202 if (!success)
195 return scoped_ptr<ResourceProvider>(); 203 return scoped_ptr<ResourceProvider>();
196 204
197 DCHECK_NE(InvalidType, resource_provider->default_resource_type()); 205 DCHECK_NE(InvalidType, resource_provider->default_resource_type());
198 return resource_provider.Pass(); 206 return resource_provider.Pass();
199 } 207 }
200 208
201 ResourceProvider::~ResourceProvider() { 209 ResourceProvider::~ResourceProvider() {
202 while (!resources_.empty()) 210 while (!resources_.empty())
203 DeleteResourceInternal(resources_.begin(), ForShutdown); 211 DeleteResourceInternal(resources_.begin(), ForShutdown);
204 212
205 CleanUpGLIfNeeded(); 213 CleanUpGLIfNeeded();
206 } 214 }
207 215
208 bool ResourceProvider::InUseByConsumer(ResourceId id) { 216 bool ResourceProvider::InUseByConsumer(ResourceId id) {
209 Resource* resource = GetResource(id); 217 Resource* resource = GetResource(id);
210 return resource->lock_for_read_count > 0 || resource->exported_count > 0; 218 return resource->lock_for_read_count > 0 || resource->exported_count > 0;
211 } 219 }
212 220
213 ResourceProvider::ResourceId ResourceProvider::CreateResource( 221 ResourceProvider::ResourceId ResourceProvider::CreateResource(
214 gfx::Size size, GLenum format, GLint wrap_mode, TextureUsageHint hint) { 222 gfx::Size size,
223 GLint wrap_mode,
224 TextureUsageHint hint,
225 Format texture_format) {
215 DCHECK(!size.IsEmpty()); 226 DCHECK(!size.IsEmpty());
216 switch (default_resource_type_) { 227 switch (default_resource_type_) {
217 case GLTexture: 228 case GLTexture:
218 return CreateGLTexture(size, format, GL_TEXTURE_POOL_UNMANAGED_CHROMIUM, 229 return CreateGLTexture(size,
219 wrap_mode, hint); 230 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM,
231 wrap_mode,
232 hint,
233 texture_format);
220 case Bitmap: 234 case Bitmap:
221 // The only wrap_mode currently implemented in software mode is 235 DCHECK(texture_format == RGBA_8888);
enne (OOO) 2013/09/13 01:39:44 DCHECK_EQ, here and elsewhere.
kaanb 2013/09/13 03:43:56 Done.
222 // GL_CLAMP_TO_EDGE.
223 // http://crbug.com/284796
224 DCHECK(format == GL_RGBA);
225 return CreateBitmap(size); 236 return CreateBitmap(size);
226 case InvalidType: 237 case InvalidType:
227 break; 238 break;
228 } 239 }
229 240
230 LOG(FATAL) << "Invalid default resource type."; 241 LOG(FATAL) << "Invalid default resource type.";
231 return 0; 242 return 0;
232 } 243 }
233 244
234 ResourceProvider::ResourceId ResourceProvider::CreateManagedResource( 245 ResourceProvider::ResourceId ResourceProvider::CreateManagedResource(
235 gfx::Size size, GLenum format, GLint wrap_mode, TextureUsageHint hint) { 246 gfx::Size size,
247 GLint wrap_mode,
248 TextureUsageHint hint,
249 Format texture_format) {
236 DCHECK(!size.IsEmpty()); 250 DCHECK(!size.IsEmpty());
237 switch (default_resource_type_) { 251 switch (default_resource_type_) {
238 case GLTexture: 252 case GLTexture:
239 return CreateGLTexture(size, format, GL_TEXTURE_POOL_MANAGED_CHROMIUM, 253 return CreateGLTexture(size,
240 wrap_mode, hint); 254 GL_TEXTURE_POOL_MANAGED_CHROMIUM,
255 wrap_mode,
256 hint,
257 texture_format);
241 case Bitmap: 258 case Bitmap:
242 DCHECK(format == GL_RGBA); 259 DCHECK(texture_format == RGBA_8888);
243 return CreateBitmap(size); 260 return CreateBitmap(size);
244 case InvalidType: 261 case InvalidType:
245 break; 262 break;
246 } 263 }
247 264
248 LOG(FATAL) << "Invalid default resource type."; 265 LOG(FATAL) << "Invalid default resource type.";
249 return 0; 266 return 0;
250 } 267 }
251 268
252 ResourceProvider::ResourceId ResourceProvider::CreateGLTexture( 269 ResourceProvider::ResourceId ResourceProvider::CreateGLTexture(
253 gfx::Size size, 270 gfx::Size size,
254 GLenum format,
255 GLenum texture_pool, 271 GLenum texture_pool,
256 GLint wrap_mode, 272 GLint wrap_mode,
257 TextureUsageHint hint) { 273 TextureUsageHint hint,
274 Format texture_format) {
258 DCHECK_LE(size.width(), max_texture_size_); 275 DCHECK_LE(size.width(), max_texture_size_);
259 DCHECK_LE(size.height(), max_texture_size_); 276 DCHECK_LE(size.height(), max_texture_size_);
260 DCHECK(thread_checker_.CalledOnValidThread()); 277 DCHECK(thread_checker_.CalledOnValidThread());
261 278
262 ResourceId id = next_id_++; 279 ResourceId id = next_id_++;
263 Resource resource(0, size, format, GL_LINEAR, texture_pool, wrap_mode, hint); 280 Resource resource(
281 0, size, GL_LINEAR, texture_pool, wrap_mode, hint, texture_format);
264 resource.allocated = false; 282 resource.allocated = false;
265 resources_[id] = resource; 283 resources_[id] = resource;
266 return id; 284 return id;
267 } 285 }
268 286
269 ResourceProvider::ResourceId ResourceProvider::CreateBitmap(gfx::Size size) { 287 ResourceProvider::ResourceId ResourceProvider::CreateBitmap(gfx::Size size) {
270 DCHECK(thread_checker_.CalledOnValidThread()); 288 DCHECK(thread_checker_.CalledOnValidThread());
271 289
272 uint8_t* pixels = new uint8_t[4 * size.GetArea()]; 290 uint8_t* pixels = new uint8_t[4 * size.GetArea()];
273 291
274 ResourceId id = next_id_++; 292 ResourceId id = next_id_++;
275 Resource resource(pixels, size, GL_RGBA, GL_LINEAR, GL_CLAMP_TO_EDGE); 293 Resource resource(pixels, size, GL_LINEAR, GL_CLAMP_TO_EDGE);
276 resource.allocated = true; 294 resource.allocated = true;
277 resources_[id] = resource; 295 resources_[id] = resource;
278 return id; 296 return id;
279 } 297 }
280 298
281 ResourceProvider::ResourceId 299 ResourceProvider::ResourceId
282 ResourceProvider::CreateResourceFromExternalTexture( 300 ResourceProvider::CreateResourceFromExternalTexture(
283 unsigned texture_target, 301 unsigned texture_target,
284 unsigned texture_id) { 302 unsigned texture_id) {
285 DCHECK(thread_checker_.CalledOnValidThread()); 303 DCHECK(thread_checker_.CalledOnValidThread());
286 304
287 WebGraphicsContext3D* context3d = Context3d(); 305 WebGraphicsContext3D* context3d = Context3d();
288 DCHECK(context3d); 306 DCHECK(context3d);
289 GLC(context3d, context3d->bindTexture(texture_target, texture_id)); 307 GLC(context3d, context3d->bindTexture(texture_target, texture_id));
290 GLC(context3d, context3d->texParameteri( 308 GLC(context3d, context3d->texParameteri(
291 texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); 309 texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
292 GLC(context3d, context3d->texParameteri( 310 GLC(context3d, context3d->texParameteri(
293 texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); 311 texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
294 GLC(context3d, context3d->texParameteri( 312 GLC(context3d, context3d->texParameteri(
295 texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); 313 texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
296 GLC(context3d, context3d->texParameteri( 314 GLC(context3d, context3d->texParameteri(
297 texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); 315 texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
298 316
299 ResourceId id = next_id_++; 317 ResourceId id = next_id_++;
300 Resource resource(texture_id, gfx::Size(), 0, GL_LINEAR, 0, GL_CLAMP_TO_EDGE, 318 Resource resource(texture_id,
301 TextureUsageAny); 319 gfx::Size(),
320 GL_LINEAR,
321 0,
322 GL_CLAMP_TO_EDGE,
323 TextureUsageAny,
324 RGBA_8888);
302 resource.external = true; 325 resource.external = true;
303 resource.allocated = true; 326 resource.allocated = true;
304 resources_[id] = resource; 327 resources_[id] = resource;
305 return id; 328 return id;
306 } 329 }
307 330
308 ResourceProvider::ResourceId ResourceProvider::CreateResourceFromTextureMailbox( 331 ResourceProvider::ResourceId ResourceProvider::CreateResourceFromTextureMailbox(
309 const TextureMailbox& mailbox) { 332 const TextureMailbox& mailbox) {
310 DCHECK(thread_checker_.CalledOnValidThread()); 333 DCHECK(thread_checker_.CalledOnValidThread());
311 // Just store the information. Mailbox will be consumed in LockForRead(). 334 // Just store the information. Mailbox will be consumed in LockForRead().
312 ResourceId id = next_id_++; 335 ResourceId id = next_id_++;
313 DCHECK(mailbox.IsValid()); 336 DCHECK(mailbox.IsValid());
314 Resource& resource = resources_[id]; 337 Resource& resource = resources_[id];
315 if (mailbox.IsTexture()) { 338 if (mailbox.IsTexture()) {
316 resource = Resource(0, gfx::Size(), 0, GL_LINEAR, 0, GL_CLAMP_TO_EDGE, 339 resource = Resource(0,
317 TextureUsageAny); 340 gfx::Size(),
341 GL_LINEAR,
342 0,
343 GL_CLAMP_TO_EDGE,
344 TextureUsageAny,
345 RGBA_8888);
318 } else { 346 } else {
319 DCHECK(mailbox.IsSharedMemory()); 347 DCHECK(mailbox.IsSharedMemory());
320 base::SharedMemory* shared_memory = mailbox.shared_memory(); 348 base::SharedMemory* shared_memory = mailbox.shared_memory();
321 DCHECK(shared_memory->memory()); 349 DCHECK(shared_memory->memory());
322 uint8_t* pixels = reinterpret_cast<uint8_t*>(shared_memory->memory()); 350 uint8_t* pixels = reinterpret_cast<uint8_t*>(shared_memory->memory());
323 resource = Resource(pixels, mailbox.shared_memory_size(), 351 resource = Resource(
324 GL_RGBA, GL_LINEAR, GL_CLAMP_TO_EDGE); 352 pixels, mailbox.shared_memory_size(), GL_LINEAR, GL_CLAMP_TO_EDGE);
325 } 353 }
326 resource.external = true; 354 resource.external = true;
327 resource.allocated = true; 355 resource.allocated = true;
328 resource.mailbox = mailbox; 356 resource.mailbox = mailbox;
329 return id; 357 return id;
330 } 358 }
331 359
332 void ResourceProvider::DeleteResource(ResourceId id) { 360 void ResourceProvider::DeleteResource(ResourceId id) {
333 DCHECK(thread_checker_.CalledOnValidThread()); 361 DCHECK(thread_checker_.CalledOnValidThread());
334 ResourceMap::iterator it = resources_.find(id); 362 ResourceMap::iterator it = resources_.find(id);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 if (resource->gl_id) { 453 if (resource->gl_id) {
426 DCHECK(!resource->pending_set_pixels); 454 DCHECK(!resource->pending_set_pixels);
427 WebGraphicsContext3D* context3d = Context3d(); 455 WebGraphicsContext3D* context3d = Context3d();
428 DCHECK(context3d); 456 DCHECK(context3d);
429 DCHECK(texture_uploader_.get()); 457 DCHECK(texture_uploader_.get());
430 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id); 458 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id);
431 texture_uploader_->Upload(image, 459 texture_uploader_->Upload(image,
432 image_rect, 460 image_rect,
433 source_rect, 461 source_rect,
434 dest_offset, 462 dest_offset,
435 resource->format, 463 resource->texture_format,
436 resource->size); 464 resource->size);
437 } 465 }
438 466
439 if (resource->pixels) { 467 if (resource->pixels) {
440 DCHECK(resource->allocated); 468 DCHECK(resource->allocated);
441 DCHECK(resource->format == GL_RGBA); 469 DCHECK(resource->texture_format == RGBA_8888);
442 SkBitmap src_full; 470 SkBitmap src_full;
443 src_full.setConfig( 471 src_full.setConfig(
444 SkBitmap::kARGB_8888_Config, image_rect.width(), image_rect.height()); 472 SkBitmap::kARGB_8888_Config, image_rect.width(), image_rect.height());
445 src_full.setPixels(const_cast<uint8_t*>(image)); 473 src_full.setPixels(const_cast<uint8_t*>(image));
446 SkBitmap src_subset; 474 SkBitmap src_subset;
447 SkIRect sk_source_rect = SkIRect::MakeXYWH(source_rect.x(), 475 SkIRect sk_source_rect = SkIRect::MakeXYWH(source_rect.x(),
448 source_rect.y(), 476 source_rect.y(),
449 source_rect.width(), 477 source_rect.width(),
450 source_rect.height()); 478 source_rect.height());
451 sk_source_rect.offset(-image_rect.x(), -image_rect.y()); 479 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_); 683 DCHECK(texture_id_);
656 } 684 }
657 685
658 ResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() { 686 ResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() {
659 resource_provider_->UnlockForWrite(resource_id_); 687 resource_provider_->UnlockForWrite(resource_id_);
660 } 688 }
661 689
662 void ResourceProvider::PopulateSkBitmapWithResource( 690 void ResourceProvider::PopulateSkBitmapWithResource(
663 SkBitmap* sk_bitmap, const Resource* resource) { 691 SkBitmap* sk_bitmap, const Resource* resource) {
664 DCHECK(resource->pixels); 692 DCHECK(resource->pixels);
665 DCHECK(resource->format == GL_RGBA); 693 DCHECK(resource->texture_format == RGBA_8888);
666 sk_bitmap->setConfig(SkBitmap::kARGB_8888_Config, 694 sk_bitmap->setConfig(SkBitmap::kARGB_8888_Config,
667 resource->size.width(), 695 resource->size.width(),
668 resource->size.height()); 696 resource->size.height());
669 sk_bitmap->setPixels(resource->pixels); 697 sk_bitmap->setPixels(resource->pixels);
670 } 698 }
671 699
672 ResourceProvider::ScopedReadLockSoftware::ScopedReadLockSoftware( 700 ResourceProvider::ScopedReadLockSoftware::ScopedReadLockSoftware(
673 ResourceProvider* resource_provider, 701 ResourceProvider* resource_provider,
674 ResourceProvider::ResourceId resource_id) 702 ResourceProvider::ResourceId resource_id)
675 : resource_provider_(resource_provider), 703 : resource_provider_(resource_provider),
(...skipping 25 matching lines...) Expand all
701 : output_surface_(output_surface), 729 : output_surface_(output_surface),
702 lost_output_surface_(false), 730 lost_output_surface_(false),
703 highp_threshold_min_(highp_threshold_min), 731 highp_threshold_min_(highp_threshold_min),
704 next_id_(1), 732 next_id_(1),
705 next_child_(1), 733 next_child_(1),
706 default_resource_type_(InvalidType), 734 default_resource_type_(InvalidType),
707 use_texture_storage_ext_(false), 735 use_texture_storage_ext_(false),
708 use_texture_usage_hint_(false), 736 use_texture_usage_hint_(false),
709 use_shallow_flush_(false), 737 use_shallow_flush_(false),
710 max_texture_size_(0), 738 max_texture_size_(0),
711 best_texture_format_(0) { 739 best_texture_format_(RGBA_8888) {
712 DCHECK(output_surface_->HasClient()); 740 DCHECK(output_surface_->HasClient());
713 } 741 }
714 742
715 void ResourceProvider::InitializeSoftware() { 743 void ResourceProvider::InitializeSoftware() {
716 DCHECK(thread_checker_.CalledOnValidThread()); 744 DCHECK(thread_checker_.CalledOnValidThread());
717 DCHECK_NE(Bitmap, default_resource_type_); 745 DCHECK_NE(Bitmap, default_resource_type_);
718 746
719 CleanUpGLIfNeeded(); 747 CleanUpGLIfNeeded();
720 748
721 default_resource_type_ = Bitmap; 749 default_resource_type_ = Bitmap;
722 max_texture_size_ = INT_MAX / 2; 750 max_texture_size_ = INT_MAX / 2;
723 best_texture_format_ = GL_RGBA; 751 best_texture_format_ = RGBA_8888;
724 } 752 }
725 753
726 bool ResourceProvider::InitializeGL() { 754 bool ResourceProvider::InitializeGL() {
727 DCHECK(thread_checker_.CalledOnValidThread()); 755 DCHECK(thread_checker_.CalledOnValidThread());
728 DCHECK(!texture_uploader_); 756 DCHECK(!texture_uploader_);
729 DCHECK_NE(GLTexture, default_resource_type_); 757 DCHECK_NE(GLTexture, default_resource_type_);
730 758
731 WebGraphicsContext3D* context3d = Context3d(); 759 WebGraphicsContext3D* context3d = Context3d();
732 DCHECK(context3d); 760 DCHECK(context3d);
733 761
734 if (!context3d->makeContextCurrent()) 762 if (!context3d->makeContextCurrent())
735 return false; 763 return false;
736 764
737 default_resource_type_ = GLTexture; 765 default_resource_type_ = GLTexture;
738 766
739 const ContextProvider::Capabilities& caps = 767 const ContextProvider::Capabilities& caps =
740 output_surface_->context_provider()->ContextCapabilities(); 768 output_surface_->context_provider()->ContextCapabilities();
741 769
742 bool use_map_sub = caps.map_sub; 770 bool use_map_sub = caps.map_sub;
743 bool use_bgra = caps.texture_format_bgra8888; 771 bool use_bgra = caps.texture_format_bgra8888;
744 use_texture_storage_ext_ = caps.texture_storage; 772 use_texture_storage_ext_ = caps.texture_storage;
745 use_shallow_flush_ = caps.shallow_flush; 773 use_shallow_flush_ = caps.shallow_flush;
746 use_texture_usage_hint_ = caps.texture_usage; 774 use_texture_usage_hint_ = caps.texture_usage;
747 775
748 texture_uploader_ = 776 texture_uploader_ =
749 TextureUploader::Create(context3d, use_map_sub, use_shallow_flush_); 777 TextureUploader::Create(context3d,
778 use_map_sub,
779 use_shallow_flush_);
750 GLC(context3d, context3d->getIntegerv(GL_MAX_TEXTURE_SIZE, 780 GLC(context3d, context3d->getIntegerv(GL_MAX_TEXTURE_SIZE,
751 &max_texture_size_)); 781 &max_texture_size_));
752 best_texture_format_ = PlatformColor::BestTextureFormat(use_bgra); 782 best_texture_format_ = PlatformColor::BestTextureFormat(use_bgra);
753 783
754 return true; 784 return true;
755 } 785 }
756 786
757 void ResourceProvider::CleanUpGLIfNeeded() { 787 void ResourceProvider::CleanUpGLIfNeeded() {
758 WebGraphicsContext3D* context3d = Context3d(); 788 WebGraphicsContext3D* context3d = Context3d();
759 if (default_resource_type_ != GLTexture) { 789 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 932 // deadlocks and/or security issues. The caller is responsible for
903 // waiting asynchronously, and resetting sync_point before calling this. 933 // 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 934 // However if the parent is a renderer (e.g. browser tag), it may be ok
905 // (and is simpler) to wait. 935 // (and is simpler) to wait.
906 if (it->sync_point) 936 if (it->sync_point)
907 GLC(context3d, context3d->waitSyncPoint(it->sync_point)); 937 GLC(context3d, context3d->waitSyncPoint(it->sync_point));
908 GLC(context3d, texture_id = context3d->createTexture()); 938 GLC(context3d, texture_id = context3d->createTexture());
909 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, texture_id)); 939 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, texture_id));
910 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, 940 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D,
911 it->mailbox.name)); 941 it->mailbox.name));
942 Format format = RGBA_8888;
943 switch (it->format) {
944 case 0:
enne (OOO) 2013/09/13 01:39:44 If somebody switched the enum order, this would br
kaanb 2013/09/13 03:43:56 reveman@ didn't like the static_cast
enne (OOO) 2013/09/13 03:53:25 I think static_cast + CHECK would be the cleanest,
reveman 2013/09/13 14:59:48 yes, it's the CHECK I want and I think a switch st
kaanb 2013/09/13 19:57:39 Done.
945 format = RGBA_8888;
946 break;
947 case 1:
948 format = RGBA_4444;
949 break;
950 case 2:
951 format = BGRA_8888;
952 break;
953 case 3:
954 format = LUMINANCE_8;
955 break;
956 }
piman 2013/09/13 01:42:01 Why not make TransferableResource use ResourceProv
kaanb 2013/09/13 03:43:56 It looks like TransferableResource is part of an I
piman 2013/09/13 04:56:51 Sure, so, we should fix that. Enums are fine to pa
reveman 2013/09/13 14:32:49 What's the proper way to check that enum values ar
kaanb 2013/09/13 19:57:39 I implemented reveman's suggestion for now. When c
957
912 ResourceId id = next_id_++; 958 ResourceId id = next_id_++;
913 Resource resource( 959 Resource resource(
914 texture_id, it->size, it->format, it->filter, 0, GL_CLAMP_TO_EDGE, 960 texture_id,
915 TextureUsageAny); 961 it->size,
962 it->filter,
963 0,
964 GL_CLAMP_TO_EDGE,
965 TextureUsageAny,
966 format);
916 resource.mailbox.SetName(it->mailbox); 967 resource.mailbox.SetName(it->mailbox);
917 // Don't allocate a texture for a child. 968 // Don't allocate a texture for a child.
918 resource.allocated = true; 969 resource.allocated = true;
919 resource.imported_count = 1; 970 resource.imported_count = 1;
920 resources_[id] = resource; 971 resources_[id] = resource;
921 child_info.parent_to_child_map[id] = it->id; 972 child_info.parent_to_child_map[id] = it->id;
922 child_info.child_to_parent_map[it->id] = id; 973 child_info.child_to_parent_map[it->id] = id;
923 } 974 }
924 } 975 }
925 976
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
957 1008
958 void ResourceProvider::TransferResource(WebGraphicsContext3D* context, 1009 void ResourceProvider::TransferResource(WebGraphicsContext3D* context,
959 ResourceId id, 1010 ResourceId id,
960 TransferableResource* resource) { 1011 TransferableResource* resource) {
961 Resource* source = GetResource(id); 1012 Resource* source = GetResource(id);
962 DCHECK(!source->locked_for_write); 1013 DCHECK(!source->locked_for_write);
963 DCHECK(!source->lock_for_read_count); 1014 DCHECK(!source->lock_for_read_count);
964 DCHECK(!source->external || (source->external && source->mailbox.IsValid())); 1015 DCHECK(!source->external || (source->external && source->mailbox.IsValid()));
965 DCHECK(source->allocated); 1016 DCHECK(source->allocated);
966 resource->id = id; 1017 resource->id = id;
967 resource->format = source->format;
968 resource->filter = source->filter; 1018 resource->filter = source->filter;
969 resource->size = source->size; 1019 resource->size = source->size;
1020 resource->format = source->texture_format;
970 1021
971 // TODO(skaslev) Implement this path for shared memory resources. 1022 // TODO(skaslev) Implement this path for shared memory resources.
972 DCHECK(!source->mailbox.IsSharedMemory()); 1023 DCHECK(!source->mailbox.IsSharedMemory());
973 1024
974 if (!source->mailbox.IsTexture()) { 1025 if (!source->mailbox.IsTexture()) {
975 // This is a resource allocated by the compositor, we need to produce it. 1026 // 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. 1027 // Don't set a sync point, the caller will do it.
977 DCHECK(source->gl_id); 1028 DCHECK(source->gl_id);
978 GLC(context, context->bindTexture(GL_TEXTURE_2D, source->gl_id)); 1029 GLC(context, context->bindTexture(GL_TEXTURE_2D, source->gl_id));
979 GLC(context, context->genMailboxCHROMIUM(resource->mailbox.name)); 1030 GLC(context, context->genMailboxCHROMIUM(resource->mailbox.name));
(...skipping 16 matching lines...) Expand all
996 DCHECK(!resource->image_id); 1047 DCHECK(!resource->image_id);
997 1048
998 if (resource->type == GLTexture) { 1049 if (resource->type == GLTexture) {
999 WebGraphicsContext3D* context3d = Context3d(); 1050 WebGraphicsContext3D* context3d = Context3d();
1000 DCHECK(context3d); 1051 DCHECK(context3d);
1001 if (!resource->gl_pixel_buffer_id) 1052 if (!resource->gl_pixel_buffer_id)
1002 resource->gl_pixel_buffer_id = context3d->createBuffer(); 1053 resource->gl_pixel_buffer_id = context3d->createBuffer();
1003 context3d->bindBuffer( 1054 context3d->bindBuffer(
1004 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 1055 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
1005 resource->gl_pixel_buffer_id); 1056 resource->gl_pixel_buffer_id);
1057 size_t bytes_per_pixel = BytesPerPixel(resource->texture_format);
1006 context3d->bufferData( 1058 context3d->bufferData(
1007 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 1059 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
1008 4 * resource->size.GetArea(), 1060 bytes_per_pixel * resource->size.GetArea(),
1009 NULL, 1061 NULL,
1010 GL_DYNAMIC_DRAW); 1062 GL_DYNAMIC_DRAW);
1011 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); 1063 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0);
1012 } 1064 }
1013 1065
1014 if (resource->pixels) { 1066 if (resource->pixels) {
1015 if (resource->pixel_buffer) 1067 if (resource->pixel_buffer)
1016 return; 1068 return;
1017 1069
1018 resource->pixel_buffer = new uint8_t[4 * resource->size.GetArea()]; 1070 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); 1221 DCHECK(resource->gl_pixel_buffer_id);
1170 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id); 1222 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id);
1171 context3d->bindBuffer( 1223 context3d->bindBuffer(
1172 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 1224 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
1173 resource->gl_pixel_buffer_id); 1225 resource->gl_pixel_buffer_id);
1174 if (!resource->gl_upload_query_id) 1226 if (!resource->gl_upload_query_id)
1175 resource->gl_upload_query_id = context3d->createQueryEXT(); 1227 resource->gl_upload_query_id = context3d->createQueryEXT();
1176 context3d->beginQueryEXT( 1228 context3d->beginQueryEXT(
1177 GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM, 1229 GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM,
1178 resource->gl_upload_query_id); 1230 resource->gl_upload_query_id);
1231 DCHECK(resource->texture_format != RGBA_4444 ||
1232 (resource->size.width() % 2) == 0);
1179 if (allocate) { 1233 if (allocate) {
1180 context3d->asyncTexImage2DCHROMIUM(GL_TEXTURE_2D, 1234 context3d->asyncTexImage2DCHROMIUM(
1181 0, /* level */ 1235 GL_TEXTURE_2D,
1182 resource->format, 1236 0, /* level */
1183 resource->size.width(), 1237 GetGLInternalFormat(resource->texture_format),
1184 resource->size.height(), 1238 resource->size.width(),
1185 0, /* border */ 1239 resource->size.height(),
1186 resource->format, 1240 0, /* border */
1187 GL_UNSIGNED_BYTE, 1241 GetGLDataFormat(resource->texture_format),
1188 NULL); 1242 GetGLDataType(resource->texture_format),
1243 NULL);
1189 } else { 1244 } else {
1190 context3d->asyncTexSubImage2DCHROMIUM(GL_TEXTURE_2D, 1245 context3d->asyncTexSubImage2DCHROMIUM(
1191 0, /* level */ 1246 GL_TEXTURE_2D,
1192 0, /* x */ 1247 0, /* level */
1193 0, /* y */ 1248 0, /* x */
1194 resource->size.width(), 1249 0, /* y */
1195 resource->size.height(), 1250 resource->size.width(),
1196 resource->format, 1251 resource->size.height(),
1197 GL_UNSIGNED_BYTE, 1252 GetGLDataFormat(resource->texture_format),
1198 NULL); 1253 GetGLDataType(resource->texture_format),
1254 NULL);
1199 } 1255 }
1200 context3d->endQueryEXT(GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM); 1256 context3d->endQueryEXT(GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM);
1201 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); 1257 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0);
1202 } 1258 }
1203 1259
1204 if (resource->pixels) { 1260 if (resource->pixels) {
1205 DCHECK(!resource->mailbox.IsValid()); 1261 DCHECK(!resource->mailbox.IsValid());
1206 DCHECK(resource->pixel_buffer); 1262 DCHECK(resource->pixel_buffer);
1207 DCHECK(resource->format == GL_RGBA); 1263 DCHECK(resource->texture_format == RGBA_8888);
1208 1264
1209 std::swap(resource->pixels, resource->pixel_buffer); 1265 std::swap(resource->pixels, resource->pixel_buffer);
1210 delete[] resource->pixel_buffer; 1266 delete[] resource->pixel_buffer;
1211 resource->pixel_buffer = NULL; 1267 resource->pixel_buffer = NULL;
1212 } 1268 }
1213 1269
1214 resource->pending_set_pixels = true; 1270 resource->pending_set_pixels = true;
1215 resource->set_pixels_completion_forced = false; 1271 resource->set_pixels_completion_forced = false;
1216 } 1272 }
1217 1273
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1303 void ResourceProvider::LazyAllocate(Resource* resource) { 1359 void ResourceProvider::LazyAllocate(Resource* resource) {
1304 DCHECK(resource); 1360 DCHECK(resource);
1305 LazyCreate(resource); 1361 LazyCreate(resource);
1306 1362
1307 DCHECK(resource->gl_id || resource->allocated); 1363 DCHECK(resource->gl_id || resource->allocated);
1308 if (resource->allocated || !resource->gl_id) 1364 if (resource->allocated || !resource->gl_id)
1309 return; 1365 return;
1310 resource->allocated = true; 1366 resource->allocated = true;
1311 WebGraphicsContext3D* context3d = Context3d(); 1367 WebGraphicsContext3D* context3d = Context3d();
1312 gfx::Size& size = resource->size; 1368 gfx::Size& size = resource->size;
1313 GLenum format = resource->format; 1369 Format format = resource->texture_format;
1314 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id)); 1370 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id));
1315 if (use_texture_storage_ext_ && IsTextureFormatSupportedForStorage(format)) { 1371 if (use_texture_storage_ext_ && IsFormatSupportedForStorage(format)) {
1316 GLenum storage_format = TextureToStorageFormat(format); 1372 GLenum storage_format = TextureToStorageFormat(format);
1317 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, 1373 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D,
1318 1, 1374 1,
1319 storage_format, 1375 storage_format,
1320 size.width(), 1376 size.width(),
1321 size.height())); 1377 size.height()));
1322 } else { 1378 } else {
1323 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, 1379 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D,
1324 0, 1380 0,
1325 format, 1381 GetGLInternalFormat(format),
1326 size.width(), 1382 size.width(),
1327 size.height(), 1383 size.height(),
1328 0, 1384 0,
1329 format, 1385 GetGLDataFormat(format),
1330 GL_UNSIGNED_BYTE, 1386 GetGLDataType(format),
1331 NULL)); 1387 NULL));
1332 } 1388 }
1333 } 1389 }
1334 1390
1335 void ResourceProvider::EnableReadLockFences(ResourceProvider::ResourceId id, 1391 void ResourceProvider::EnableReadLockFences(ResourceProvider::ResourceId id,
1336 bool enable) { 1392 bool enable) {
1337 Resource* resource = GetResource(id); 1393 Resource* resource = GetResource(id);
1338 resource->enable_read_lock_fences = enable; 1394 resource->enable_read_lock_fences = enable;
1339 } 1395 }
1340 1396
1341 void ResourceProvider::AcquireImage(ResourceId id) { 1397 void ResourceProvider::AcquireImage(ResourceId id) {
1342 Resource* resource = GetResource(id); 1398 Resource* resource = GetResource(id);
1343 DCHECK(!resource->external); 1399 DCHECK(!resource->external);
1344 DCHECK_EQ(resource->exported_count, 0); 1400 DCHECK_EQ(resource->exported_count, 0);
1345 1401
1346 if (resource->type != GLTexture) 1402 if (resource->type != GLTexture)
1347 return; 1403 return;
1348 1404
1349 if (resource->image_id) 1405 if (resource->image_id)
1350 return; 1406 return;
1351 1407
1352 resource->allocated = true; 1408 resource->allocated = true;
1353 WebGraphicsContext3D* context3d = Context3d(); 1409 WebGraphicsContext3D* context3d = Context3d();
1354 DCHECK(context3d); 1410 DCHECK(context3d);
1355 DCHECK_EQ(static_cast<GLenum>(GL_RGBA), resource->format); 1411 DCHECK_EQ(RGBA_8888, resource->texture_format);
1356 resource->image_id = context3d->createImageCHROMIUM( 1412 resource->image_id = context3d->createImageCHROMIUM(
1357 resource->size.width(), resource->size.height(), GL_RGBA8_OES); 1413 resource->size.width(), resource->size.height(), GL_RGBA8_OES);
1358 DCHECK(resource->image_id); 1414 DCHECK(resource->image_id);
1359 } 1415 }
1360 1416
1361 void ResourceProvider::ReleaseImage(ResourceId id) { 1417 void ResourceProvider::ReleaseImage(ResourceId id) {
1362 Resource* resource = GetResource(id); 1418 Resource* resource = GetResource(id);
1363 DCHECK(!resource->external); 1419 DCHECK(!resource->external);
1364 DCHECK_EQ(resource->exported_count, 0); 1420 DCHECK_EQ(resource->exported_count, 0);
1365 1421
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1425 GLint active_unit = 0; 1481 GLint active_unit = 0;
1426 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit); 1482 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit);
1427 return active_unit; 1483 return active_unit;
1428 } 1484 }
1429 1485
1430 WebKit::WebGraphicsContext3D* ResourceProvider::Context3d() const { 1486 WebKit::WebGraphicsContext3D* ResourceProvider::Context3d() const {
1431 ContextProvider* context_provider = output_surface_->context_provider(); 1487 ContextProvider* context_provider = output_surface_->context_provider();
1432 return context_provider ? context_provider->Context3d() : NULL; 1488 return context_provider ? context_provider->Context3d() : NULL;
1433 } 1489 }
1434 1490
1491 size_t ResourceProvider::BytesPerPixel(Format format) {
1492 size_t components_per_pixel = 0;
1493 switch (format) {
1494 case RGBA_8888:
1495 case RGBA_4444:
1496 case BGRA_8888:
1497 components_per_pixel = 4;
1498 break;
1499 case LUMINANCE_8:
1500 components_per_pixel = 1;
1501 break;
1502 }
1503 size_t bits_per_component = 0;
1504 switch (format) {
1505 case RGBA_8888:
1506 case BGRA_8888:
1507 case LUMINANCE_8:
1508 bits_per_component = 8;
1509 break;
1510 case RGBA_4444:
1511 bits_per_component = 4;
1512 break;
1513 }
1514 const size_t kBitsPerByte = 8;
1515 return (components_per_pixel * bits_per_component) / kBitsPerByte;
1516 }
1517
1518 GLenum ResourceProvider::GetGLDataType(Format format) {
1519 GLenum texture_data_type = GL_UNSIGNED_BYTE;
1520 switch (format) {
1521 case RGBA_4444:
1522 texture_data_type = GL_UNSIGNED_SHORT_4_4_4_4;
reveman 2013/09/13 14:32:49 nit: I'd remove the temporary variable and just "r
kaanb 2013/09/13 19:57:39 Done.
1523 break;
1524 case RGBA_8888:
1525 case BGRA_8888:
1526 case LUMINANCE_8:
1527 texture_data_type = GL_UNSIGNED_BYTE;
1528 break;
1529 }
1530 return texture_data_type;
1531 }
1532
1533 GLenum ResourceProvider::GetGLDataFormat(Format format) {
1534 GLenum data_format = GL_RGBA;
1535 switch (format) {
1536 case RGBA_8888:
1537 case RGBA_4444:
1538 data_format = GL_RGBA;
1539 break;
1540 case BGRA_8888:
1541 data_format = GL_BGRA_EXT;
1542 break;
1543 case LUMINANCE_8:
1544 data_format = GL_LUMINANCE;
1545 break;
1546 }
1547 return data_format;
1548 }
1549
1550 GLenum ResourceProvider::GetGLInternalFormat(Format format) {
1551 return GetGLDataFormat(format);
1552 }
1553
1554 unsigned ResourceProvider::GetStride(Format format) {
1555 unsigned stride = 4;
1556 switch (format) {
1557 case RGBA_4444:
1558 stride = 2;
1559 break;
1560 case RGBA_8888:
1561 case BGRA_8888:
1562 case LUMINANCE_8:
1563 stride = 4;
1564 break;
1565 }
1566 return stride;
1567 }
1568
1435 } // namespace cc 1569 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698