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

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

Issue 135273008: cc: Use ResourceProvider::Resouce::type to check the type of the given resource. (Closed) Base URL: https://git.chromium.org/chromium/src.git@master
Patch Set: In addition, clarify texture_pool Created 6 years, 10 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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 target(0), 183 target(0),
184 original_filter(0), 184 original_filter(0),
185 filter(0), 185 filter(0),
186 image_id(0), 186 image_id(0),
187 bound_image_id(0), 187 bound_image_id(0),
188 dirty_image(false), 188 dirty_image(false),
189 texture_pool(0), 189 texture_pool(0),
190 wrap_mode(0), 190 wrap_mode(0),
191 lost(false), 191 lost(false),
192 hint(TextureUsageAny), 192 hint(TextureUsageAny),
193 type(static_cast<ResourceType>(0)), 193 type(InvalidType),
194 format(RGBA_8888), 194 format(RGBA_8888),
195 shared_bitmap(NULL) {} 195 shared_bitmap(NULL) {}
196 196
197 ResourceProvider::Resource::~Resource() {} 197 ResourceProvider::Resource::~Resource() {}
198 198
199 ResourceProvider::Resource::Resource(GLuint texture_id, 199 ResourceProvider::Resource::Resource(GLuint texture_id,
200 gfx::Size size, 200 gfx::Size size,
201 Origin origin,
201 GLenum target, 202 GLenum target,
202 GLenum filter, 203 GLenum filter,
203 GLenum texture_pool, 204 GLenum texture_pool,
204 GLint wrap_mode, 205 GLint wrap_mode,
205 TextureUsageHint hint, 206 TextureUsageHint hint,
206 ResourceFormat format) 207 ResourceFormat format)
207 : child_id(0), 208 : child_id(0),
208 gl_id(texture_id), 209 gl_id(texture_id),
209 gl_pixel_buffer_id(0), 210 gl_pixel_buffer_id(0),
210 gl_upload_query_id(0), 211 gl_upload_query_id(0),
211 pixels(NULL), 212 pixels(NULL),
212 pixel_buffer(NULL), 213 pixel_buffer(NULL),
213 lock_for_read_count(0), 214 lock_for_read_count(0),
214 imported_count(0), 215 imported_count(0),
215 exported_count(0), 216 exported_count(0),
216 locked_for_write(false), 217 locked_for_write(false),
217 origin(Internal), 218 origin(origin),
218 marked_for_deletion(false), 219 marked_for_deletion(false),
219 pending_set_pixels(false), 220 pending_set_pixels(false),
220 set_pixels_completion_forced(false), 221 set_pixels_completion_forced(false),
221 allocated(false), 222 allocated(false),
222 enable_read_lock_fences(false), 223 enable_read_lock_fences(false),
223 read_lock_fence(NULL), 224 read_lock_fence(NULL),
224 size(size), 225 size(size),
225 target(target), 226 target(target),
226 original_filter(filter), 227 original_filter(filter),
227 filter(filter), 228 filter(filter),
228 image_id(0), 229 image_id(0),
229 bound_image_id(0), 230 bound_image_id(0),
230 dirty_image(false), 231 dirty_image(false),
231 texture_pool(texture_pool), 232 texture_pool(texture_pool),
232 wrap_mode(wrap_mode), 233 wrap_mode(wrap_mode),
233 lost(false), 234 lost(false),
234 hint(hint), 235 hint(hint),
235 type(GLTexture), 236 type(GLTexture),
236 format(format), 237 format(format),
237 shared_bitmap(NULL) { 238 shared_bitmap(NULL) {
238 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); 239 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT);
240 DCHECK(texture_pool || origin != Internal);
dshwang 2014/01/28 20:35:36 For this DCHECK, I change the constructor.
danakj 2014/01/28 21:59:02 DCHECK_EQ(origin == Internal, !!texture_pool) ?
239 } 241 }
240 242
241 ResourceProvider::Resource::Resource(uint8_t* pixels, 243 ResourceProvider::Resource::Resource(uint8_t* pixels,
242 SharedBitmap* bitmap, 244 SharedBitmap* bitmap,
243 gfx::Size size, 245 gfx::Size size,
246 Origin origin,
244 GLenum filter, 247 GLenum filter,
245 GLint wrap_mode) 248 GLint wrap_mode)
246 : child_id(0), 249 : child_id(0),
247 gl_id(0), 250 gl_id(0),
248 gl_pixel_buffer_id(0), 251 gl_pixel_buffer_id(0),
249 gl_upload_query_id(0), 252 gl_upload_query_id(0),
250 pixels(pixels), 253 pixels(pixels),
251 pixel_buffer(NULL), 254 pixel_buffer(NULL),
252 lock_for_read_count(0), 255 lock_for_read_count(0),
253 imported_count(0), 256 imported_count(0),
254 exported_count(0), 257 exported_count(0),
255 locked_for_write(false), 258 locked_for_write(false),
256 origin(Internal), 259 origin(origin),
257 marked_for_deletion(false), 260 marked_for_deletion(false),
258 pending_set_pixels(false), 261 pending_set_pixels(false),
259 set_pixels_completion_forced(false), 262 set_pixels_completion_forced(false),
260 allocated(false), 263 allocated(false),
261 enable_read_lock_fences(false), 264 enable_read_lock_fences(false),
262 read_lock_fence(NULL), 265 read_lock_fence(NULL),
263 size(size), 266 size(size),
264 target(0), 267 target(0),
265 original_filter(filter), 268 original_filter(filter),
266 filter(filter), 269 filter(filter),
267 image_id(0), 270 image_id(0),
268 bound_image_id(0), 271 bound_image_id(0),
269 dirty_image(false), 272 dirty_image(false),
270 texture_pool(0), 273 texture_pool(0),
271 wrap_mode(wrap_mode), 274 wrap_mode(wrap_mode),
272 lost(false), 275 lost(false),
273 hint(TextureUsageAny), 276 hint(TextureUsageAny),
274 type(Bitmap), 277 type(Bitmap),
275 format(RGBA_8888), 278 format(RGBA_8888),
276 shared_bitmap(bitmap) { 279 shared_bitmap(bitmap) {
277 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); 280 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT);
281 DCHECK(pixels);
278 } 282 }
279 283
280 ResourceProvider::Child::Child() : marked_for_deletion(false) {} 284 ResourceProvider::Child::Child() : marked_for_deletion(false) {}
281 285
282 ResourceProvider::Child::~Child() {} 286 ResourceProvider::Child::~Child() {}
283 287
284 scoped_ptr<ResourceProvider> ResourceProvider::Create( 288 scoped_ptr<ResourceProvider> ResourceProvider::Create(
285 OutputSurface* output_surface, 289 OutputSurface* output_surface,
286 SharedBitmapManager* shared_bitmap_manager, 290 SharedBitmapManager* shared_bitmap_manager,
287 int highp_threshold_min, 291 int highp_threshold_min,
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 GLenum target, 389 GLenum target,
386 GLenum texture_pool, 390 GLenum texture_pool,
387 GLint wrap_mode, 391 GLint wrap_mode,
388 TextureUsageHint hint, 392 TextureUsageHint hint,
389 ResourceFormat format) { 393 ResourceFormat format) {
390 DCHECK_LE(size.width(), max_texture_size_); 394 DCHECK_LE(size.width(), max_texture_size_);
391 DCHECK_LE(size.height(), max_texture_size_); 395 DCHECK_LE(size.height(), max_texture_size_);
392 DCHECK(thread_checker_.CalledOnValidThread()); 396 DCHECK(thread_checker_.CalledOnValidThread());
393 397
394 ResourceId id = next_id_++; 398 ResourceId id = next_id_++;
395 Resource resource( 399 Resource resource(0,
396 0, size, target, GL_LINEAR, texture_pool, wrap_mode, hint, format); 400 size,
401 Resource::Internal,
402 target,
403 GL_LINEAR,
404 texture_pool,
405 wrap_mode,
406 hint,
407 format);
397 resource.allocated = false; 408 resource.allocated = false;
398 resources_[id] = resource; 409 resources_[id] = resource;
399 return id; 410 return id;
400 } 411 }
401 412
402 ResourceProvider::ResourceId ResourceProvider::CreateBitmap( 413 ResourceProvider::ResourceId ResourceProvider::CreateBitmap(
403 gfx::Size size, GLint wrap_mode) { 414 gfx::Size size, GLint wrap_mode) {
404 DCHECK(thread_checker_.CalledOnValidThread()); 415 DCHECK(thread_checker_.CalledOnValidThread());
405 416
406 scoped_ptr<SharedBitmap> bitmap; 417 scoped_ptr<SharedBitmap> bitmap;
407 if (shared_bitmap_manager_) 418 if (shared_bitmap_manager_)
408 bitmap = shared_bitmap_manager_->AllocateSharedBitmap(size); 419 bitmap = shared_bitmap_manager_->AllocateSharedBitmap(size);
409 420
410 uint8_t* pixels; 421 uint8_t* pixels;
411 if (bitmap) 422 if (bitmap)
412 pixels = bitmap->pixels(); 423 pixels = bitmap->pixels();
413 else 424 else
414 pixels = new uint8_t[4 * size.GetArea()]; 425 pixels = new uint8_t[4 * size.GetArea()];
415 426
416 ResourceId id = next_id_++; 427 ResourceId id = next_id_++;
417 Resource resource( 428 Resource resource(
418 pixels, bitmap.release(), size, GL_LINEAR, wrap_mode); 429 pixels, bitmap.release(), size, Resource::Internal, GL_LINEAR, wrap_mode);
419 resource.allocated = true; 430 resource.allocated = true;
420 resources_[id] = resource; 431 resources_[id] = resource;
421 return id; 432 return id;
422 } 433 }
423 434
424 ResourceProvider::ResourceId 435 ResourceProvider::ResourceId
425 ResourceProvider::CreateResourceFromExternalTexture( 436 ResourceProvider::CreateResourceFromExternalTexture(
426 GLuint texture_target, 437 GLuint texture_target,
427 GLuint texture_id) { 438 GLuint texture_id) {
danakj 2014/01/28 21:59:02 Can we DCHECK that texture_id is not 0 here?
428 DCHECK(thread_checker_.CalledOnValidThread()); 439 DCHECK(thread_checker_.CalledOnValidThread());
429 440
430 GLES2Interface* gl = ContextGL(); 441 GLES2Interface* gl = ContextGL();
431 DCHECK(gl); 442 DCHECK(gl);
432 GLC(gl, gl->BindTexture(texture_target, texture_id)); 443 GLC(gl, gl->BindTexture(texture_target, texture_id));
433 GLC(gl, gl->TexParameteri(texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); 444 GLC(gl, gl->TexParameteri(texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
434 GLC(gl, gl->TexParameteri(texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); 445 GLC(gl, gl->TexParameteri(texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
435 GLC(gl, 446 GLC(gl,
436 gl->TexParameteri(texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); 447 gl->TexParameteri(texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
437 GLC(gl, 448 GLC(gl,
438 gl->TexParameteri(texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); 449 gl->TexParameteri(texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
439 450
440 ResourceId id = next_id_++; 451 ResourceId id = next_id_++;
441 Resource resource(texture_id, 452 Resource resource(texture_id,
442 gfx::Size(), 453 gfx::Size(),
454 Resource::External,
443 texture_target, 455 texture_target,
444 GL_LINEAR, 456 GL_LINEAR,
445 0, 457 0,
446 GL_CLAMP_TO_EDGE, 458 GL_CLAMP_TO_EDGE,
447 TextureUsageAny, 459 TextureUsageAny,
448 RGBA_8888); 460 RGBA_8888);
449 resource.origin = Resource::External;
450 resource.allocated = true; 461 resource.allocated = true;
451 resources_[id] = resource; 462 resources_[id] = resource;
452 return id; 463 return id;
453 } 464 }
454 465
455 ResourceProvider::ResourceId ResourceProvider::CreateResourceFromTextureMailbox( 466 ResourceProvider::ResourceId ResourceProvider::CreateResourceFromTextureMailbox(
456 const TextureMailbox& mailbox, 467 const TextureMailbox& mailbox,
457 scoped_ptr<SingleReleaseCallback> release_callback) { 468 scoped_ptr<SingleReleaseCallback> release_callback) {
458 DCHECK(thread_checker_.CalledOnValidThread()); 469 DCHECK(thread_checker_.CalledOnValidThread());
459 // Just store the information. Mailbox will be consumed in LockForRead(). 470 // Just store the information. Mailbox will be consumed in LockForRead().
460 ResourceId id = next_id_++; 471 ResourceId id = next_id_++;
461 DCHECK(mailbox.IsValid()); 472 DCHECK(mailbox.IsValid());
462 Resource& resource = resources_[id]; 473 Resource& resource = resources_[id];
463 if (mailbox.IsTexture()) { 474 if (mailbox.IsTexture()) {
464 resource = Resource(0, 475 resource = Resource(0,
465 gfx::Size(), 476 gfx::Size(),
477 Resource::External,
466 mailbox.target(), 478 mailbox.target(),
467 GL_LINEAR, 479 GL_LINEAR,
468 0, 480 0,
469 GL_CLAMP_TO_EDGE, 481 GL_CLAMP_TO_EDGE,
470 TextureUsageAny, 482 TextureUsageAny,
471 RGBA_8888); 483 RGBA_8888);
472 } else { 484 } else {
473 DCHECK(mailbox.IsSharedMemory()); 485 DCHECK(mailbox.IsSharedMemory());
474 base::SharedMemory* shared_memory = mailbox.shared_memory(); 486 base::SharedMemory* shared_memory = mailbox.shared_memory();
475 DCHECK(shared_memory->memory()); 487 DCHECK(shared_memory->memory());
476 uint8_t* pixels = reinterpret_cast<uint8_t*>(shared_memory->memory()); 488 uint8_t* pixels = reinterpret_cast<uint8_t*>(shared_memory->memory());
477 scoped_ptr<SharedBitmap> shared_bitmap; 489 scoped_ptr<SharedBitmap> shared_bitmap;
478 if (shared_bitmap_manager_) { 490 if (shared_bitmap_manager_) {
479 shared_bitmap = 491 shared_bitmap =
480 shared_bitmap_manager_->GetBitmapForSharedMemory(shared_memory); 492 shared_bitmap_manager_->GetBitmapForSharedMemory(shared_memory);
481 } 493 }
482 resource = Resource(pixels, 494 resource = Resource(pixels,
483 shared_bitmap.release(), 495 shared_bitmap.release(),
484 mailbox.shared_memory_size(), 496 mailbox.shared_memory_size(),
497 Resource::External,
485 GL_LINEAR, 498 GL_LINEAR,
486 GL_CLAMP_TO_EDGE); 499 GL_CLAMP_TO_EDGE);
487 } 500 }
488 resource.origin = Resource::External;
489 resource.allocated = true; 501 resource.allocated = true;
490 resource.mailbox = mailbox; 502 resource.mailbox = mailbox;
491 resource.release_callback = 503 resource.release_callback =
492 base::Bind(&SingleReleaseCallback::Run, 504 base::Bind(&SingleReleaseCallback::Run,
493 base::Owned(release_callback.release())); 505 base::Owned(release_callback.release()));
494 return id; 506 return id;
495 } 507 }
496 508
497 void ResourceProvider::DeleteResource(ResourceId id) { 509 void ResourceProvider::DeleteResource(ResourceId id) {
498 DCHECK(thread_checker_.CalledOnValidThread()); 510 DCHECK(thread_checker_.CalledOnValidThread());
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 GLC(gl, gl->DeleteQueriesEXT(1, &resource->gl_upload_query_id)); 548 GLC(gl, gl->DeleteQueriesEXT(1, &resource->gl_upload_query_id));
537 } 549 }
538 if (resource->gl_pixel_buffer_id) { 550 if (resource->gl_pixel_buffer_id) {
539 DCHECK(resource->origin == Resource::Internal); 551 DCHECK(resource->origin == Resource::Internal);
540 GLES2Interface* gl = ContextGL(); 552 GLES2Interface* gl = ContextGL();
541 DCHECK(gl); 553 DCHECK(gl);
542 GLC(gl, gl->DeleteBuffers(1, &resource->gl_pixel_buffer_id)); 554 GLC(gl, gl->DeleteBuffers(1, &resource->gl_pixel_buffer_id));
543 } 555 }
544 if (resource->mailbox.IsValid() && resource->origin == Resource::External) { 556 if (resource->mailbox.IsValid() && resource->origin == Resource::External) {
545 GLuint sync_point = resource->mailbox.sync_point(); 557 GLuint sync_point = resource->mailbox.sync_point();
546 if (resource->mailbox.IsTexture()) { 558 if (resource->type == GLTexture) {
559 DCHECK(resource->mailbox.IsTexture());
547 lost_resource |= lost_output_surface_; 560 lost_resource |= lost_output_surface_;
548 GLES2Interface* gl = ContextGL(); 561 GLES2Interface* gl = ContextGL();
549 DCHECK(gl); 562 DCHECK(gl);
550 if (resource->gl_id) { 563 if (resource->gl_id) {
551 GLC(gl, gl->DeleteTextures(1, &resource->gl_id)); 564 GLC(gl, gl->DeleteTextures(1, &resource->gl_id));
552 resource->gl_id = 0; 565 resource->gl_id = 0;
553 if (!lost_resource) 566 if (!lost_resource)
554 sync_point = gl->InsertSyncPointCHROMIUM(); 567 sync_point = gl->InsertSyncPointCHROMIUM();
555 } 568 }
556 } else { 569 } else {
557 DCHECK(resource->mailbox.IsSharedMemory()); 570 DCHECK(resource->mailbox.IsSharedMemory());
558 base::SharedMemory* shared_memory = resource->mailbox.shared_memory(); 571 base::SharedMemory* shared_memory = resource->mailbox.shared_memory();
559 if (resource->pixels && shared_memory) { 572 if (resource->pixels && shared_memory) {
560 DCHECK(shared_memory->memory() == resource->pixels); 573 DCHECK(shared_memory->memory() == resource->pixels);
561 resource->pixels = NULL; 574 resource->pixels = NULL;
562 delete resource->shared_bitmap; 575 delete resource->shared_bitmap;
563 resource->shared_bitmap = NULL; 576 resource->shared_bitmap = NULL;
564 } 577 }
565 } 578 }
566 resource->release_callback.Run(sync_point, lost_resource); 579 resource->release_callback.Run(sync_point, lost_resource);
567 } 580 }
568 if (resource->gl_id && resource->origin != Resource::External) { 581 if (resource->gl_id && resource->origin != Resource::External) {
569 GLES2Interface* gl = ContextGL(); 582 GLES2Interface* gl = ContextGL();
570 DCHECK(gl); 583 DCHECK(gl);
571 GLC(gl, gl->DeleteTextures(1, &resource->gl_id)); 584 GLC(gl, gl->DeleteTextures(1, &resource->gl_id));
572 resource->gl_id = 0; 585 resource->gl_id = 0;
573 } 586 }
574 if (resource->shared_bitmap) { 587 if (resource->shared_bitmap) {
575 DCHECK(resource->origin != Resource::External); 588 DCHECK(resource->origin != Resource::External);
589 DCHECK_EQ(Bitmap, resource->type);
576 delete resource->shared_bitmap; 590 delete resource->shared_bitmap;
577 resource->pixels = NULL; 591 resource->pixels = NULL;
578 } 592 }
579 if (resource->pixels) { 593 if (resource->pixels) {
580 DCHECK(resource->origin == Resource::Internal); 594 DCHECK(resource->origin == Resource::Internal);
581 delete[] resource->pixels; 595 delete[] resource->pixels;
582 } 596 }
583 if (resource->pixel_buffer) { 597 if (resource->pixel_buffer) {
584 DCHECK(resource->origin == Resource::Internal); 598 DCHECK(resource->origin == Resource::Internal);
585 delete[] resource->pixel_buffer; 599 delete[] resource->pixel_buffer;
(...skipping 16 matching lines...) Expand all
602 const gfx::Rect& source_rect, 616 const gfx::Rect& source_rect,
603 gfx::Vector2d dest_offset) { 617 gfx::Vector2d dest_offset) {
604 Resource* resource = GetResource(id); 618 Resource* resource = GetResource(id);
605 DCHECK(!resource->locked_for_write); 619 DCHECK(!resource->locked_for_write);
606 DCHECK(!resource->lock_for_read_count); 620 DCHECK(!resource->lock_for_read_count);
607 DCHECK(resource->origin == Resource::Internal); 621 DCHECK(resource->origin == Resource::Internal);
608 DCHECK_EQ(resource->exported_count, 0); 622 DCHECK_EQ(resource->exported_count, 0);
609 DCHECK(ReadLockFenceHasPassed(resource)); 623 DCHECK(ReadLockFenceHasPassed(resource));
610 LazyAllocate(resource); 624 LazyAllocate(resource);
611 625
612 if (resource->gl_id) { 626 if (resource->type == GLTexture) {
627 DCHECK(resource->gl_id);
613 DCHECK(!resource->pending_set_pixels); 628 DCHECK(!resource->pending_set_pixels);
614 DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D)); 629 DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D));
615 GLES2Interface* gl = ContextGL(); 630 GLES2Interface* gl = ContextGL();
616 DCHECK(gl); 631 DCHECK(gl);
617 DCHECK(texture_uploader_.get()); 632 DCHECK(texture_uploader_.get());
618 gl->BindTexture(GL_TEXTURE_2D, resource->gl_id); 633 gl->BindTexture(GL_TEXTURE_2D, resource->gl_id);
619 texture_uploader_->Upload(image, 634 texture_uploader_->Upload(image,
620 image_rect, 635 image_rect,
621 source_rect, 636 source_rect,
622 dest_offset, 637 dest_offset,
623 resource->format, 638 resource->format,
624 resource->size); 639 resource->size);
625 } 640 } else {
626 641 DCHECK_EQ(Bitmap, resource->type);
627 if (resource->pixels) {
628 DCHECK(resource->allocated); 642 DCHECK(resource->allocated);
629 DCHECK_EQ(RGBA_8888, resource->format); 643 DCHECK_EQ(RGBA_8888, resource->format);
630 SkBitmap src_full; 644 SkBitmap src_full;
631 src_full.setConfig( 645 src_full.setConfig(
632 SkBitmap::kARGB_8888_Config, image_rect.width(), image_rect.height()); 646 SkBitmap::kARGB_8888_Config, image_rect.width(), image_rect.height());
633 src_full.setPixels(const_cast<uint8_t*>(image)); 647 src_full.setPixels(const_cast<uint8_t*>(image));
634 SkBitmap src_subset; 648 SkBitmap src_subset;
635 SkIRect sk_source_rect = SkIRect::MakeXYWH(source_rect.x(), 649 SkIRect sk_source_rect = SkIRect::MakeXYWH(source_rect.x(),
636 source_rect.y(), 650 source_rect.y(),
637 source_rect.width(), 651 source_rect.width(),
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
740 DCHECK(!resource->locked_for_write || 754 DCHECK(!resource->locked_for_write ||
741 resource->set_pixels_completion_forced) << 755 resource->set_pixels_completion_forced) <<
742 "locked for write: " << resource->locked_for_write << 756 "locked for write: " << resource->locked_for_write <<
743 " pixels completion forced: " << resource->set_pixels_completion_forced; 757 " pixels completion forced: " << resource->set_pixels_completion_forced;
744 DCHECK_EQ(resource->exported_count, 0); 758 DCHECK_EQ(resource->exported_count, 0);
745 // Uninitialized! Call SetPixels or LockForWrite first. 759 // Uninitialized! Call SetPixels or LockForWrite first.
746 DCHECK(resource->allocated); 760 DCHECK(resource->allocated);
747 761
748 LazyCreate(resource); 762 LazyCreate(resource);
749 763
750 if (!resource->gl_id && resource->mailbox.IsTexture()) { 764 if (!resource->gl_id && resource->type == GLTexture) {
danakj 2014/01/28 21:59:02 can you reverse these 2 conditions? checking the g
751 DCHECK(resource->origin != Resource::Internal); 765 DCHECK(resource->origin != Resource::Internal);
766 DCHECK(resource->mailbox.IsTexture());
752 GLES2Interface* gl = ContextGL(); 767 GLES2Interface* gl = ContextGL();
753 DCHECK(gl); 768 DCHECK(gl);
754 if (resource->mailbox.sync_point()) { 769 if (resource->mailbox.sync_point()) {
755 GLC(gl, gl->WaitSyncPointCHROMIUM(resource->mailbox.sync_point())); 770 GLC(gl, gl->WaitSyncPointCHROMIUM(resource->mailbox.sync_point()));
756 resource->mailbox.ResetSyncPoint(); 771 resource->mailbox.ResetSyncPoint();
757 } 772 }
758 resource->gl_id = texture_id_allocator_->NextId(); 773 resource->gl_id = texture_id_allocator_->NextId();
759 GLC(gl, gl->BindTexture(resource->target, resource->gl_id)); 774 GLC(gl, gl->BindTexture(resource->target, resource->gl_id));
760 GLC(gl, 775 GLC(gl,
761 gl->ConsumeTextureCHROMIUM(resource->target, 776 gl->ConsumeTextureCHROMIUM(resource->target,
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
1080 TRACE_EVENT0("cc", "ResourceProvider::ReceiveFromChild dropping invalid"); 1095 TRACE_EVENT0("cc", "ResourceProvider::ReceiveFromChild dropping invalid");
1081 ReturnedResourceArray to_return; 1096 ReturnedResourceArray to_return;
1082 to_return.push_back(it->ToReturnedResource()); 1097 to_return.push_back(it->ToReturnedResource());
1083 child_info.return_callback.Run(to_return); 1098 child_info.return_callback.Run(to_return);
1084 continue; 1099 continue;
1085 } 1100 }
1086 1101
1087 ResourceId local_id = next_id_++; 1102 ResourceId local_id = next_id_++;
1088 Resource& resource = resources_[local_id]; 1103 Resource& resource = resources_[local_id];
1089 if (it->is_software) { 1104 if (it->is_software) {
1090 resource = Resource( 1105 resource = Resource(pixels,
1091 pixels, bitmap.release(), it->size, GL_LINEAR, GL_CLAMP_TO_EDGE); 1106 bitmap.release(),
1107 it->size,
1108 Resource::Delegated,
1109 GL_LINEAR,
1110 GL_CLAMP_TO_EDGE);
1092 } else { 1111 } else {
1093 resource = Resource(0, 1112 resource = Resource(0,
1094 it->size, 1113 it->size,
1114 Resource::Delegated,
1095 it->target, 1115 it->target,
1096 it->filter, 1116 it->filter,
1097 0, 1117 0,
1098 GL_CLAMP_TO_EDGE, 1118 GL_CLAMP_TO_EDGE,
1099 TextureUsageAny, 1119 TextureUsageAny,
1100 it->format); 1120 it->format);
1101 resource.mailbox = 1121 resource.mailbox =
1102 TextureMailbox(it->mailbox, it->target, it->sync_point); 1122 TextureMailbox(it->mailbox, it->target, it->sync_point);
1103 } 1123 }
1104 resource.child_id = child; 1124 resource.child_id = child;
1105 resource.origin = Resource::Delegated;
1106 // Don't allocate a texture for a child. 1125 // Don't allocate a texture for a child.
1107 resource.allocated = true; 1126 resource.allocated = true;
1108 resource.imported_count = 1; 1127 resource.imported_count = 1;
1109 child_info.parent_to_child_map[local_id] = it->id; 1128 child_info.parent_to_child_map[local_id] = it->id;
1110 child_info.child_to_parent_map[it->id] = local_id; 1129 child_info.child_to_parent_map[it->id] = local_id;
1111 } 1130 }
1112 } 1131 }
1113 1132
1114 void ResourceProvider::DeclareUsedResourcesFromChild( 1133 void ResourceProvider::DeclareUsedResourcesFromChild(
1115 int child, 1134 int child,
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
1265 source->origin == Resource::Delegated || 1284 source->origin == Resource::Delegated ||
1266 (source->origin == Resource::External && source->mailbox.IsValid())); 1285 (source->origin == Resource::External && source->mailbox.IsValid()));
1267 DCHECK(source->allocated); 1286 DCHECK(source->allocated);
1268 DCHECK_EQ(source->wrap_mode, GL_CLAMP_TO_EDGE); 1287 DCHECK_EQ(source->wrap_mode, GL_CLAMP_TO_EDGE);
1269 resource->id = id; 1288 resource->id = id;
1270 resource->format = source->format; 1289 resource->format = source->format;
1271 resource->target = source->target; 1290 resource->target = source->target;
1272 resource->filter = source->filter; 1291 resource->filter = source->filter;
1273 resource->size = source->size; 1292 resource->size = source->size;
1274 1293
1275 if (source->shared_bitmap) { 1294 if (source->type == Bitmap) {
1295 DCHECK(source->shared_bitmap);
danakj 2014/01/28 21:59:02 given the next line will crash anyway, not sure we
1276 resource->mailbox = source->shared_bitmap->id(); 1296 resource->mailbox = source->shared_bitmap->id();
1277 resource->is_software = true; 1297 resource->is_software = true;
1278 } else if (!source->mailbox.IsValid()) { 1298 } else if (!source->mailbox.IsValid()) {
1279 LazyCreate(source); 1299 LazyCreate(source);
1280 DCHECK(source->gl_id); 1300 DCHECK(source->gl_id);
1281 DCHECK(source->origin == Resource::Internal); 1301 DCHECK(source->origin == Resource::Internal);
1282 GLC(gl, gl->BindTexture(resource->target, source->gl_id)); 1302 GLC(gl, gl->BindTexture(resource->target, source->gl_id));
1283 if (source->image_id) { 1303 if (source->image_id) {
1284 DCHECK(source->dirty_image); 1304 DCHECK(source->dirty_image);
1285 BindImageForSampling(source); 1305 BindImageForSampling(source);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1330 1350
1331 DCHECK(!resource.locked_for_write); 1351 DCHECK(!resource.locked_for_write);
1332 DCHECK(!resource.lock_for_read_count); 1352 DCHECK(!resource.lock_for_read_count);
1333 DCHECK_EQ(0u, child_info->in_use_resources.count(local_id)); 1353 DCHECK_EQ(0u, child_info->in_use_resources.count(local_id));
1334 DCHECK(child_info->parent_to_child_map.count(local_id)); 1354 DCHECK(child_info->parent_to_child_map.count(local_id));
1335 1355
1336 ResourceId child_id = child_info->parent_to_child_map[local_id]; 1356 ResourceId child_id = child_info->parent_to_child_map[local_id];
1337 DCHECK(child_info->child_to_parent_map.count(child_id)); 1357 DCHECK(child_info->child_to_parent_map.count(child_id));
1338 1358
1339 bool is_lost = 1359 bool is_lost =
1340 resource.lost || (!resource.shared_bitmap && lost_output_surface_); 1360 resource.lost ||
1361 (resource.type == GLTexture && lost_output_surface_);
1341 if (resource.exported_count > 0) { 1362 if (resource.exported_count > 0) {
1342 if (style != ForShutdown) { 1363 if (style != ForShutdown) {
1343 // Defer this until we receive the resource back from the parent. 1364 // Defer this until we receive the resource back from the parent.
1344 resource.marked_for_deletion = true; 1365 resource.marked_for_deletion = true;
1345 continue; 1366 continue;
1346 } 1367 }
1347 1368
1348 // We still have an exported_count, so we'll have to lose it. 1369 // We still have an exported_count, so we'll have to lose it.
1349 is_lost = true; 1370 is_lost = true;
1350 } 1371 }
1351 1372
1352 if (gl && resource.filter != resource.original_filter) { 1373 if (gl && resource.filter != resource.original_filter) {
1353 DCHECK(resource.target); 1374 DCHECK(resource.target);
1354 DCHECK(resource.gl_id); 1375 DCHECK(resource.gl_id);
1355 1376
1356 GLC(gl, gl->BindTexture(resource.target, resource.gl_id)); 1377 GLC(gl, gl->BindTexture(resource.target, resource.gl_id));
1357 GLC(gl, 1378 GLC(gl,
1358 gl->TexParameteri(resource.target, 1379 gl->TexParameteri(resource.target,
1359 GL_TEXTURE_MIN_FILTER, 1380 GL_TEXTURE_MIN_FILTER,
1360 resource.original_filter)); 1381 resource.original_filter));
1361 GLC(gl, 1382 GLC(gl,
1362 gl->TexParameteri(resource.target, 1383 gl->TexParameteri(resource.target,
1363 GL_TEXTURE_MAG_FILTER, 1384 GL_TEXTURE_MAG_FILTER,
1364 resource.original_filter)); 1385 resource.original_filter));
1365 } 1386 }
1366 1387
1367 ReturnedResource returned; 1388 ReturnedResource returned;
1368 returned.id = child_id; 1389 returned.id = child_id;
1369 returned.sync_point = resource.mailbox.sync_point(); 1390 returned.sync_point = resource.mailbox.sync_point();
1370 if (!returned.sync_point && !resource.shared_bitmap) 1391 if (!returned.sync_point && resource.type == GLTexture)
1371 need_sync_point = true; 1392 need_sync_point = true;
1372 returned.count = resource.imported_count; 1393 returned.count = resource.imported_count;
1373 returned.lost = is_lost; 1394 returned.lost = is_lost;
1374 to_return.push_back(returned); 1395 to_return.push_back(returned);
1375 1396
1376 child_info->parent_to_child_map.erase(local_id); 1397 child_info->parent_to_child_map.erase(local_id);
1377 child_info->child_to_parent_map.erase(child_id); 1398 child_info->child_to_parent_map.erase(child_id);
1378 resource.imported_count = 0; 1399 resource.imported_count = 0;
1379 DeleteResourceInternal(it, style); 1400 DeleteResourceInternal(it, style);
1380 } 1401 }
(...skipping 30 matching lines...) Expand all
1411 resource->gl_pixel_buffer_id = buffer_id_allocator_->NextId(); 1432 resource->gl_pixel_buffer_id = buffer_id_allocator_->NextId();
1412 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 1433 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
1413 resource->gl_pixel_buffer_id); 1434 resource->gl_pixel_buffer_id);
1414 unsigned bytes_per_pixel = BitsPerPixel(resource->format) / 8; 1435 unsigned bytes_per_pixel = BitsPerPixel(resource->format) / 8;
1415 gl->BufferData(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 1436 gl->BufferData(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
1416 resource->size.height() * 1437 resource->size.height() *
1417 RoundUp(bytes_per_pixel * resource->size.width(), 4u), 1438 RoundUp(bytes_per_pixel * resource->size.width(), 4u),
1418 NULL, 1439 NULL,
1419 GL_DYNAMIC_DRAW); 1440 GL_DYNAMIC_DRAW);
1420 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); 1441 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0);
1421 } 1442 } else {
1422 1443 DCHECK_EQ(Bitmap, resource->type);
1423 if (resource->pixels) {
1424 if (resource->pixel_buffer) 1444 if (resource->pixel_buffer)
1425 return; 1445 return;
1426 1446
1427 resource->pixel_buffer = new uint8_t[4 * resource->size.GetArea()]; 1447 resource->pixel_buffer = new uint8_t[4 * resource->size.GetArea()];
1428 } 1448 }
1429 } 1449 }
1430 1450
1431 void ResourceProvider::ReleasePixelBuffer(ResourceId id) { 1451 void ResourceProvider::ReleasePixelBuffer(ResourceId id) {
1432 Resource* resource = GetResource(id); 1452 Resource* resource = GetResource(id);
1433 DCHECK(resource->origin == Resource::Internal); 1453 DCHECK(resource->origin == Resource::Internal);
(...skipping 15 matching lines...) Expand all
1449 if (resource->type == GLTexture) { 1469 if (resource->type == GLTexture) {
1450 if (!resource->gl_pixel_buffer_id) 1470 if (!resource->gl_pixel_buffer_id)
1451 return; 1471 return;
1452 GLES2Interface* gl = ContextGL(); 1472 GLES2Interface* gl = ContextGL();
1453 DCHECK(gl); 1473 DCHECK(gl);
1454 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 1474 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
1455 resource->gl_pixel_buffer_id); 1475 resource->gl_pixel_buffer_id);
1456 gl->BufferData( 1476 gl->BufferData(
1457 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0, NULL, GL_DYNAMIC_DRAW); 1477 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0, NULL, GL_DYNAMIC_DRAW);
1458 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); 1478 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0);
1459 } 1479 } else {
1460 1480 DCHECK_EQ(Bitmap, resource->type);
1461 if (resource->pixels) {
1462 if (!resource->pixel_buffer) 1481 if (!resource->pixel_buffer)
1463 return; 1482 return;
1464 delete[] resource->pixel_buffer; 1483 delete[] resource->pixel_buffer;
1465 resource->pixel_buffer = NULL; 1484 resource->pixel_buffer = NULL;
1466 } 1485 }
1467 } 1486 }
1468 1487
1469 uint8_t* ResourceProvider::MapPixelBuffer(ResourceId id) { 1488 uint8_t* ResourceProvider::MapPixelBuffer(ResourceId id) {
1470 Resource* resource = GetResource(id); 1489 Resource* resource = GetResource(id);
1471 DCHECK(resource->origin == Resource::Internal); 1490 DCHECK(resource->origin == Resource::Internal);
1472 DCHECK_EQ(resource->exported_count, 0); 1491 DCHECK_EQ(resource->exported_count, 0);
1473 DCHECK(!resource->image_id); 1492 DCHECK(!resource->image_id);
1474 1493
1475 if (resource->type == GLTexture) { 1494 if (resource->type == GLTexture) {
1476 GLES2Interface* gl = ContextGL(); 1495 GLES2Interface* gl = ContextGL();
1477 DCHECK(gl); 1496 DCHECK(gl);
1478 DCHECK(resource->gl_pixel_buffer_id); 1497 DCHECK(resource->gl_pixel_buffer_id);
1479 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 1498 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
1480 resource->gl_pixel_buffer_id); 1499 resource->gl_pixel_buffer_id);
1481 uint8_t* image = static_cast<uint8_t*>(gl->MapBufferCHROMIUM( 1500 uint8_t* image = static_cast<uint8_t*>(gl->MapBufferCHROMIUM(
1482 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, GL_WRITE_ONLY)); 1501 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, GL_WRITE_ONLY));
1483 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); 1502 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0);
1484 // Buffer is required to be 4-byte aligned. 1503 // Buffer is required to be 4-byte aligned.
1485 CHECK(!(reinterpret_cast<intptr_t>(image) & 3)); 1504 CHECK(!(reinterpret_cast<intptr_t>(image) & 3));
1486 return image; 1505 return image;
1487 } 1506 }
1488 1507 DCHECK_EQ(Bitmap, resource->type);
1489 if (resource->pixels) 1508 return resource->pixel_buffer;
1490 return resource->pixel_buffer;
1491
1492 return NULL;
1493 } 1509 }
1494 1510
1495 void ResourceProvider::UnmapPixelBuffer(ResourceId id) { 1511 void ResourceProvider::UnmapPixelBuffer(ResourceId id) {
1496 Resource* resource = GetResource(id); 1512 Resource* resource = GetResource(id);
1497 DCHECK(resource->origin == Resource::Internal); 1513 DCHECK(resource->origin == Resource::Internal);
1498 DCHECK_EQ(resource->exported_count, 0); 1514 DCHECK_EQ(resource->exported_count, 0);
1499 DCHECK(!resource->image_id); 1515 DCHECK(!resource->image_id);
1500 1516
1501 if (resource->type == GLTexture) { 1517 if (resource->type == GLTexture) {
1502 GLES2Interface* gl = ContextGL(); 1518 GLES2Interface* gl = ContextGL();
(...skipping 29 matching lines...) Expand all
1532 1548
1533 if (resource->image_id && resource->dirty_image) 1549 if (resource->image_id && resource->dirty_image)
1534 BindImageForSampling(resource); 1550 BindImageForSampling(resource);
1535 1551
1536 return target; 1552 return target;
1537 } 1553 }
1538 1554
1539 void ResourceProvider::BeginSetPixels(ResourceId id) { 1555 void ResourceProvider::BeginSetPixels(ResourceId id) {
1540 Resource* resource = GetResource(id); 1556 Resource* resource = GetResource(id);
1541 DCHECK(!resource->pending_set_pixels); 1557 DCHECK(!resource->pending_set_pixels);
1542 1558
danakj 2014/01/28 21:59:02 Should we DCHECK the resource has Internal Origin
1543 LazyCreate(resource); 1559 LazyCreate(resource);
1544 DCHECK(resource->gl_id || resource->allocated); 1560 DCHECK(resource->gl_id || resource->allocated);
1545 DCHECK(ReadLockFenceHasPassed(resource)); 1561 DCHECK(ReadLockFenceHasPassed(resource));
1546 DCHECK(!resource->image_id); 1562 DCHECK(!resource->image_id);
1547 1563
1548 bool allocate = !resource->allocated; 1564 bool allocate = !resource->allocated;
1549 resource->allocated = true; 1565 resource->allocated = true;
1550 LockForWrite(id); 1566 LockForWrite(id);
1551 1567
1552 if (resource->gl_id) { 1568 if (resource->type == GLTexture) {
dshwang 2014/01/28 20:35:36 For this change, I changed ResourceProvider::LazyC
1569 DCHECK(resource->gl_id);
1553 GLES2Interface* gl = ContextGL(); 1570 GLES2Interface* gl = ContextGL();
1554 DCHECK(gl); 1571 DCHECK(gl);
1555 DCHECK(resource->gl_pixel_buffer_id); 1572 DCHECK(resource->gl_pixel_buffer_id);
1556 DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D)); 1573 DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D));
1557 gl->BindTexture(GL_TEXTURE_2D, resource->gl_id); 1574 gl->BindTexture(GL_TEXTURE_2D, resource->gl_id);
1558 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 1575 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
1559 resource->gl_pixel_buffer_id); 1576 resource->gl_pixel_buffer_id);
1560 if (!resource->gl_upload_query_id) 1577 if (!resource->gl_upload_query_id)
1561 gl->GenQueriesEXT(1, &resource->gl_upload_query_id); 1578 gl->GenQueriesEXT(1, &resource->gl_upload_query_id);
1562 gl->BeginQueryEXT(GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM, 1579 gl->BeginQueryEXT(GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM,
(...skipping 14 matching lines...) Expand all
1577 0, /* x */ 1594 0, /* x */
1578 0, /* y */ 1595 0, /* y */
1579 resource->size.width(), 1596 resource->size.width(),
1580 resource->size.height(), 1597 resource->size.height(),
1581 GLDataFormat(resource->format), 1598 GLDataFormat(resource->format),
1582 GLDataType(resource->format), 1599 GLDataType(resource->format),
1583 NULL); 1600 NULL);
1584 } 1601 }
1585 gl->EndQueryEXT(GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM); 1602 gl->EndQueryEXT(GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM);
1586 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); 1603 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0);
1587 } 1604 } else {
1588 1605 DCHECK_EQ(Bitmap, resource->type);
1589 if (resource->pixels) {
1590 DCHECK(!resource->mailbox.IsValid()); 1606 DCHECK(!resource->mailbox.IsValid());
1591 DCHECK(resource->pixel_buffer); 1607 DCHECK(resource->pixel_buffer);
1592 DCHECK_EQ(RGBA_8888, resource->format); 1608 DCHECK_EQ(RGBA_8888, resource->format);
1593 1609
1594 std::swap(resource->pixels, resource->pixel_buffer); 1610 std::swap(resource->pixels, resource->pixel_buffer);
1595 delete[] resource->pixel_buffer; 1611 delete[] resource->pixel_buffer;
1596 resource->pixel_buffer = NULL; 1612 resource->pixel_buffer = NULL;
1597 } 1613 }
1598 1614
1599 resource->pending_set_pixels = true; 1615 resource->pending_set_pixels = true;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1641 void ResourceProvider::CreateForTesting(ResourceId id) { 1657 void ResourceProvider::CreateForTesting(ResourceId id) {
1642 LazyCreate(GetResource(id)); 1658 LazyCreate(GetResource(id));
1643 } 1659 }
1644 1660
1645 GLenum ResourceProvider::TargetForTesting(ResourceId id) { 1661 GLenum ResourceProvider::TargetForTesting(ResourceId id) {
1646 Resource* resource = GetResource(id); 1662 Resource* resource = GetResource(id);
1647 return resource->target; 1663 return resource->target;
1648 } 1664 }
1649 1665
1650 void ResourceProvider::LazyCreate(Resource* resource) { 1666 void ResourceProvider::LazyCreate(Resource* resource) {
1651 if (resource->type != GLTexture || resource->gl_id != 0) 1667 if (resource->type != GLTexture || resource->origin != Resource::Internal) {
1668 DCHECK(!resource->texture_pool);
danakj 2014/01/28 21:59:02 I think these DCHECKs can be covered in the constr
1669 return;
1670 }
1671
1672 if (resource->gl_id)
1652 return; 1673 return;
1653 1674
1654 // Early out for resources that don't require texture creation. 1675 DCHECK(resource->texture_pool);
dshwang 2014/01/28 20:35:36 how about the change of LazyCreate()?
1655 if (resource->texture_pool == 0)
1656 return;
1657
1658 DCHECK(resource->origin == Resource::Internal); 1676 DCHECK(resource->origin == Resource::Internal);
1659 DCHECK(!resource->mailbox.IsValid()); 1677 DCHECK(!resource->mailbox.IsValid());
1660 resource->gl_id = texture_id_allocator_->NextId(); 1678 resource->gl_id = texture_id_allocator_->NextId();
1661 1679
1662 GLES2Interface* gl = ContextGL(); 1680 GLES2Interface* gl = ContextGL();
1663 DCHECK(gl); 1681 DCHECK(gl);
1664 1682
1665 // Create and set texture properties. Allocation is delayed until needed. 1683 // Create and set texture properties. Allocation is delayed until needed.
1666 GLC(gl, gl->BindTexture(resource->target, resource->gl_id)); 1684 GLC(gl, gl->BindTexture(resource->target, resource->gl_id));
1667 GLC(gl, 1685 GLC(gl,
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1781 resource->dirty_image = false; 1799 resource->dirty_image = false;
1782 resource->allocated = false; 1800 resource->allocated = false;
1783 } 1801 }
1784 1802
1785 uint8_t* ResourceProvider::MapImage(ResourceId id) { 1803 uint8_t* ResourceProvider::MapImage(ResourceId id) {
1786 Resource* resource = GetResource(id); 1804 Resource* resource = GetResource(id);
1787 DCHECK(ReadLockFenceHasPassed(resource)); 1805 DCHECK(ReadLockFenceHasPassed(resource));
1788 DCHECK(resource->origin == Resource::Internal); 1806 DCHECK(resource->origin == Resource::Internal);
1789 DCHECK_EQ(resource->exported_count, 0); 1807 DCHECK_EQ(resource->exported_count, 0);
1790 1808
1791 if (resource->image_id) { 1809 if (resource->type == GLTexture) {
1810 DCHECK(resource->image_id);
1792 GLES2Interface* gl = ContextGL(); 1811 GLES2Interface* gl = ContextGL();
1793 DCHECK(gl); 1812 DCHECK(gl);
1794 return static_cast<uint8_t*>( 1813 return static_cast<uint8_t*>(
1795 gl->MapImageCHROMIUM(resource->image_id, GL_READ_WRITE)); 1814 gl->MapImageCHROMIUM(resource->image_id, GL_READ_WRITE));
1796 } 1815 }
1797 1816 DCHECK_EQ(Bitmap, resource->type);
1798 if (resource->pixels) 1817 return resource->pixels;
1799 return resource->pixels;
1800
1801 return NULL;
1802 } 1818 }
1803 1819
1804 void ResourceProvider::UnmapImage(ResourceId id) { 1820 void ResourceProvider::UnmapImage(ResourceId id) {
1805 Resource* resource = GetResource(id); 1821 Resource* resource = GetResource(id);
1806 DCHECK(resource->origin == Resource::Internal); 1822 DCHECK(resource->origin == Resource::Internal);
1807 DCHECK_EQ(resource->exported_count, 0); 1823 DCHECK_EQ(resource->exported_count, 0);
1808 1824
1809 if (resource->image_id) { 1825 if (resource->image_id) {
1810 GLES2Interface* gl = ContextGL(); 1826 GLES2Interface* gl = ContextGL();
1811 DCHECK(gl); 1827 DCHECK(gl);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1846 gl->GetIntegerv(GL_ACTIVE_TEXTURE, &active_unit); 1862 gl->GetIntegerv(GL_ACTIVE_TEXTURE, &active_unit);
1847 return active_unit; 1863 return active_unit;
1848 } 1864 }
1849 1865
1850 GLES2Interface* ResourceProvider::ContextGL() const { 1866 GLES2Interface* ResourceProvider::ContextGL() const {
1851 ContextProvider* context_provider = output_surface_->context_provider(); 1867 ContextProvider* context_provider = output_surface_->context_provider();
1852 return context_provider ? context_provider->ContextGL() : NULL; 1868 return context_provider ? context_provider->ContextGL() : NULL;
1853 } 1869 }
1854 1870
1855 } // namespace cc 1871 } // namespace cc
OLDNEW
« cc/resources/resource_provider.h ('K') | « cc/resources/resource_provider.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698