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

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

Issue 1142343008: cc: Rework overlays to not use the ResourceProvider and pass texture size (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 exported_count(0), 266 exported_count(0),
267 dirty_image(false), 267 dirty_image(false),
268 locked_for_write(false), 268 locked_for_write(false),
269 lost(false), 269 lost(false),
270 marked_for_deletion(false), 270 marked_for_deletion(false),
271 pending_set_pixels(false), 271 pending_set_pixels(false),
272 set_pixels_completion_forced(false), 272 set_pixels_completion_forced(false),
273 allocated(false), 273 allocated(false),
274 read_lock_fences_enabled(false), 274 read_lock_fences_enabled(false),
275 has_shared_bitmap_id(false), 275 has_shared_bitmap_id(false),
276 allow_overlay(false),
277 read_lock_fence(NULL), 276 read_lock_fence(NULL),
278 size(size), 277 size(size),
279 origin(origin), 278 origin(origin),
280 target(target), 279 target(target),
281 original_filter(filter), 280 original_filter(filter),
282 filter(filter), 281 filter(filter),
283 image_id(0), 282 image_id(0),
284 bound_image_id(0), 283 bound_image_id(0),
285 texture_pool(texture_pool), 284 texture_pool(texture_pool),
286 wrap_mode(wrap_mode), 285 wrap_mode(wrap_mode),
(...skipping 23 matching lines...) Expand all
310 exported_count(0), 309 exported_count(0),
311 dirty_image(false), 310 dirty_image(false),
312 locked_for_write(false), 311 locked_for_write(false),
313 lost(false), 312 lost(false),
314 marked_for_deletion(false), 313 marked_for_deletion(false),
315 pending_set_pixels(false), 314 pending_set_pixels(false),
316 set_pixels_completion_forced(false), 315 set_pixels_completion_forced(false),
317 allocated(false), 316 allocated(false),
318 read_lock_fences_enabled(false), 317 read_lock_fences_enabled(false),
319 has_shared_bitmap_id(!!bitmap), 318 has_shared_bitmap_id(!!bitmap),
320 allow_overlay(false),
321 read_lock_fence(NULL), 319 read_lock_fence(NULL),
322 size(size), 320 size(size),
323 origin(origin), 321 origin(origin),
324 target(0), 322 target(0),
325 original_filter(filter), 323 original_filter(filter),
326 filter(filter), 324 filter(filter),
327 image_id(0), 325 image_id(0),
328 bound_image_id(0), 326 bound_image_id(0),
329 texture_pool(0), 327 texture_pool(0),
330 wrap_mode(wrap_mode), 328 wrap_mode(wrap_mode),
(...skipping 24 matching lines...) Expand all
355 exported_count(0), 353 exported_count(0),
356 dirty_image(false), 354 dirty_image(false),
357 locked_for_write(false), 355 locked_for_write(false),
358 lost(false), 356 lost(false),
359 marked_for_deletion(false), 357 marked_for_deletion(false),
360 pending_set_pixels(false), 358 pending_set_pixels(false),
361 set_pixels_completion_forced(false), 359 set_pixels_completion_forced(false),
362 allocated(false), 360 allocated(false),
363 read_lock_fences_enabled(false), 361 read_lock_fences_enabled(false),
364 has_shared_bitmap_id(true), 362 has_shared_bitmap_id(true),
365 allow_overlay(false),
366 read_lock_fence(NULL), 363 read_lock_fence(NULL),
367 size(size), 364 size(size),
368 origin(origin), 365 origin(origin),
369 target(0), 366 target(0),
370 original_filter(filter), 367 original_filter(filter),
371 filter(filter), 368 filter(filter),
372 image_id(0), 369 image_id(0),
373 bound_image_id(0), 370 bound_image_id(0),
374 texture_pool(0), 371 texture_pool(0),
375 wrap_mode(wrap_mode), 372 wrap_mode(wrap_mode),
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 Resource* resource = GetResource(id); 446 Resource* resource = GetResource(id);
450 return resource->lock_for_read_count > 0 || resource->exported_count > 0 || 447 return resource->lock_for_read_count > 0 || resource->exported_count > 0 ||
451 resource->lost; 448 resource->lost;
452 } 449 }
453 450
454 bool ResourceProvider::IsLost(ResourceId id) { 451 bool ResourceProvider::IsLost(ResourceId id) {
455 Resource* resource = GetResource(id); 452 Resource* resource = GetResource(id);
456 return resource->lost; 453 return resource->lost;
457 } 454 }
458 455
459 bool ResourceProvider::AllowOverlay(ResourceId id) {
460 Resource* resource = GetResource(id);
461 return resource->allow_overlay;
462 }
463
464 ResourceId ResourceProvider::CreateResource(const gfx::Size& size, 456 ResourceId ResourceProvider::CreateResource(const gfx::Size& size,
465 GLint wrap_mode, 457 GLint wrap_mode,
466 TextureHint hint, 458 TextureHint hint,
467 ResourceFormat format) { 459 ResourceFormat format) {
468 DCHECK(!size.IsEmpty()); 460 DCHECK(!size.IsEmpty());
469 switch (default_resource_type_) { 461 switch (default_resource_type_) {
470 case RESOURCE_TYPE_GL_TEXTURE: 462 case RESOURCE_TYPE_GL_TEXTURE:
471 return CreateGLTexture(size, 463 return CreateGLTexture(size,
472 GL_TEXTURE_2D, 464 GL_TEXTURE_2D,
473 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM, 465 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM,
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 ResourceId ResourceProvider::CreateResourceFromTextureMailbox( 556 ResourceId ResourceProvider::CreateResourceFromTextureMailbox(
565 const TextureMailbox& mailbox, 557 const TextureMailbox& mailbox,
566 scoped_ptr<SingleReleaseCallbackImpl> release_callback_impl) { 558 scoped_ptr<SingleReleaseCallbackImpl> release_callback_impl) {
567 DCHECK(thread_checker_.CalledOnValidThread()); 559 DCHECK(thread_checker_.CalledOnValidThread());
568 // Just store the information. Mailbox will be consumed in LockForRead(). 560 // Just store the information. Mailbox will be consumed in LockForRead().
569 ResourceId id = next_id_++; 561 ResourceId id = next_id_++;
570 DCHECK(mailbox.IsValid()); 562 DCHECK(mailbox.IsValid());
571 Resource* resource = nullptr; 563 Resource* resource = nullptr;
572 if (mailbox.IsTexture()) { 564 if (mailbox.IsTexture()) {
573 resource = InsertResource( 565 resource = InsertResource(
574 id, Resource(0, gfx::Size(), Resource::EXTERNAL, mailbox.target(), 566 id, Resource(0, mailbox.size(), Resource::EXTERNAL, mailbox.target(),
danakj 2015/05/29 20:04:15 if we're not going to use the size maybe just leav
achaulk 2015/06/01 15:43:10 Done.
575 mailbox.nearest_neighbor() ? GL_NEAREST : GL_LINEAR, 0, 567 mailbox.nearest_neighbor() ? GL_NEAREST : GL_LINEAR, 0,
576 GL_CLAMP_TO_EDGE, TEXTURE_HINT_IMMUTABLE, RGBA_8888)); 568 GL_CLAMP_TO_EDGE, TEXTURE_HINT_IMMUTABLE, RGBA_8888));
577 } else { 569 } else {
578 DCHECK(mailbox.IsSharedMemory()); 570 DCHECK(mailbox.IsSharedMemory());
579 SharedBitmap* shared_bitmap = mailbox.shared_bitmap(); 571 SharedBitmap* shared_bitmap = mailbox.shared_bitmap();
580 uint8_t* pixels = shared_bitmap->pixels(); 572 uint8_t* pixels = shared_bitmap->pixels();
581 DCHECK(pixels); 573 DCHECK(pixels);
582 resource = InsertResource( 574 resource = InsertResource(
583 id, Resource(pixels, shared_bitmap, mailbox.shared_memory_size(), 575 id, Resource(pixels, shared_bitmap, mailbox.size(), Resource::EXTERNAL,
584 Resource::EXTERNAL, GL_LINEAR, GL_CLAMP_TO_EDGE)); 576 GL_LINEAR, GL_CLAMP_TO_EDGE));
585 } 577 }
586 resource->allocated = true; 578 resource->allocated = true;
587 resource->mailbox = mailbox; 579 resource->mailbox = mailbox;
588 resource->release_callback_impl = 580 resource->release_callback_impl =
589 base::Bind(&SingleReleaseCallbackImpl::Run, 581 base::Bind(&SingleReleaseCallbackImpl::Run,
590 base::Owned(release_callback_impl.release())); 582 base::Owned(release_callback_impl.release()));
591 resource->allow_overlay = mailbox.allow_overlay();
592 return id; 583 return id;
593 } 584 }
594 585
595 void ResourceProvider::DeleteResource(ResourceId id) { 586 void ResourceProvider::DeleteResource(ResourceId id) {
596 DCHECK(thread_checker_.CalledOnValidThread()); 587 DCHECK(thread_checker_.CalledOnValidThread());
597 ResourceMap::iterator it = resources_.find(id); 588 ResourceMap::iterator it = resources_.find(id);
598 CHECK(it != resources_.end()); 589 CHECK(it != resources_.end());
599 Resource* resource = &it->second; 590 Resource* resource = &it->second;
600 DCHECK(!resource->marked_for_deletion); 591 DCHECK(!resource->marked_for_deletion);
601 DCHECK_EQ(resource->imported_count, 0); 592 DCHECK_EQ(resource->imported_count, 0);
(...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after
1381 it->is_repeated ? GL_REPEAT : GL_CLAMP_TO_EDGE, 1372 it->is_repeated ? GL_REPEAT : GL_CLAMP_TO_EDGE,
1382 TEXTURE_HINT_IMMUTABLE, it->format)); 1373 TEXTURE_HINT_IMMUTABLE, it->format));
1383 resource->mailbox = TextureMailbox(it->mailbox_holder.mailbox, 1374 resource->mailbox = TextureMailbox(it->mailbox_holder.mailbox,
1384 it->mailbox_holder.texture_target, 1375 it->mailbox_holder.texture_target,
1385 it->mailbox_holder.sync_point); 1376 it->mailbox_holder.sync_point);
1386 } 1377 }
1387 resource->child_id = child; 1378 resource->child_id = child;
1388 // Don't allocate a texture for a child. 1379 // Don't allocate a texture for a child.
1389 resource->allocated = true; 1380 resource->allocated = true;
1390 resource->imported_count = 1; 1381 resource->imported_count = 1;
1391 resource->allow_overlay = it->allow_overlay;
1392 child_info.parent_to_child_map[local_id] = it->id; 1382 child_info.parent_to_child_map[local_id] = it->id;
1393 child_info.child_to_parent_map[it->id] = local_id; 1383 child_info.child_to_parent_map[it->id] = local_id;
1394 } 1384 }
1395 } 1385 }
1396 1386
1397 void ResourceProvider::DeclareUsedResourcesFromChild( 1387 void ResourceProvider::DeclareUsedResourcesFromChild(
1398 int child, 1388 int child,
1399 const ResourceIdSet& resources_from_child) { 1389 const ResourceIdSet& resources_from_child) {
1400 DCHECK(thread_checker_.CalledOnValidThread()); 1390 DCHECK(thread_checker_.CalledOnValidThread());
1401 1391
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1485 DCHECK(!source->locked_for_write); 1475 DCHECK(!source->locked_for_write);
1486 DCHECK(!source->lock_for_read_count); 1476 DCHECK(!source->lock_for_read_count);
1487 DCHECK(source->origin != Resource::EXTERNAL || source->mailbox.IsValid()); 1477 DCHECK(source->origin != Resource::EXTERNAL || source->mailbox.IsValid());
1488 DCHECK(source->allocated); 1478 DCHECK(source->allocated);
1489 resource->id = id; 1479 resource->id = id;
1490 resource->format = source->format; 1480 resource->format = source->format;
1491 resource->mailbox_holder.texture_target = source->target; 1481 resource->mailbox_holder.texture_target = source->target;
1492 resource->filter = source->filter; 1482 resource->filter = source->filter;
1493 resource->size = source->size; 1483 resource->size = source->size;
1494 resource->is_repeated = (source->wrap_mode == GL_REPEAT); 1484 resource->is_repeated = (source->wrap_mode == GL_REPEAT);
1495 resource->allow_overlay = source->allow_overlay;
1496 1485
1497 if (source->type == RESOURCE_TYPE_BITMAP) { 1486 if (source->type == RESOURCE_TYPE_BITMAP) {
1498 resource->mailbox_holder.mailbox = source->shared_bitmap_id; 1487 resource->mailbox_holder.mailbox = source->shared_bitmap_id;
1499 resource->is_software = true; 1488 resource->is_software = true;
1500 } else if (!source->mailbox.IsValid()) { 1489 } else if (!source->mailbox.IsValid()) {
1501 LazyCreate(source); 1490 LazyCreate(source);
1502 DCHECK(source->gl_id); 1491 DCHECK(source->gl_id);
1503 DCHECK(source->origin == Resource::INTERNAL); 1492 DCHECK(source->origin == Resource::INTERNAL);
1504 if (source->image_id) { 1493 if (source->image_id) {
1505 DCHECK(source->dirty_image); 1494 DCHECK(source->dirty_image);
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after
2057 } 2046 }
2058 2047
2059 class GrContext* ResourceProvider::GrContext(bool worker_context) const { 2048 class GrContext* ResourceProvider::GrContext(bool worker_context) const {
2060 ContextProvider* context_provider = 2049 ContextProvider* context_provider =
2061 worker_context ? output_surface_->worker_context_provider() 2050 worker_context ? output_surface_->worker_context_provider()
2062 : output_surface_->context_provider(); 2051 : output_surface_->context_provider();
2063 return context_provider ? context_provider->GrContext() : NULL; 2052 return context_provider ? context_provider->GrContext() : NULL;
2064 } 2053 }
2065 2054
2066 } // namespace cc 2055 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698