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

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: Move stride check to RWP 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 original_filter(0), 105 original_filter(0),
100 filter(0), 106 filter(0),
101 target(0), 107 target(0),
102 image_id(0), 108 image_id(0),
103 texture_pool(0), 109 texture_pool(0),
104 wrap_mode(0), 110 wrap_mode(0),
105 hint(TextureUsageAny), 111 hint(TextureUsageAny),
106 type(static_cast<ResourceType>(0)) {} 112 type(static_cast<ResourceType>(0)),
113 format(RGBA_8888) {}
107 114
108 ResourceProvider::Resource::~Resource() {} 115 ResourceProvider::Resource::~Resource() {}
109 116
110 ResourceProvider::Resource::Resource( 117 ResourceProvider::Resource::Resource(
111 unsigned texture_id, 118 unsigned texture_id,
112 gfx::Size size, 119 gfx::Size size,
113 GLenum format,
114 GLenum filter, 120 GLenum filter,
115 GLenum texture_pool, 121 GLenum texture_pool,
116 GLint wrap_mode, 122 GLint wrap_mode,
117 TextureUsageHint hint) 123 TextureUsageHint hint,
124 ResourceFormat format)
118 : gl_id(texture_id), 125 : gl_id(texture_id),
119 gl_pixel_buffer_id(0), 126 gl_pixel_buffer_id(0),
120 gl_upload_query_id(0), 127 gl_upload_query_id(0),
121 pixels(NULL), 128 pixels(NULL),
122 pixel_buffer(NULL), 129 pixel_buffer(NULL),
123 lock_for_read_count(0), 130 lock_for_read_count(0),
124 imported_count(0), 131 imported_count(0),
125 exported_count(0), 132 exported_count(0),
126 locked_for_write(false), 133 locked_for_write(false),
127 external(false), 134 external(false),
128 marked_for_deletion(false), 135 marked_for_deletion(false),
129 pending_set_pixels(false), 136 pending_set_pixels(false),
130 set_pixels_completion_forced(false), 137 set_pixels_completion_forced(false),
131 allocated(false), 138 allocated(false),
132 enable_read_lock_fences(false), 139 enable_read_lock_fences(false),
133 read_lock_fence(NULL), 140 read_lock_fence(NULL),
134 size(size), 141 size(size),
135 format(format),
136 original_filter(filter), 142 original_filter(filter),
137 filter(filter), 143 filter(filter),
138 target(0), 144 target(0),
139 image_id(0), 145 image_id(0),
140 texture_pool(texture_pool), 146 texture_pool(texture_pool),
141 wrap_mode(wrap_mode), 147 wrap_mode(wrap_mode),
142 hint(hint), 148 hint(hint),
143 type(GLTexture) { 149 type(GLTexture),
150 format(format) {
144 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); 151 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT);
145 } 152 }
146 153
147 ResourceProvider::Resource::Resource( 154 ResourceProvider::Resource::Resource(
148 uint8_t* pixels, 155 uint8_t* pixels,
149 gfx::Size size, 156 gfx::Size size,
150 GLenum format,
151 GLenum filter, 157 GLenum filter,
152 GLint wrap_mode) 158 GLint wrap_mode)
153 : gl_id(0), 159 : gl_id(0),
154 gl_pixel_buffer_id(0), 160 gl_pixel_buffer_id(0),
155 gl_upload_query_id(0), 161 gl_upload_query_id(0),
156 pixels(pixels), 162 pixels(pixels),
157 pixel_buffer(NULL), 163 pixel_buffer(NULL),
158 lock_for_read_count(0), 164 lock_for_read_count(0),
159 imported_count(0), 165 imported_count(0),
160 exported_count(0), 166 exported_count(0),
161 locked_for_write(false), 167 locked_for_write(false),
162 external(false), 168 external(false),
163 marked_for_deletion(false), 169 marked_for_deletion(false),
164 pending_set_pixels(false), 170 pending_set_pixels(false),
165 set_pixels_completion_forced(false), 171 set_pixels_completion_forced(false),
166 allocated(false), 172 allocated(false),
167 enable_read_lock_fences(false), 173 enable_read_lock_fences(false),
168 read_lock_fence(NULL), 174 read_lock_fence(NULL),
169 size(size), 175 size(size),
170 format(format),
171 original_filter(filter), 176 original_filter(filter),
172 filter(filter), 177 filter(filter),
173 target(0), 178 target(0),
174 image_id(0), 179 image_id(0),
175 texture_pool(0), 180 texture_pool(0),
176 wrap_mode(wrap_mode), 181 wrap_mode(wrap_mode),
177 hint(TextureUsageAny), 182 hint(TextureUsageAny),
178 type(Bitmap) { 183 type(Bitmap),
184 format(RGBA_8888) {
179 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); 185 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT);
180 } 186 }
181 187
182 ResourceProvider::Child::Child() {} 188 ResourceProvider::Child::Child() {}
183 189
184 ResourceProvider::Child::~Child() {} 190 ResourceProvider::Child::~Child() {}
185 191
186 scoped_ptr<ResourceProvider> ResourceProvider::Create( 192 scoped_ptr<ResourceProvider> ResourceProvider::Create(
187 OutputSurface* output_surface, 193 OutputSurface* output_surface,
188 int highp_threshold_min) { 194 int highp_threshold_min,
195 bool use_rgba_4444_texture_format) {
189 scoped_ptr<ResourceProvider> resource_provider( 196 scoped_ptr<ResourceProvider> resource_provider(
190 new ResourceProvider(output_surface, highp_threshold_min)); 197 new ResourceProvider(output_surface,
198 highp_threshold_min,
199 use_rgba_4444_texture_format));
191 200
192 bool success = false; 201 bool success = false;
193 if (resource_provider->Context3d()) { 202 if (resource_provider->Context3d()) {
194 success = resource_provider->InitializeGL(); 203 success = resource_provider->InitializeGL();
195 } else { 204 } else {
196 resource_provider->InitializeSoftware(); 205 resource_provider->InitializeSoftware();
197 success = true; 206 success = true;
198 } 207 }
199 208
200 if (!success) 209 if (!success)
201 return scoped_ptr<ResourceProvider>(); 210 return scoped_ptr<ResourceProvider>();
202 211
203 DCHECK_NE(InvalidType, resource_provider->default_resource_type()); 212 DCHECK_NE(InvalidType, resource_provider->default_resource_type());
204 return resource_provider.Pass(); 213 return resource_provider.Pass();
205 } 214 }
206 215
207 ResourceProvider::~ResourceProvider() { 216 ResourceProvider::~ResourceProvider() {
208 while (!resources_.empty()) 217 while (!resources_.empty())
209 DeleteResourceInternal(resources_.begin(), ForShutdown); 218 DeleteResourceInternal(resources_.begin(), ForShutdown);
210 219
211 CleanUpGLIfNeeded(); 220 CleanUpGLIfNeeded();
212 } 221 }
213 222
214 bool ResourceProvider::InUseByConsumer(ResourceId id) { 223 bool ResourceProvider::InUseByConsumer(ResourceId id) {
215 Resource* resource = GetResource(id); 224 Resource* resource = GetResource(id);
216 return resource->lock_for_read_count > 0 || resource->exported_count > 0; 225 return resource->lock_for_read_count > 0 || resource->exported_count > 0;
217 } 226 }
218 227
219 ResourceProvider::ResourceId ResourceProvider::CreateResource( 228 ResourceProvider::ResourceId ResourceProvider::CreateResource(
220 gfx::Size size, GLenum format, GLint wrap_mode, TextureUsageHint hint) { 229 gfx::Size size,
230 GLint wrap_mode,
231 TextureUsageHint hint,
232 ResourceFormat format) {
221 DCHECK(!size.IsEmpty()); 233 DCHECK(!size.IsEmpty());
222 switch (default_resource_type_) { 234 switch (default_resource_type_) {
223 case GLTexture: 235 case GLTexture:
224 return CreateGLTexture(size, format, GL_TEXTURE_POOL_UNMANAGED_CHROMIUM, 236 return CreateGLTexture(size,
225 wrap_mode, hint); 237 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM,
238 wrap_mode,
239 hint,
240 format);
226 case Bitmap: 241 case Bitmap:
227 // The only wrap_mode currently implemented in software mode is 242 DCHECK_EQ(RGBA_8888, format);
228 // GL_CLAMP_TO_EDGE.
229 // http://crbug.com/284796
230 DCHECK(format == GL_RGBA);
231 return CreateBitmap(size); 243 return CreateBitmap(size);
232 case InvalidType: 244 case InvalidType:
233 break; 245 break;
234 } 246 }
235 247
236 LOG(FATAL) << "Invalid default resource type."; 248 LOG(FATAL) << "Invalid default resource type.";
237 return 0; 249 return 0;
238 } 250 }
239 251
240 ResourceProvider::ResourceId ResourceProvider::CreateManagedResource( 252 ResourceProvider::ResourceId ResourceProvider::CreateManagedResource(
241 gfx::Size size, GLenum format, GLint wrap_mode, TextureUsageHint hint) { 253 gfx::Size size,
254 GLint wrap_mode,
255 TextureUsageHint hint,
256 ResourceFormat format) {
242 DCHECK(!size.IsEmpty()); 257 DCHECK(!size.IsEmpty());
243 switch (default_resource_type_) { 258 switch (default_resource_type_) {
244 case GLTexture: 259 case GLTexture:
245 return CreateGLTexture(size, format, GL_TEXTURE_POOL_MANAGED_CHROMIUM, 260 return CreateGLTexture(size,
246 wrap_mode, hint); 261 GL_TEXTURE_POOL_MANAGED_CHROMIUM,
262 wrap_mode,
263 hint,
264 format);
247 case Bitmap: 265 case Bitmap:
248 DCHECK(format == GL_RGBA); 266 DCHECK_EQ(RGBA_8888, format);
249 return CreateBitmap(size); 267 return CreateBitmap(size);
250 case InvalidType: 268 case InvalidType:
251 break; 269 break;
252 } 270 }
253 271
254 LOG(FATAL) << "Invalid default resource type."; 272 LOG(FATAL) << "Invalid default resource type.";
255 return 0; 273 return 0;
256 } 274 }
257 275
258 ResourceProvider::ResourceId ResourceProvider::CreateGLTexture( 276 ResourceProvider::ResourceId ResourceProvider::CreateGLTexture(
259 gfx::Size size, 277 gfx::Size size,
260 GLenum format,
261 GLenum texture_pool, 278 GLenum texture_pool,
262 GLint wrap_mode, 279 GLint wrap_mode,
263 TextureUsageHint hint) { 280 TextureUsageHint hint,
281 ResourceFormat format) {
264 DCHECK_LE(size.width(), max_texture_size_); 282 DCHECK_LE(size.width(), max_texture_size_);
265 DCHECK_LE(size.height(), max_texture_size_); 283 DCHECK_LE(size.height(), max_texture_size_);
266 DCHECK(thread_checker_.CalledOnValidThread()); 284 DCHECK(thread_checker_.CalledOnValidThread());
267 285
268 ResourceId id = next_id_++; 286 ResourceId id = next_id_++;
269 Resource resource(0, size, format, GL_LINEAR, texture_pool, wrap_mode, hint); 287 Resource resource(0, size, GL_LINEAR, texture_pool, wrap_mode, hint, format);
270 resource.allocated = false; 288 resource.allocated = false;
271 resources_[id] = resource; 289 resources_[id] = resource;
272 return id; 290 return id;
273 } 291 }
274 292
275 ResourceProvider::ResourceId ResourceProvider::CreateBitmap(gfx::Size size) { 293 ResourceProvider::ResourceId ResourceProvider::CreateBitmap(gfx::Size size) {
276 DCHECK(thread_checker_.CalledOnValidThread()); 294 DCHECK(thread_checker_.CalledOnValidThread());
277 295
278 uint8_t* pixels = new uint8_t[4 * size.GetArea()]; 296 uint8_t* pixels = new uint8_t[4 * size.GetArea()];
279 297
280 ResourceId id = next_id_++; 298 ResourceId id = next_id_++;
281 Resource resource(pixels, size, GL_RGBA, GL_LINEAR, GL_CLAMP_TO_EDGE); 299 Resource resource(pixels, size, GL_LINEAR, GL_CLAMP_TO_EDGE);
282 resource.allocated = true; 300 resource.allocated = true;
283 resources_[id] = resource; 301 resources_[id] = resource;
284 return id; 302 return id;
285 } 303 }
286 304
287 ResourceProvider::ResourceId 305 ResourceProvider::ResourceId
288 ResourceProvider::CreateResourceFromExternalTexture( 306 ResourceProvider::CreateResourceFromExternalTexture(
289 unsigned texture_target, 307 unsigned texture_target,
290 unsigned texture_id) { 308 unsigned texture_id) {
291 DCHECK(thread_checker_.CalledOnValidThread()); 309 DCHECK(thread_checker_.CalledOnValidThread());
292 310
293 WebGraphicsContext3D* context3d = Context3d(); 311 WebGraphicsContext3D* context3d = Context3d();
294 DCHECK(context3d); 312 DCHECK(context3d);
295 GLC(context3d, context3d->bindTexture(texture_target, texture_id)); 313 GLC(context3d, context3d->bindTexture(texture_target, texture_id));
296 GLC(context3d, context3d->texParameteri( 314 GLC(context3d, context3d->texParameteri(
297 texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); 315 texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
298 GLC(context3d, context3d->texParameteri( 316 GLC(context3d, context3d->texParameteri(
299 texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); 317 texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
300 GLC(context3d, context3d->texParameteri( 318 GLC(context3d, context3d->texParameteri(
301 texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); 319 texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
302 GLC(context3d, context3d->texParameteri( 320 GLC(context3d, context3d->texParameteri(
303 texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); 321 texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
304 322
305 ResourceId id = next_id_++; 323 ResourceId id = next_id_++;
306 Resource resource(texture_id, gfx::Size(), 0, GL_LINEAR, 0, GL_CLAMP_TO_EDGE, 324 Resource resource(texture_id,
307 TextureUsageAny); 325 gfx::Size(),
326 GL_LINEAR,
327 0,
328 GL_CLAMP_TO_EDGE,
329 TextureUsageAny,
330 RGBA_8888);
308 resource.external = true; 331 resource.external = true;
309 resource.allocated = true; 332 resource.allocated = true;
310 resources_[id] = resource; 333 resources_[id] = resource;
311 return id; 334 return id;
312 } 335 }
313 336
314 ResourceProvider::ResourceId ResourceProvider::CreateResourceFromTextureMailbox( 337 ResourceProvider::ResourceId ResourceProvider::CreateResourceFromTextureMailbox(
315 const TextureMailbox& mailbox) { 338 const TextureMailbox& mailbox) {
316 DCHECK(thread_checker_.CalledOnValidThread()); 339 DCHECK(thread_checker_.CalledOnValidThread());
317 // Just store the information. Mailbox will be consumed in LockForRead(). 340 // Just store the information. Mailbox will be consumed in LockForRead().
318 ResourceId id = next_id_++; 341 ResourceId id = next_id_++;
319 DCHECK(mailbox.IsValid()); 342 DCHECK(mailbox.IsValid());
320 Resource& resource = resources_[id]; 343 Resource& resource = resources_[id];
321 if (mailbox.IsTexture()) { 344 if (mailbox.IsTexture()) {
322 resource = Resource(0, gfx::Size(), 0, GL_LINEAR, 0, GL_CLAMP_TO_EDGE, 345 resource = Resource(0,
323 TextureUsageAny); 346 gfx::Size(),
347 GL_LINEAR,
348 0,
349 GL_CLAMP_TO_EDGE,
350 TextureUsageAny,
351 RGBA_8888);
324 } else { 352 } else {
325 DCHECK(mailbox.IsSharedMemory()); 353 DCHECK(mailbox.IsSharedMemory());
326 base::SharedMemory* shared_memory = mailbox.shared_memory(); 354 base::SharedMemory* shared_memory = mailbox.shared_memory();
327 DCHECK(shared_memory->memory()); 355 DCHECK(shared_memory->memory());
328 uint8_t* pixels = reinterpret_cast<uint8_t*>(shared_memory->memory()); 356 uint8_t* pixels = reinterpret_cast<uint8_t*>(shared_memory->memory());
329 resource = Resource(pixels, mailbox.shared_memory_size(), 357 resource = Resource(
330 GL_RGBA, GL_LINEAR, GL_CLAMP_TO_EDGE); 358 pixels, mailbox.shared_memory_size(), GL_LINEAR, GL_CLAMP_TO_EDGE);
331 } 359 }
332 resource.external = true; 360 resource.external = true;
333 resource.allocated = true; 361 resource.allocated = true;
334 resource.mailbox = mailbox; 362 resource.mailbox = mailbox;
335 return id; 363 return id;
336 } 364 }
337 365
338 void ResourceProvider::DeleteResource(ResourceId id) { 366 void ResourceProvider::DeleteResource(ResourceId id) {
339 DCHECK(thread_checker_.CalledOnValidThread()); 367 DCHECK(thread_checker_.CalledOnValidThread());
340 ResourceMap::iterator it = resources_.find(id); 368 ResourceMap::iterator it = resources_.find(id);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 texture_uploader_->Upload(image, 465 texture_uploader_->Upload(image,
438 image_rect, 466 image_rect,
439 source_rect, 467 source_rect,
440 dest_offset, 468 dest_offset,
441 resource->format, 469 resource->format,
442 resource->size); 470 resource->size);
443 } 471 }
444 472
445 if (resource->pixels) { 473 if (resource->pixels) {
446 DCHECK(resource->allocated); 474 DCHECK(resource->allocated);
447 DCHECK(resource->format == GL_RGBA); 475 DCHECK_EQ(RGBA_8888, resource->format);
448 SkBitmap src_full; 476 SkBitmap src_full;
449 src_full.setConfig( 477 src_full.setConfig(
450 SkBitmap::kARGB_8888_Config, image_rect.width(), image_rect.height()); 478 SkBitmap::kARGB_8888_Config, image_rect.width(), image_rect.height());
451 src_full.setPixels(const_cast<uint8_t*>(image)); 479 src_full.setPixels(const_cast<uint8_t*>(image));
452 SkBitmap src_subset; 480 SkBitmap src_subset;
453 SkIRect sk_source_rect = SkIRect::MakeXYWH(source_rect.x(), 481 SkIRect sk_source_rect = SkIRect::MakeXYWH(source_rect.x(),
454 source_rect.y(), 482 source_rect.y(),
455 source_rect.width(), 483 source_rect.width(),
456 source_rect.height()); 484 source_rect.height());
457 sk_source_rect.offset(-image_rect.x(), -image_rect.y()); 485 sk_source_rect.offset(-image_rect.x(), -image_rect.y());
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 DCHECK(texture_id_); 689 DCHECK(texture_id_);
662 } 690 }
663 691
664 ResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() { 692 ResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() {
665 resource_provider_->UnlockForWrite(resource_id_); 693 resource_provider_->UnlockForWrite(resource_id_);
666 } 694 }
667 695
668 void ResourceProvider::PopulateSkBitmapWithResource( 696 void ResourceProvider::PopulateSkBitmapWithResource(
669 SkBitmap* sk_bitmap, const Resource* resource) { 697 SkBitmap* sk_bitmap, const Resource* resource) {
670 DCHECK(resource->pixels); 698 DCHECK(resource->pixels);
671 DCHECK(resource->format == GL_RGBA); 699 DCHECK_EQ(RGBA_8888, resource->format);
672 sk_bitmap->setConfig(SkBitmap::kARGB_8888_Config, 700 sk_bitmap->setConfig(SkBitmap::kARGB_8888_Config,
673 resource->size.width(), 701 resource->size.width(),
674 resource->size.height()); 702 resource->size.height());
675 sk_bitmap->setPixels(resource->pixels); 703 sk_bitmap->setPixels(resource->pixels);
676 } 704 }
677 705
678 ResourceProvider::ScopedReadLockSoftware::ScopedReadLockSoftware( 706 ResourceProvider::ScopedReadLockSoftware::ScopedReadLockSoftware(
679 ResourceProvider* resource_provider, 707 ResourceProvider* resource_provider,
680 ResourceProvider::ResourceId resource_id) 708 ResourceProvider::ResourceId resource_id)
681 : resource_provider_(resource_provider), 709 : resource_provider_(resource_provider),
(...skipping 14 matching lines...) Expand all
696 ResourceProvider::PopulateSkBitmapWithResource( 724 ResourceProvider::PopulateSkBitmapWithResource(
697 &sk_bitmap_, resource_provider->LockForWrite(resource_id)); 725 &sk_bitmap_, resource_provider->LockForWrite(resource_id));
698 sk_canvas_.reset(new SkCanvas(sk_bitmap_)); 726 sk_canvas_.reset(new SkCanvas(sk_bitmap_));
699 } 727 }
700 728
701 ResourceProvider::ScopedWriteLockSoftware::~ScopedWriteLockSoftware() { 729 ResourceProvider::ScopedWriteLockSoftware::~ScopedWriteLockSoftware() {
702 resource_provider_->UnlockForWrite(resource_id_); 730 resource_provider_->UnlockForWrite(resource_id_);
703 } 731 }
704 732
705 ResourceProvider::ResourceProvider(OutputSurface* output_surface, 733 ResourceProvider::ResourceProvider(OutputSurface* output_surface,
706 int highp_threshold_min) 734 int highp_threshold_min,
735 bool use_rgba_4444_texture_format)
707 : output_surface_(output_surface), 736 : output_surface_(output_surface),
708 lost_output_surface_(false), 737 lost_output_surface_(false),
709 highp_threshold_min_(highp_threshold_min), 738 highp_threshold_min_(highp_threshold_min),
710 next_id_(1), 739 next_id_(1),
711 next_child_(1), 740 next_child_(1),
712 default_resource_type_(InvalidType), 741 default_resource_type_(InvalidType),
713 use_texture_storage_ext_(false), 742 use_texture_storage_ext_(false),
714 use_texture_usage_hint_(false), 743 use_texture_usage_hint_(false),
715 use_shallow_flush_(false), 744 use_shallow_flush_(false),
716 max_texture_size_(0), 745 max_texture_size_(0),
717 best_texture_format_(0) { 746 best_texture_format_(RGBA_8888),
747 use_rgba_4444_texture_format_(use_rgba_4444_texture_format) {
718 DCHECK(output_surface_->HasClient()); 748 DCHECK(output_surface_->HasClient());
719 } 749 }
720 750
721 void ResourceProvider::InitializeSoftware() { 751 void ResourceProvider::InitializeSoftware() {
722 DCHECK(thread_checker_.CalledOnValidThread()); 752 DCHECK(thread_checker_.CalledOnValidThread());
723 DCHECK_NE(Bitmap, default_resource_type_); 753 DCHECK_NE(Bitmap, default_resource_type_);
724 754
725 CleanUpGLIfNeeded(); 755 CleanUpGLIfNeeded();
726 756
727 default_resource_type_ = Bitmap; 757 default_resource_type_ = Bitmap;
728 max_texture_size_ = INT_MAX / 2; 758 max_texture_size_ = INT_MAX / 2;
729 best_texture_format_ = GL_RGBA; 759 best_texture_format_ = RGBA_8888;
730 } 760 }
731 761
732 bool ResourceProvider::InitializeGL() { 762 bool ResourceProvider::InitializeGL() {
733 DCHECK(thread_checker_.CalledOnValidThread()); 763 DCHECK(thread_checker_.CalledOnValidThread());
734 DCHECK(!texture_uploader_); 764 DCHECK(!texture_uploader_);
735 DCHECK_NE(GLTexture, default_resource_type_); 765 DCHECK_NE(GLTexture, default_resource_type_);
736 766
737 WebGraphicsContext3D* context3d = Context3d(); 767 WebGraphicsContext3D* context3d = Context3d();
738 DCHECK(context3d); 768 DCHECK(context3d);
739 769
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 // deadlocks and/or security issues. The caller is responsible for 950 // deadlocks and/or security issues. The caller is responsible for
921 // waiting asynchronously, and resetting sync_point before calling this. 951 // waiting asynchronously, and resetting sync_point before calling this.
922 // However if the parent is a renderer (e.g. browser tag), it may be ok 952 // However if the parent is a renderer (e.g. browser tag), it may be ok
923 // (and is simpler) to wait. 953 // (and is simpler) to wait.
924 if (it->sync_point) 954 if (it->sync_point)
925 GLC(context3d, context3d->waitSyncPoint(it->sync_point)); 955 GLC(context3d, context3d->waitSyncPoint(it->sync_point));
926 GLC(context3d, texture_id = context3d->createTexture()); 956 GLC(context3d, texture_id = context3d->createTexture());
927 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, texture_id)); 957 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, texture_id));
928 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, 958 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D,
929 it->mailbox.name)); 959 it->mailbox.name));
960
930 ResourceId id = next_id_++; 961 ResourceId id = next_id_++;
931 Resource resource( 962 Resource resource(
932 texture_id, it->size, it->format, it->filter, 0, GL_CLAMP_TO_EDGE, 963 texture_id,
933 TextureUsageAny); 964 it->size,
965 it->filter,
966 0,
967 GL_CLAMP_TO_EDGE,
968 TextureUsageAny,
969 it->format);
934 resource.mailbox.SetName(it->mailbox); 970 resource.mailbox.SetName(it->mailbox);
935 // Don't allocate a texture for a child. 971 // Don't allocate a texture for a child.
936 resource.allocated = true; 972 resource.allocated = true;
937 resource.imported_count = 1; 973 resource.imported_count = 1;
938 resources_[id] = resource; 974 resources_[id] = resource;
939 child_info.parent_to_child_map[id] = it->id; 975 child_info.parent_to_child_map[id] = it->id;
940 child_info.child_to_parent_map[it->id] = id; 976 child_info.child_to_parent_map[it->id] = id;
941 } 977 }
942 } 978 }
943 979
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 DCHECK(!resource->image_id); 1049 DCHECK(!resource->image_id);
1014 1050
1015 if (resource->type == GLTexture) { 1051 if (resource->type == GLTexture) {
1016 WebGraphicsContext3D* context3d = Context3d(); 1052 WebGraphicsContext3D* context3d = Context3d();
1017 DCHECK(context3d); 1053 DCHECK(context3d);
1018 if (!resource->gl_pixel_buffer_id) 1054 if (!resource->gl_pixel_buffer_id)
1019 resource->gl_pixel_buffer_id = context3d->createBuffer(); 1055 resource->gl_pixel_buffer_id = context3d->createBuffer();
1020 context3d->bindBuffer( 1056 context3d->bindBuffer(
1021 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 1057 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
1022 resource->gl_pixel_buffer_id); 1058 resource->gl_pixel_buffer_id);
1059 size_t bytes_per_pixel = BytesPerPixel(resource->format);
1023 context3d->bufferData( 1060 context3d->bufferData(
1024 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 1061 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
1025 4 * resource->size.GetArea(), 1062 bytes_per_pixel * resource->size.GetArea(),
reveman 2013/09/17 22:09:38 Please change this to "resource->size.height() * R
kaanb 2013/09/17 22:40:01 Done.
1026 NULL, 1063 NULL,
1027 GL_DYNAMIC_DRAW); 1064 GL_DYNAMIC_DRAW);
1028 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); 1065 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0);
1029 } 1066 }
1030 1067
1031 if (resource->pixels) { 1068 if (resource->pixels) {
1032 if (resource->pixel_buffer) 1069 if (resource->pixel_buffer)
1033 return; 1070 return;
1034 1071
1035 resource->pixel_buffer = new uint8_t[4 * resource->size.GetArea()]; 1072 resource->pixel_buffer = new uint8_t[4 * resource->size.GetArea()];
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
1191 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id); 1228 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id);
1192 context3d->bindBuffer( 1229 context3d->bindBuffer(
1193 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 1230 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
1194 resource->gl_pixel_buffer_id); 1231 resource->gl_pixel_buffer_id);
1195 if (!resource->gl_upload_query_id) 1232 if (!resource->gl_upload_query_id)
1196 resource->gl_upload_query_id = context3d->createQueryEXT(); 1233 resource->gl_upload_query_id = context3d->createQueryEXT();
1197 context3d->beginQueryEXT( 1234 context3d->beginQueryEXT(
1198 GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM, 1235 GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM,
1199 resource->gl_upload_query_id); 1236 resource->gl_upload_query_id);
1200 if (allocate) { 1237 if (allocate) {
1201 context3d->asyncTexImage2DCHROMIUM(GL_TEXTURE_2D, 1238 context3d->asyncTexImage2DCHROMIUM(
1202 0, /* level */ 1239 GL_TEXTURE_2D,
1203 resource->format, 1240 0, /* level */
1204 resource->size.width(), 1241 GetGLInternalFormat(resource->format),
1205 resource->size.height(), 1242 resource->size.width(),
1206 0, /* border */ 1243 resource->size.height(),
1207 resource->format, 1244 0, /* border */
1208 GL_UNSIGNED_BYTE, 1245 GetGLDataFormat(resource->format),
1209 NULL); 1246 GetGLDataType(resource->format),
1247 NULL);
1210 } else { 1248 } else {
1211 context3d->asyncTexSubImage2DCHROMIUM(GL_TEXTURE_2D, 1249 context3d->asyncTexSubImage2DCHROMIUM(
1212 0, /* level */ 1250 GL_TEXTURE_2D,
1213 0, /* x */ 1251 0, /* level */
1214 0, /* y */ 1252 0, /* x */
1215 resource->size.width(), 1253 0, /* y */
1216 resource->size.height(), 1254 resource->size.width(),
1217 resource->format, 1255 resource->size.height(),
1218 GL_UNSIGNED_BYTE, 1256 GetGLDataFormat(resource->format),
1219 NULL); 1257 GetGLDataType(resource->format),
1258 NULL);
1220 } 1259 }
1221 context3d->endQueryEXT(GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM); 1260 context3d->endQueryEXT(GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM);
1222 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); 1261 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0);
1223 } 1262 }
1224 1263
1225 if (resource->pixels) { 1264 if (resource->pixels) {
1226 DCHECK(!resource->mailbox.IsValid()); 1265 DCHECK(!resource->mailbox.IsValid());
1227 DCHECK(resource->pixel_buffer); 1266 DCHECK(resource->pixel_buffer);
1228 DCHECK(resource->format == GL_RGBA); 1267 DCHECK_EQ(RGBA_8888, resource->format);
1229 1268
1230 std::swap(resource->pixels, resource->pixel_buffer); 1269 std::swap(resource->pixels, resource->pixel_buffer);
1231 delete[] resource->pixel_buffer; 1270 delete[] resource->pixel_buffer;
1232 resource->pixel_buffer = NULL; 1271 resource->pixel_buffer = NULL;
1233 } 1272 }
1234 1273
1235 resource->pending_set_pixels = true; 1274 resource->pending_set_pixels = true;
1236 resource->set_pixels_completion_forced = false; 1275 resource->set_pixels_completion_forced = false;
1237 } 1276 }
1238 1277
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1324 void ResourceProvider::LazyAllocate(Resource* resource) { 1363 void ResourceProvider::LazyAllocate(Resource* resource) {
1325 DCHECK(resource); 1364 DCHECK(resource);
1326 LazyCreate(resource); 1365 LazyCreate(resource);
1327 1366
1328 DCHECK(resource->gl_id || resource->allocated); 1367 DCHECK(resource->gl_id || resource->allocated);
1329 if (resource->allocated || !resource->gl_id) 1368 if (resource->allocated || !resource->gl_id)
1330 return; 1369 return;
1331 resource->allocated = true; 1370 resource->allocated = true;
1332 WebGraphicsContext3D* context3d = Context3d(); 1371 WebGraphicsContext3D* context3d = Context3d();
1333 gfx::Size& size = resource->size; 1372 gfx::Size& size = resource->size;
1334 GLenum format = resource->format; 1373 ResourceFormat format = resource->format;
1335 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id)); 1374 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id));
1336 if (use_texture_storage_ext_ && IsTextureFormatSupportedForStorage(format)) { 1375 if (use_texture_storage_ext_ && IsFormatSupportedForStorage(format)) {
1337 GLenum storage_format = TextureToStorageFormat(format); 1376 GLenum storage_format = TextureToStorageFormat(format);
1338 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, 1377 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D,
1339 1, 1378 1,
1340 storage_format, 1379 storage_format,
1341 size.width(), 1380 size.width(),
1342 size.height())); 1381 size.height()));
1343 } else { 1382 } else {
1344 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, 1383 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D,
1345 0, 1384 0,
1346 format, 1385 GetGLInternalFormat(format),
1347 size.width(), 1386 size.width(),
1348 size.height(), 1387 size.height(),
1349 0, 1388 0,
1350 format, 1389 GetGLDataFormat(format),
1351 GL_UNSIGNED_BYTE, 1390 GetGLDataType(format),
1352 NULL)); 1391 NULL));
1353 } 1392 }
1354 } 1393 }
1355 1394
1356 void ResourceProvider::EnableReadLockFences(ResourceProvider::ResourceId id, 1395 void ResourceProvider::EnableReadLockFences(ResourceProvider::ResourceId id,
1357 bool enable) { 1396 bool enable) {
1358 Resource* resource = GetResource(id); 1397 Resource* resource = GetResource(id);
1359 resource->enable_read_lock_fences = enable; 1398 resource->enable_read_lock_fences = enable;
1360 } 1399 }
1361 1400
1362 void ResourceProvider::AcquireImage(ResourceId id) { 1401 void ResourceProvider::AcquireImage(ResourceId id) {
1363 Resource* resource = GetResource(id); 1402 Resource* resource = GetResource(id);
1364 DCHECK(!resource->external); 1403 DCHECK(!resource->external);
1365 DCHECK_EQ(resource->exported_count, 0); 1404 DCHECK_EQ(resource->exported_count, 0);
1366 1405
1367 if (resource->type != GLTexture) 1406 if (resource->type != GLTexture)
1368 return; 1407 return;
1369 1408
1370 if (resource->image_id) 1409 if (resource->image_id)
1371 return; 1410 return;
1372 1411
1373 resource->allocated = true; 1412 resource->allocated = true;
1374 WebGraphicsContext3D* context3d = Context3d(); 1413 WebGraphicsContext3D* context3d = Context3d();
1375 DCHECK(context3d); 1414 DCHECK(context3d);
1376 DCHECK_EQ(static_cast<GLenum>(GL_RGBA), resource->format); 1415 DCHECK_EQ(RGBA_8888, resource->format);
1377 resource->image_id = context3d->createImageCHROMIUM( 1416 resource->image_id = context3d->createImageCHROMIUM(
1378 resource->size.width(), resource->size.height(), GL_RGBA8_OES); 1417 resource->size.width(), resource->size.height(), GL_RGBA8_OES);
1379 DCHECK(resource->image_id); 1418 DCHECK(resource->image_id);
1380 } 1419 }
1381 1420
1382 void ResourceProvider::ReleaseImage(ResourceId id) { 1421 void ResourceProvider::ReleaseImage(ResourceId id) {
1383 Resource* resource = GetResource(id); 1422 Resource* resource = GetResource(id);
1384 DCHECK(!resource->external); 1423 DCHECK(!resource->external);
1385 DCHECK_EQ(resource->exported_count, 0); 1424 DCHECK_EQ(resource->exported_count, 0);
1386 1425
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1446 GLint active_unit = 0; 1485 GLint active_unit = 0;
1447 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit); 1486 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit);
1448 return active_unit; 1487 return active_unit;
1449 } 1488 }
1450 1489
1451 WebKit::WebGraphicsContext3D* ResourceProvider::Context3d() const { 1490 WebKit::WebGraphicsContext3D* ResourceProvider::Context3d() const {
1452 ContextProvider* context_provider = output_surface_->context_provider(); 1491 ContextProvider* context_provider = output_surface_->context_provider();
1453 return context_provider ? context_provider->Context3d() : NULL; 1492 return context_provider ? context_provider->Context3d() : NULL;
1454 } 1493 }
1455 1494
1495 size_t ResourceProvider::BytesPerPixel(ResourceFormat format) {
1496 size_t components_per_pixel = 0;
1497 switch (format) {
1498 case RGBA_8888:
1499 case RGBA_4444:
1500 case BGRA_8888:
1501 components_per_pixel = 4;
1502 break;
1503 case LUMINANCE_8:
1504 components_per_pixel = 1;
1505 break;
1506 }
1507 size_t bits_per_component = 0;
1508 switch (format) {
1509 case RGBA_8888:
1510 case BGRA_8888:
1511 case LUMINANCE_8:
1512 bits_per_component = 8;
1513 break;
1514 case RGBA_4444:
1515 bits_per_component = 4;
1516 break;
1517 }
1518 const size_t kBitsPerByte = 8;
1519 return (components_per_pixel * bits_per_component) / kBitsPerByte;
1520 }
1521
1522 GLenum ResourceProvider::GetGLDataType(ResourceFormat format) {
1523 switch (format) {
1524 case RGBA_4444:
1525 return GL_UNSIGNED_SHORT_4_4_4_4;
1526 case RGBA_8888:
1527 case BGRA_8888:
1528 case LUMINANCE_8:
1529 return GL_UNSIGNED_BYTE;
1530 }
1531 NOTREACHED();
1532 return GL_UNSIGNED_BYTE;
1533 }
1534
1535 GLenum ResourceProvider::GetGLDataFormat(ResourceFormat format) {
1536 switch (format) {
1537 case RGBA_8888:
1538 case RGBA_4444:
1539 return GL_RGBA;
1540 case BGRA_8888:
1541 return GL_BGRA_EXT;
1542 case LUMINANCE_8:
1543 return GL_LUMINANCE;
1544 }
1545 NOTREACHED();
1546 return GL_RGBA;
1547 }
1548
1549 GLenum ResourceProvider::GetGLInternalFormat(ResourceFormat format) {
1550 return GetGLDataFormat(format);
1551 }
1552
1456 } // namespace cc 1553 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698