OLD | NEW |
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 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 exported_count(0), | 270 exported_count(0), |
271 dirty_image(false), | 271 dirty_image(false), |
272 locked_for_write(false), | 272 locked_for_write(false), |
273 lost(false), | 273 lost(false), |
274 marked_for_deletion(false), | 274 marked_for_deletion(false), |
275 pending_set_pixels(false), | 275 pending_set_pixels(false), |
276 set_pixels_completion_forced(false), | 276 set_pixels_completion_forced(false), |
277 allocated(false), | 277 allocated(false), |
278 read_lock_fences_enabled(false), | 278 read_lock_fences_enabled(false), |
279 has_shared_bitmap_id(false), | 279 has_shared_bitmap_id(false), |
280 allow_overlay(false), | |
281 read_lock_fence(NULL), | 280 read_lock_fence(NULL), |
282 size(size), | 281 size(size), |
283 origin(origin), | 282 origin(origin), |
284 target(target), | 283 target(target), |
285 original_filter(filter), | 284 original_filter(filter), |
286 filter(filter), | 285 filter(filter), |
287 image_id(0), | 286 image_id(0), |
288 bound_image_id(0), | 287 bound_image_id(0), |
289 texture_pool(texture_pool), | 288 texture_pool(texture_pool), |
290 wrap_mode(wrap_mode), | 289 wrap_mode(wrap_mode), |
(...skipping 23 matching lines...) Expand all Loading... |
314 exported_count(0), | 313 exported_count(0), |
315 dirty_image(false), | 314 dirty_image(false), |
316 locked_for_write(false), | 315 locked_for_write(false), |
317 lost(false), | 316 lost(false), |
318 marked_for_deletion(false), | 317 marked_for_deletion(false), |
319 pending_set_pixels(false), | 318 pending_set_pixels(false), |
320 set_pixels_completion_forced(false), | 319 set_pixels_completion_forced(false), |
321 allocated(false), | 320 allocated(false), |
322 read_lock_fences_enabled(false), | 321 read_lock_fences_enabled(false), |
323 has_shared_bitmap_id(!!bitmap), | 322 has_shared_bitmap_id(!!bitmap), |
324 allow_overlay(false), | |
325 read_lock_fence(NULL), | 323 read_lock_fence(NULL), |
326 size(size), | 324 size(size), |
327 origin(origin), | 325 origin(origin), |
328 target(0), | 326 target(0), |
329 original_filter(filter), | 327 original_filter(filter), |
330 filter(filter), | 328 filter(filter), |
331 image_id(0), | 329 image_id(0), |
332 bound_image_id(0), | 330 bound_image_id(0), |
333 texture_pool(0), | 331 texture_pool(0), |
334 wrap_mode(wrap_mode), | 332 wrap_mode(wrap_mode), |
(...skipping 24 matching lines...) Expand all Loading... |
359 exported_count(0), | 357 exported_count(0), |
360 dirty_image(false), | 358 dirty_image(false), |
361 locked_for_write(false), | 359 locked_for_write(false), |
362 lost(false), | 360 lost(false), |
363 marked_for_deletion(false), | 361 marked_for_deletion(false), |
364 pending_set_pixels(false), | 362 pending_set_pixels(false), |
365 set_pixels_completion_forced(false), | 363 set_pixels_completion_forced(false), |
366 allocated(false), | 364 allocated(false), |
367 read_lock_fences_enabled(false), | 365 read_lock_fences_enabled(false), |
368 has_shared_bitmap_id(true), | 366 has_shared_bitmap_id(true), |
369 allow_overlay(false), | |
370 read_lock_fence(NULL), | 367 read_lock_fence(NULL), |
371 size(size), | 368 size(size), |
372 origin(origin), | 369 origin(origin), |
373 target(0), | 370 target(0), |
374 original_filter(filter), | 371 original_filter(filter), |
375 filter(filter), | 372 filter(filter), |
376 image_id(0), | 373 image_id(0), |
377 bound_image_id(0), | 374 bound_image_id(0), |
378 texture_pool(0), | 375 texture_pool(0), |
379 wrap_mode(wrap_mode), | 376 wrap_mode(wrap_mode), |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 Resource* resource = GetResource(id); | 440 Resource* resource = GetResource(id); |
444 return resource->lock_for_read_count > 0 || resource->exported_count > 0 || | 441 return resource->lock_for_read_count > 0 || resource->exported_count > 0 || |
445 resource->lost; | 442 resource->lost; |
446 } | 443 } |
447 | 444 |
448 bool ResourceProvider::IsLost(ResourceId id) { | 445 bool ResourceProvider::IsLost(ResourceId id) { |
449 Resource* resource = GetResource(id); | 446 Resource* resource = GetResource(id); |
450 return resource->lost; | 447 return resource->lost; |
451 } | 448 } |
452 | 449 |
453 bool ResourceProvider::AllowOverlay(ResourceId id) { | |
454 Resource* resource = GetResource(id); | |
455 return resource->allow_overlay; | |
456 } | |
457 | |
458 ResourceId ResourceProvider::CreateResource(const gfx::Size& size, | 450 ResourceId ResourceProvider::CreateResource(const gfx::Size& size, |
459 GLint wrap_mode, | 451 GLint wrap_mode, |
460 TextureHint hint, | 452 TextureHint hint, |
461 ResourceFormat format) { | 453 ResourceFormat format) { |
462 DCHECK(!size.IsEmpty()); | 454 DCHECK(!size.IsEmpty()); |
463 switch (default_resource_type_) { | 455 switch (default_resource_type_) { |
464 case RESOURCE_TYPE_GL_TEXTURE: | 456 case RESOURCE_TYPE_GL_TEXTURE: |
465 return CreateGLTexture(size, | 457 return CreateGLTexture(size, |
466 GL_TEXTURE_2D, | 458 GL_TEXTURE_2D, |
467 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM, | 459 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM, |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 resource = InsertResource( | 559 resource = InsertResource( |
568 id, Resource(0, gfx::Size(), Resource::EXTERNAL, mailbox.target(), | 560 id, Resource(0, gfx::Size(), Resource::EXTERNAL, mailbox.target(), |
569 mailbox.nearest_neighbor() ? GL_NEAREST : GL_LINEAR, 0, | 561 mailbox.nearest_neighbor() ? GL_NEAREST : GL_LINEAR, 0, |
570 GL_CLAMP_TO_EDGE, TEXTURE_HINT_IMMUTABLE, RGBA_8888)); | 562 GL_CLAMP_TO_EDGE, TEXTURE_HINT_IMMUTABLE, RGBA_8888)); |
571 } else { | 563 } else { |
572 DCHECK(mailbox.IsSharedMemory()); | 564 DCHECK(mailbox.IsSharedMemory()); |
573 SharedBitmap* shared_bitmap = mailbox.shared_bitmap(); | 565 SharedBitmap* shared_bitmap = mailbox.shared_bitmap(); |
574 uint8_t* pixels = shared_bitmap->pixels(); | 566 uint8_t* pixels = shared_bitmap->pixels(); |
575 DCHECK(pixels); | 567 DCHECK(pixels); |
576 resource = InsertResource( | 568 resource = InsertResource( |
577 id, Resource(pixels, shared_bitmap, mailbox.shared_memory_size(), | 569 id, Resource(pixels, shared_bitmap, mailbox.size_in_pixels(), |
578 Resource::EXTERNAL, GL_LINEAR, GL_CLAMP_TO_EDGE)); | 570 Resource::EXTERNAL, GL_LINEAR, GL_CLAMP_TO_EDGE)); |
579 } | 571 } |
580 resource->allocated = true; | 572 resource->allocated = true; |
581 resource->mailbox = mailbox; | 573 resource->mailbox = mailbox; |
582 resource->release_callback_impl = | 574 resource->release_callback_impl = |
583 base::Bind(&SingleReleaseCallbackImpl::Run, | 575 base::Bind(&SingleReleaseCallbackImpl::Run, |
584 base::Owned(release_callback_impl.release())); | 576 base::Owned(release_callback_impl.release())); |
585 resource->allow_overlay = mailbox.allow_overlay(); | |
586 return id; | 577 return id; |
587 } | 578 } |
588 | 579 |
589 void ResourceProvider::DeleteResource(ResourceId id) { | 580 void ResourceProvider::DeleteResource(ResourceId id) { |
590 DCHECK(thread_checker_.CalledOnValidThread()); | 581 DCHECK(thread_checker_.CalledOnValidThread()); |
591 ResourceMap::iterator it = resources_.find(id); | 582 ResourceMap::iterator it = resources_.find(id); |
592 CHECK(it != resources_.end()); | 583 CHECK(it != resources_.end()); |
593 Resource* resource = &it->second; | 584 Resource* resource = &it->second; |
594 DCHECK(!resource->marked_for_deletion); | 585 DCHECK(!resource->marked_for_deletion); |
595 DCHECK_EQ(resource->imported_count, 0); | 586 DCHECK_EQ(resource->imported_count, 0); |
(...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1380 it->is_repeated ? GL_REPEAT : GL_CLAMP_TO_EDGE, | 1371 it->is_repeated ? GL_REPEAT : GL_CLAMP_TO_EDGE, |
1381 TEXTURE_HINT_IMMUTABLE, it->format)); | 1372 TEXTURE_HINT_IMMUTABLE, it->format)); |
1382 resource->mailbox = TextureMailbox(it->mailbox_holder.mailbox, | 1373 resource->mailbox = TextureMailbox(it->mailbox_holder.mailbox, |
1383 it->mailbox_holder.texture_target, | 1374 it->mailbox_holder.texture_target, |
1384 it->mailbox_holder.sync_point); | 1375 it->mailbox_holder.sync_point); |
1385 } | 1376 } |
1386 resource->child_id = child; | 1377 resource->child_id = child; |
1387 // Don't allocate a texture for a child. | 1378 // Don't allocate a texture for a child. |
1388 resource->allocated = true; | 1379 resource->allocated = true; |
1389 resource->imported_count = 1; | 1380 resource->imported_count = 1; |
1390 resource->allow_overlay = it->allow_overlay; | |
1391 child_info.parent_to_child_map[local_id] = it->id; | 1381 child_info.parent_to_child_map[local_id] = it->id; |
1392 child_info.child_to_parent_map[it->id] = local_id; | 1382 child_info.child_to_parent_map[it->id] = local_id; |
1393 } | 1383 } |
1394 } | 1384 } |
1395 | 1385 |
1396 void ResourceProvider::DeclareUsedResourcesFromChild( | 1386 void ResourceProvider::DeclareUsedResourcesFromChild( |
1397 int child, | 1387 int child, |
1398 const ResourceIdSet& resources_from_child) { | 1388 const ResourceIdSet& resources_from_child) { |
1399 DCHECK(thread_checker_.CalledOnValidThread()); | 1389 DCHECK(thread_checker_.CalledOnValidThread()); |
1400 | 1390 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1484 DCHECK(!source->locked_for_write); | 1474 DCHECK(!source->locked_for_write); |
1485 DCHECK(!source->lock_for_read_count); | 1475 DCHECK(!source->lock_for_read_count); |
1486 DCHECK(source->origin != Resource::EXTERNAL || source->mailbox.IsValid()); | 1476 DCHECK(source->origin != Resource::EXTERNAL || source->mailbox.IsValid()); |
1487 DCHECK(source->allocated); | 1477 DCHECK(source->allocated); |
1488 resource->id = id; | 1478 resource->id = id; |
1489 resource->format = source->format; | 1479 resource->format = source->format; |
1490 resource->mailbox_holder.texture_target = source->target; | 1480 resource->mailbox_holder.texture_target = source->target; |
1491 resource->filter = source->filter; | 1481 resource->filter = source->filter; |
1492 resource->size = source->size; | 1482 resource->size = source->size; |
1493 resource->is_repeated = (source->wrap_mode == GL_REPEAT); | 1483 resource->is_repeated = (source->wrap_mode == GL_REPEAT); |
1494 resource->allow_overlay = source->allow_overlay; | |
1495 | 1484 |
1496 if (source->type == RESOURCE_TYPE_BITMAP) { | 1485 if (source->type == RESOURCE_TYPE_BITMAP) { |
1497 resource->mailbox_holder.mailbox = source->shared_bitmap_id; | 1486 resource->mailbox_holder.mailbox = source->shared_bitmap_id; |
1498 resource->is_software = true; | 1487 resource->is_software = true; |
1499 } else if (!source->mailbox.IsValid()) { | 1488 } else if (!source->mailbox.IsValid()) { |
1500 LazyCreate(source); | 1489 LazyCreate(source); |
1501 DCHECK(source->gl_id); | 1490 DCHECK(source->gl_id); |
1502 DCHECK(source->origin == Resource::INTERNAL); | 1491 DCHECK(source->origin == Resource::INTERNAL); |
1503 if (source->image_id) { | 1492 if (source->image_id) { |
1504 DCHECK(source->dirty_image); | 1493 DCHECK(source->dirty_image); |
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2056 } | 2045 } |
2057 | 2046 |
2058 class GrContext* ResourceProvider::GrContext(bool worker_context) const { | 2047 class GrContext* ResourceProvider::GrContext(bool worker_context) const { |
2059 ContextProvider* context_provider = | 2048 ContextProvider* context_provider = |
2060 worker_context ? output_surface_->worker_context_provider() | 2049 worker_context ? output_surface_->worker_context_provider() |
2061 : output_surface_->context_provider(); | 2050 : output_surface_->context_provider(); |
2062 return context_provider ? context_provider->GrContext() : NULL; | 2051 return context_provider ? context_provider->GrContext() : NULL; |
2063 } | 2052 } |
2064 | 2053 |
2065 } // namespace cc | 2054 } // namespace cc |
OLD | NEW |