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" |
11 #include "base/debug/trace_event.h" | 11 #include "base/debug/trace_event.h" |
12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
13 #include "base/strings/string_split.h" | 13 #include "base/strings/string_split.h" |
14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
15 #include "cc/base/util.h" | 15 #include "cc/base/util.h" |
16 #include "cc/output/gl_renderer.h" // For the GLC() macro. | 16 #include "cc/output/gl_renderer.h" // For the GLC() macro. |
17 #include "cc/resources/platform_color.h" | 17 #include "cc/resources/platform_color.h" |
18 #include "cc/resources/returned_resource.h" | 18 #include "cc/resources/returned_resource.h" |
19 #include "cc/resources/shared_bitmap_manager.h" | 19 #include "cc/resources/shared_bitmap_manager.h" |
20 #include "cc/resources/texture_uploader.h" | 20 #include "cc/resources/texture_uploader.h" |
21 #include "cc/resources/transferable_resource.h" | 21 #include "cc/resources/transferable_resource.h" |
22 #include "gpu/GLES2/gl2extchromium.h" | 22 #include "gpu/GLES2/gl2extchromium.h" |
23 #include "gpu/command_buffer/client/gles2_interface.h" | 23 #include "gpu/command_buffer/client/gles2_interface.h" |
24 #include "third_party/khronos/GLES2/gl2.h" | 24 #include "third_party/khronos/GLES2/gl2.h" |
25 #include "third_party/khronos/GLES2/gl2ext.h" | 25 #include "third_party/khronos/GLES2/gl2ext.h" |
| 26 #include "third_party/skia/include/core/SkSurface.h" |
| 27 #include "third_party/skia/include/gpu/GrContext.h" |
| 28 #include "third_party/skia/include/gpu/SkGpuDevice.h" |
26 #include "ui/gfx/frame_time.h" | 29 #include "ui/gfx/frame_time.h" |
27 #include "ui/gfx/rect.h" | 30 #include "ui/gfx/rect.h" |
28 #include "ui/gfx/vector2d.h" | 31 #include "ui/gfx/vector2d.h" |
29 | 32 |
30 using gpu::gles2::GLES2Interface; | 33 using gpu::gles2::GLES2Interface; |
31 | 34 |
32 namespace cc { | 35 namespace cc { |
33 | 36 |
34 class IdAllocator { | 37 class IdAllocator { |
35 public: | 38 public: |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 return true; | 87 return true; |
85 case RGBA_4444: | 88 case RGBA_4444: |
86 case LUMINANCE_8: | 89 case LUMINANCE_8: |
87 case RGB_565: | 90 case RGB_565: |
88 case ETC1: | 91 case ETC1: |
89 return false; | 92 return false; |
90 } | 93 } |
91 return false; | 94 return false; |
92 } | 95 } |
93 | 96 |
| 97 GrPixelConfig ToGrPixelConfig(ResourceFormat format) { |
| 98 switch (format) { |
| 99 case RGBA_8888: |
| 100 return kRGBA_8888_GrPixelConfig; |
| 101 case BGRA_8888: |
| 102 return kBGRA_8888_GrPixelConfig; |
| 103 case RGBA_4444: |
| 104 return kRGBA_4444_GrPixelConfig; |
| 105 default: |
| 106 break; |
| 107 } |
| 108 DCHECK(false) << "Unsupported resource format."; |
| 109 return kSkia8888_GrPixelConfig; |
| 110 } |
| 111 |
94 class ScopedSetActiveTexture { | 112 class ScopedSetActiveTexture { |
95 public: | 113 public: |
96 ScopedSetActiveTexture(GLES2Interface* gl, GLenum unit) | 114 ScopedSetActiveTexture(GLES2Interface* gl, GLenum unit) |
97 : gl_(gl), unit_(unit) { | 115 : gl_(gl), unit_(unit) { |
98 DCHECK_EQ(GL_TEXTURE0, ResourceProvider::GetActiveTextureUnit(gl_)); | 116 DCHECK_EQ(GL_TEXTURE0, ResourceProvider::GetActiveTextureUnit(gl_)); |
99 | 117 |
100 if (unit_ != GL_TEXTURE0) | 118 if (unit_ != GL_TEXTURE0) |
101 GLC(gl_, gl_->ActiveTexture(unit_)); | 119 GLC(gl_, gl_->ActiveTexture(unit_)); |
102 } | 120 } |
103 | 121 |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 wrap_mode(wrap_mode), | 292 wrap_mode(wrap_mode), |
275 lost(false), | 293 lost(false), |
276 hint(TextureUsageAny), | 294 hint(TextureUsageAny), |
277 type(Bitmap), | 295 type(Bitmap), |
278 format(RGBA_8888), | 296 format(RGBA_8888), |
279 shared_bitmap(bitmap) { | 297 shared_bitmap(bitmap) { |
280 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); | 298 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); |
281 DCHECK(origin == Delegated || pixels); | 299 DCHECK(origin == Delegated || pixels); |
282 } | 300 } |
283 | 301 |
| 302 ResourceProvider::RasterBuffer::RasterBuffer( |
| 303 const Resource* resource, |
| 304 ResourceProvider* resource_provider) |
| 305 : resource_(resource), |
| 306 resource_provider_(resource_provider), |
| 307 locked_canvas_(NULL), |
| 308 canvas_save_count_(0) { |
| 309 DCHECK(resource_); |
| 310 DCHECK(resource_provider_); |
| 311 } |
| 312 |
| 313 ResourceProvider::RasterBuffer::~RasterBuffer() {} |
| 314 |
| 315 SkCanvas* ResourceProvider::RasterBuffer::LockForWrite() { |
| 316 DCHECK(!locked_canvas_); |
| 317 |
| 318 locked_canvas_ = DoLockForWrite(); |
| 319 canvas_save_count_ = locked_canvas_->save(); |
| 320 return locked_canvas_; |
| 321 } |
| 322 |
| 323 void ResourceProvider::RasterBuffer::UnlockForWrite() { |
| 324 DCHECK(locked_canvas_); |
| 325 |
| 326 locked_canvas_->restoreToCount(canvas_save_count_); |
| 327 locked_canvas_ = NULL; |
| 328 DoUnlockForWrite(); |
| 329 } |
| 330 |
| 331 ResourceProvider::DirectRasterBuffer::DirectRasterBuffer( |
| 332 const Resource* resource, |
| 333 ResourceProvider* resource_provider) |
| 334 : RasterBuffer(resource, resource_provider) {} |
| 335 |
| 336 ResourceProvider::DirectRasterBuffer::~DirectRasterBuffer() {} |
| 337 |
| 338 SkCanvas* ResourceProvider::DirectRasterBuffer::DoLockForWrite() { |
| 339 if (!surface_) |
| 340 surface_ = CreateSurface(); |
| 341 return surface_->getCanvas(); |
| 342 } |
| 343 |
| 344 void ResourceProvider::DirectRasterBuffer::DoUnlockForWrite() {} |
| 345 |
| 346 skia::RefPtr<SkSurface> ResourceProvider::DirectRasterBuffer::CreateSurface() { |
| 347 skia::RefPtr<SkSurface> surface; |
| 348 switch (resource()->type) { |
| 349 case GLTexture: { |
| 350 DCHECK(resource()->gl_id); |
| 351 class GrContext* gr_context = resource_provider()->GrContext(); |
| 352 GrBackendTextureDesc desc; |
| 353 desc.fFlags = kRenderTarget_GrBackendTextureFlag; |
| 354 desc.fWidth = resource()->size.width(); |
| 355 desc.fHeight = resource()->size.height(); |
| 356 desc.fConfig = ToGrPixelConfig(resource()->format); |
| 357 desc.fOrigin = kTopLeft_GrSurfaceOrigin; |
| 358 desc.fTextureHandle = resource()->gl_id; |
| 359 skia::RefPtr<GrTexture> gr_texture = |
| 360 skia::AdoptRef(gr_context->wrapBackendTexture(desc)); |
| 361 surface = skia::AdoptRef( |
| 362 SkSurface::NewRenderTargetDirect(gr_texture->asRenderTarget())); |
| 363 break; |
| 364 } |
| 365 case Bitmap: { |
| 366 DCHECK(resource()->pixels); |
| 367 DCHECK_EQ(RGBA_8888, resource()->format); |
| 368 SkImageInfo image_info = SkImageInfo::MakeN32Premul( |
| 369 resource()->size.width(), resource()->size.height()); |
| 370 size_t row_bytes = SkBitmap::ComputeRowBytes(SkBitmap::kARGB_8888_Config, |
| 371 resource()->size.width()); |
| 372 surface = skia::AdoptRef(SkSurface::NewRasterDirect( |
| 373 image_info, resource()->pixels, row_bytes)); |
| 374 break; |
| 375 } |
| 376 default: |
| 377 NOTREACHED(); |
| 378 } |
| 379 return surface; |
| 380 } |
| 381 |
| 382 ResourceProvider::BitmapRasterBuffer::BitmapRasterBuffer( |
| 383 const Resource* resource, |
| 384 ResourceProvider* resource_provider) |
| 385 : RasterBuffer(resource, resource_provider), buffer_(NULL) {} |
| 386 |
| 387 ResourceProvider::BitmapRasterBuffer::~BitmapRasterBuffer() {} |
| 388 |
| 389 SkCanvas* ResourceProvider::BitmapRasterBuffer::DoLockForWrite() { |
| 390 DCHECK(!buffer_); |
| 391 DCHECK(!canvas_); |
| 392 |
| 393 int stride = 0; |
| 394 buffer_ = MapBuffer(&stride); |
| 395 SkBitmap bitmap; |
| 396 switch (resource()->format) { |
| 397 case RGBA_4444: |
| 398 // Use the default stride if we will eventually convert this |
| 399 // bitmap to 4444. |
| 400 bitmap.setConfig(SkBitmap::kARGB_8888_Config, |
| 401 resource()->size.width(), |
| 402 resource()->size.height()); |
| 403 bitmap.allocPixels(); |
| 404 break; |
| 405 case RGBA_8888: |
| 406 case BGRA_8888: |
| 407 bitmap.setConfig(SkBitmap::kARGB_8888_Config, |
| 408 resource()->size.width(), |
| 409 resource()->size.height(), |
| 410 stride); |
| 411 bitmap.setPixels(buffer_); |
| 412 break; |
| 413 case LUMINANCE_8: |
| 414 case RGB_565: |
| 415 case ETC1: |
| 416 NOTREACHED(); |
| 417 break; |
| 418 } |
| 419 skia::RefPtr<SkBitmapDevice> device = |
| 420 skia::AdoptRef(new SkBitmapDevice(bitmap)); |
| 421 canvas_ = skia::AdoptRef(new SkCanvas(device.get())); |
| 422 |
| 423 return canvas_.get(); |
| 424 } |
| 425 |
| 426 void ResourceProvider::BitmapRasterBuffer::DoUnlockForWrite() { |
| 427 canvas_.clear(); |
| 428 |
| 429 UnmapBuffer(); |
| 430 buffer_ = NULL; |
| 431 } |
| 432 |
| 433 ResourceProvider::ImageRasterBuffer::ImageRasterBuffer( |
| 434 const Resource* resource, |
| 435 ResourceProvider* resource_provider) |
| 436 : BitmapRasterBuffer(resource, resource_provider) {} |
| 437 |
| 438 ResourceProvider::ImageRasterBuffer::~ImageRasterBuffer() {} |
| 439 |
| 440 uint8_t* ResourceProvider::ImageRasterBuffer::MapBuffer(int* stride) { |
| 441 return resource_provider()->MapImage(resource(), stride); |
| 442 } |
| 443 |
| 444 void ResourceProvider::ImageRasterBuffer::UnmapBuffer() { |
| 445 resource_provider()->UnmapImage(resource()); |
| 446 } |
| 447 |
| 448 ResourceProvider::PixelRasterBuffer::PixelRasterBuffer( |
| 449 const Resource* resource, |
| 450 ResourceProvider* resource_provider) |
| 451 : BitmapRasterBuffer(resource, resource_provider) {} |
| 452 |
| 453 ResourceProvider::PixelRasterBuffer::~PixelRasterBuffer() {} |
| 454 |
| 455 uint8_t* ResourceProvider::PixelRasterBuffer::MapBuffer(int* stride) { |
| 456 return resource_provider()->MapPixelBuffer(resource(), stride); |
| 457 } |
| 458 |
| 459 void ResourceProvider::PixelRasterBuffer::UnmapBuffer() { |
| 460 resource_provider()->UnmapPixelBuffer(resource()); |
| 461 } |
| 462 |
284 ResourceProvider::Child::Child() : marked_for_deletion(false) {} | 463 ResourceProvider::Child::Child() : marked_for_deletion(false) {} |
285 | 464 |
286 ResourceProvider::Child::~Child() {} | 465 ResourceProvider::Child::~Child() {} |
287 | 466 |
288 scoped_ptr<ResourceProvider> ResourceProvider::Create( | 467 scoped_ptr<ResourceProvider> ResourceProvider::Create( |
289 OutputSurface* output_surface, | 468 OutputSurface* output_surface, |
290 SharedBitmapManager* shared_bitmap_manager, | 469 SharedBitmapManager* shared_bitmap_manager, |
291 int highp_threshold_min, | 470 int highp_threshold_min, |
292 bool use_rgba_4444_texture_format, | 471 bool use_rgba_4444_texture_format, |
293 size_t id_allocation_chunk_size) { | 472 size_t id_allocation_chunk_size) { |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 void ResourceProvider::DeleteResourceInternal(ResourceMap::iterator it, | 710 void ResourceProvider::DeleteResourceInternal(ResourceMap::iterator it, |
532 DeleteStyle style) { | 711 DeleteStyle style) { |
533 TRACE_EVENT0("cc", "ResourceProvider::DeleteResourceInternal"); | 712 TRACE_EVENT0("cc", "ResourceProvider::DeleteResourceInternal"); |
534 Resource* resource = &it->second; | 713 Resource* resource = &it->second; |
535 bool lost_resource = resource->lost; | 714 bool lost_resource = resource->lost; |
536 | 715 |
537 DCHECK(resource->exported_count == 0 || style != Normal); | 716 DCHECK(resource->exported_count == 0 || style != Normal); |
538 if (style == ForShutdown && resource->exported_count > 0) | 717 if (style == ForShutdown && resource->exported_count > 0) |
539 lost_resource = true; | 718 lost_resource = true; |
540 | 719 |
| 720 resource->direct_raster_buffer.reset(); |
| 721 resource->image_raster_buffer.reset(); |
| 722 resource->pixel_raster_buffer.reset(); |
| 723 |
541 if (resource->image_id) { | 724 if (resource->image_id) { |
542 DCHECK(resource->origin == Resource::Internal); | 725 DCHECK(resource->origin == Resource::Internal); |
543 GLES2Interface* gl = ContextGL(); | 726 GLES2Interface* gl = ContextGL(); |
544 DCHECK(gl); | 727 DCHECK(gl); |
545 GLC(gl, gl->DestroyImageCHROMIUM(resource->image_id)); | 728 GLC(gl, gl->DestroyImageCHROMIUM(resource->image_id)); |
546 } | 729 } |
547 | 730 |
548 if (resource->gl_upload_query_id) { | 731 if (resource->gl_upload_query_id) { |
549 DCHECK(resource->origin == Resource::Internal); | 732 DCHECK(resource->origin == Resource::Internal); |
550 GLES2Interface* gl = ContextGL(); | 733 GLES2Interface* gl = ContextGL(); |
(...skipping 867 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1418 if (!to_return.empty()) | 1601 if (!to_return.empty()) |
1419 child_info->return_callback.Run(to_return); | 1602 child_info->return_callback.Run(to_return); |
1420 | 1603 |
1421 if (child_info->marked_for_deletion && | 1604 if (child_info->marked_for_deletion && |
1422 child_info->parent_to_child_map.empty()) { | 1605 child_info->parent_to_child_map.empty()) { |
1423 DCHECK(child_info->child_to_parent_map.empty()); | 1606 DCHECK(child_info->child_to_parent_map.empty()); |
1424 children_.erase(child_it); | 1607 children_.erase(child_it); |
1425 } | 1608 } |
1426 } | 1609 } |
1427 | 1610 |
1428 void ResourceProvider::AcquirePixelBuffer(ResourceId id) { | 1611 SkCanvas* ResourceProvider::MapDirectRasterBuffer(ResourceId id) { |
| 1612 // Resource needs to be locked for write since DirectRasterBuffer writes |
| 1613 // directly to it. |
| 1614 LockForWrite(id); |
1429 Resource* resource = GetResource(id); | 1615 Resource* resource = GetResource(id); |
| 1616 if (!resource->direct_raster_buffer.get()) { |
| 1617 resource->direct_raster_buffer.reset( |
| 1618 new DirectRasterBuffer(resource, this)); |
| 1619 } |
| 1620 return resource->direct_raster_buffer->LockForWrite(); |
| 1621 } |
| 1622 |
| 1623 void ResourceProvider::UnmapDirectRasterBuffer(ResourceId id) { |
| 1624 Resource* resource = GetResource(id); |
| 1625 DCHECK(resource->direct_raster_buffer.get()); |
| 1626 resource->direct_raster_buffer->UnlockForWrite(); |
| 1627 UnlockForWrite(id); |
| 1628 } |
| 1629 |
| 1630 SkCanvas* ResourceProvider::MapImageRasterBuffer(ResourceId id) { |
| 1631 Resource* resource = GetResource(id); |
| 1632 AcquireImage(resource); |
| 1633 if (!resource->image_raster_buffer.get()) |
| 1634 resource->image_raster_buffer.reset(new ImageRasterBuffer(resource, this)); |
| 1635 return resource->image_raster_buffer->LockForWrite(); |
| 1636 } |
| 1637 |
| 1638 void ResourceProvider::UnmapImageRasterBuffer(ResourceId id) { |
| 1639 Resource* resource = GetResource(id); |
| 1640 resource->image_raster_buffer->UnlockForWrite(); |
| 1641 resource->dirty_image = true; |
| 1642 } |
| 1643 |
| 1644 void ResourceProvider::AcquirePixelRasterBuffer(ResourceId id) { |
| 1645 Resource* resource = GetResource(id); |
| 1646 AcquirePixelBuffer(resource); |
| 1647 resource->pixel_raster_buffer.reset(new PixelRasterBuffer(resource, this)); |
| 1648 } |
| 1649 |
| 1650 void ResourceProvider::ReleasePixelRasterBuffer(ResourceId id) { |
| 1651 Resource* resource = GetResource(id); |
| 1652 resource->pixel_raster_buffer.reset(); |
| 1653 ReleasePixelBuffer(resource); |
| 1654 } |
| 1655 |
| 1656 SkCanvas* ResourceProvider::MapPixelRasterBuffer(ResourceId id) { |
| 1657 Resource* resource = GetResource(id); |
| 1658 DCHECK(resource->pixel_raster_buffer.get()); |
| 1659 return resource->pixel_raster_buffer->LockForWrite(); |
| 1660 } |
| 1661 |
| 1662 void ResourceProvider::UnmapPixelRasterBuffer(ResourceId id) { |
| 1663 Resource* resource = GetResource(id); |
| 1664 DCHECK(resource->pixel_raster_buffer.get()); |
| 1665 resource->pixel_raster_buffer->UnlockForWrite(); |
| 1666 } |
| 1667 |
| 1668 void ResourceProvider::AcquirePixelBuffer(Resource* resource) { |
1430 DCHECK(resource->origin == Resource::Internal); | 1669 DCHECK(resource->origin == Resource::Internal); |
1431 DCHECK_EQ(resource->exported_count, 0); | 1670 DCHECK_EQ(resource->exported_count, 0); |
1432 DCHECK(!resource->image_id); | 1671 DCHECK(!resource->image_id); |
1433 DCHECK_NE(ETC1, resource->format); | 1672 DCHECK_NE(ETC1, resource->format); |
1434 | 1673 |
1435 if (resource->type == GLTexture) { | 1674 if (resource->type == GLTexture) { |
1436 GLES2Interface* gl = ContextGL(); | 1675 GLES2Interface* gl = ContextGL(); |
1437 DCHECK(gl); | 1676 DCHECK(gl); |
1438 if (!resource->gl_pixel_buffer_id) | 1677 if (!resource->gl_pixel_buffer_id) |
1439 resource->gl_pixel_buffer_id = buffer_id_allocator_->NextId(); | 1678 resource->gl_pixel_buffer_id = buffer_id_allocator_->NextId(); |
1440 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1679 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
1441 resource->gl_pixel_buffer_id); | 1680 resource->gl_pixel_buffer_id); |
1442 unsigned bytes_per_pixel = BitsPerPixel(resource->format) / 8; | 1681 unsigned bytes_per_pixel = BitsPerPixel(resource->format) / 8; |
1443 gl->BufferData(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1682 gl->BufferData(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
1444 resource->size.height() * | 1683 resource->size.height() * |
1445 RoundUp(bytes_per_pixel * resource->size.width(), 4u), | 1684 RoundUp(bytes_per_pixel * resource->size.width(), 4u), |
1446 NULL, | 1685 NULL, |
1447 GL_DYNAMIC_DRAW); | 1686 GL_DYNAMIC_DRAW); |
1448 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | 1687 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
1449 } else { | 1688 } else { |
1450 DCHECK_EQ(Bitmap, resource->type); | 1689 DCHECK_EQ(Bitmap, resource->type); |
1451 if (resource->pixel_buffer) | 1690 if (resource->pixel_buffer) |
1452 return; | 1691 return; |
1453 | 1692 |
1454 resource->pixel_buffer = new uint8_t[4 * resource->size.GetArea()]; | 1693 resource->pixel_buffer = new uint8_t[4 * resource->size.GetArea()]; |
1455 } | 1694 } |
1456 } | 1695 } |
1457 | 1696 |
1458 void ResourceProvider::ReleasePixelBuffer(ResourceId id) { | 1697 void ResourceProvider::ReleasePixelBuffer(Resource* resource) { |
1459 Resource* resource = GetResource(id); | |
1460 DCHECK(resource->origin == Resource::Internal); | 1698 DCHECK(resource->origin == Resource::Internal); |
1461 DCHECK_EQ(resource->exported_count, 0); | 1699 DCHECK_EQ(resource->exported_count, 0); |
1462 DCHECK(!resource->image_id); | 1700 DCHECK(!resource->image_id); |
1463 | 1701 |
1464 // The pixel buffer can be released while there is a pending "set pixels" | 1702 // The pixel buffer can be released while there is a pending "set pixels" |
1465 // if completion has been forced. Any shared memory associated with this | 1703 // if completion has been forced. Any shared memory associated with this |
1466 // pixel buffer will not be freed until the waitAsyncTexImage2DCHROMIUM | 1704 // pixel buffer will not be freed until the waitAsyncTexImage2DCHROMIUM |
1467 // command has been processed on the service side. It is also safe to | 1705 // command has been processed on the service side. It is also safe to |
1468 // reuse any query id associated with this resource before they complete | 1706 // reuse any query id associated with this resource before they complete |
1469 // as each new query has a unique submit count. | 1707 // as each new query has a unique submit count. |
1470 if (resource->pending_set_pixels) { | 1708 if (resource->pending_set_pixels) { |
1471 DCHECK(resource->set_pixels_completion_forced); | 1709 DCHECK(resource->set_pixels_completion_forced); |
1472 resource->pending_set_pixels = false; | 1710 resource->pending_set_pixels = false; |
1473 UnlockForWrite(id); | 1711 resource->locked_for_write = false; |
1474 } | 1712 } |
1475 | 1713 |
1476 if (resource->type == GLTexture) { | 1714 if (resource->type == GLTexture) { |
1477 if (!resource->gl_pixel_buffer_id) | 1715 if (!resource->gl_pixel_buffer_id) |
1478 return; | 1716 return; |
1479 GLES2Interface* gl = ContextGL(); | 1717 GLES2Interface* gl = ContextGL(); |
1480 DCHECK(gl); | 1718 DCHECK(gl); |
1481 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1719 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
1482 resource->gl_pixel_buffer_id); | 1720 resource->gl_pixel_buffer_id); |
1483 gl->BufferData( | 1721 gl->BufferData( |
1484 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0, NULL, GL_DYNAMIC_DRAW); | 1722 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0, NULL, GL_DYNAMIC_DRAW); |
1485 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | 1723 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
1486 } else { | 1724 } else { |
1487 DCHECK_EQ(Bitmap, resource->type); | 1725 DCHECK_EQ(Bitmap, resource->type); |
1488 if (!resource->pixel_buffer) | 1726 if (!resource->pixel_buffer) |
1489 return; | 1727 return; |
1490 delete[] resource->pixel_buffer; | 1728 delete[] resource->pixel_buffer; |
1491 resource->pixel_buffer = NULL; | 1729 resource->pixel_buffer = NULL; |
1492 } | 1730 } |
1493 } | 1731 } |
1494 | 1732 |
1495 uint8_t* ResourceProvider::MapPixelBuffer(ResourceId id) { | 1733 uint8_t* ResourceProvider::MapPixelBuffer(const Resource* resource, |
1496 Resource* resource = GetResource(id); | 1734 int* stride) { |
1497 DCHECK(resource->origin == Resource::Internal); | 1735 DCHECK(resource->origin == Resource::Internal); |
1498 DCHECK_EQ(resource->exported_count, 0); | 1736 DCHECK_EQ(resource->exported_count, 0); |
1499 DCHECK(!resource->image_id); | 1737 DCHECK(!resource->image_id); |
1500 | 1738 |
| 1739 *stride = 0; |
1501 if (resource->type == GLTexture) { | 1740 if (resource->type == GLTexture) { |
1502 GLES2Interface* gl = ContextGL(); | 1741 GLES2Interface* gl = ContextGL(); |
1503 DCHECK(gl); | 1742 DCHECK(gl); |
1504 DCHECK(resource->gl_pixel_buffer_id); | 1743 DCHECK(resource->gl_pixel_buffer_id); |
1505 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1744 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
1506 resource->gl_pixel_buffer_id); | 1745 resource->gl_pixel_buffer_id); |
1507 uint8_t* image = static_cast<uint8_t*>(gl->MapBufferCHROMIUM( | 1746 uint8_t* image = static_cast<uint8_t*>(gl->MapBufferCHROMIUM( |
1508 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, GL_WRITE_ONLY)); | 1747 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, GL_WRITE_ONLY)); |
1509 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | 1748 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
1510 // Buffer is required to be 4-byte aligned. | 1749 // Buffer is required to be 4-byte aligned. |
1511 CHECK(!(reinterpret_cast<intptr_t>(image) & 3)); | 1750 CHECK(!(reinterpret_cast<intptr_t>(image) & 3)); |
1512 return image; | 1751 return image; |
1513 } | 1752 } |
1514 DCHECK_EQ(Bitmap, resource->type); | 1753 DCHECK_EQ(Bitmap, resource->type); |
1515 return resource->pixel_buffer; | 1754 return resource->pixel_buffer; |
1516 } | 1755 } |
1517 | 1756 |
1518 void ResourceProvider::UnmapPixelBuffer(ResourceId id) { | 1757 void ResourceProvider::UnmapPixelBuffer(const Resource* resource) { |
1519 Resource* resource = GetResource(id); | |
1520 DCHECK(resource->origin == Resource::Internal); | 1758 DCHECK(resource->origin == Resource::Internal); |
1521 DCHECK_EQ(resource->exported_count, 0); | 1759 DCHECK_EQ(resource->exported_count, 0); |
1522 DCHECK(!resource->image_id); | 1760 DCHECK(!resource->image_id); |
1523 | 1761 |
1524 if (resource->type == GLTexture) { | 1762 if (resource->type == GLTexture) { |
1525 GLES2Interface* gl = ContextGL(); | 1763 GLES2Interface* gl = ContextGL(); |
1526 DCHECK(gl); | 1764 DCHECK(gl); |
1527 DCHECK(resource->gl_pixel_buffer_id); | 1765 DCHECK(resource->gl_pixel_buffer_id); |
1528 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1766 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
1529 resource->gl_pixel_buffer_id); | 1767 resource->gl_pixel_buffer_id); |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1761 resource->bound_image_id = resource->image_id; | 1999 resource->bound_image_id = resource->image_id; |
1762 resource->dirty_image = false; | 2000 resource->dirty_image = false; |
1763 } | 2001 } |
1764 | 2002 |
1765 void ResourceProvider::EnableReadLockFences(ResourceProvider::ResourceId id, | 2003 void ResourceProvider::EnableReadLockFences(ResourceProvider::ResourceId id, |
1766 bool enable) { | 2004 bool enable) { |
1767 Resource* resource = GetResource(id); | 2005 Resource* resource = GetResource(id); |
1768 resource->enable_read_lock_fences = enable; | 2006 resource->enable_read_lock_fences = enable; |
1769 } | 2007 } |
1770 | 2008 |
1771 void ResourceProvider::AcquireImage(ResourceId id) { | 2009 void ResourceProvider::AcquireImage(Resource* resource) { |
1772 Resource* resource = GetResource(id); | |
1773 DCHECK(resource->origin == Resource::Internal); | 2010 DCHECK(resource->origin == Resource::Internal); |
1774 DCHECK_EQ(resource->exported_count, 0); | 2011 DCHECK_EQ(resource->exported_count, 0); |
1775 | 2012 |
1776 if (resource->type != GLTexture) | 2013 if (resource->type != GLTexture) |
1777 return; | 2014 return; |
1778 | 2015 |
1779 if (resource->image_id) | 2016 if (resource->image_id) |
1780 return; | 2017 return; |
1781 | 2018 |
1782 resource->allocated = true; | 2019 resource->allocated = true; |
1783 GLES2Interface* gl = ContextGL(); | 2020 GLES2Interface* gl = ContextGL(); |
1784 DCHECK(gl); | 2021 DCHECK(gl); |
1785 resource->image_id = | 2022 resource->image_id = |
1786 gl->CreateImageCHROMIUM(resource->size.width(), | 2023 gl->CreateImageCHROMIUM(resource->size.width(), |
1787 resource->size.height(), | 2024 resource->size.height(), |
1788 TextureToStorageFormat(resource->format)); | 2025 TextureToStorageFormat(resource->format)); |
1789 DCHECK(resource->image_id); | 2026 DCHECK(resource->image_id); |
1790 } | 2027 } |
1791 | 2028 |
1792 void ResourceProvider::ReleaseImage(ResourceId id) { | 2029 void ResourceProvider::ReleaseImage(Resource* resource) { |
1793 Resource* resource = GetResource(id); | |
1794 DCHECK(resource->origin == Resource::Internal); | 2030 DCHECK(resource->origin == Resource::Internal); |
1795 DCHECK_EQ(resource->exported_count, 0); | 2031 DCHECK_EQ(resource->exported_count, 0); |
1796 | 2032 |
1797 if (!resource->image_id) | 2033 if (!resource->image_id) |
1798 return; | 2034 return; |
1799 | 2035 |
1800 GLES2Interface* gl = ContextGL(); | 2036 GLES2Interface* gl = ContextGL(); |
1801 DCHECK(gl); | 2037 DCHECK(gl); |
1802 gl->DestroyImageCHROMIUM(resource->image_id); | 2038 gl->DestroyImageCHROMIUM(resource->image_id); |
1803 resource->image_id = 0; | 2039 resource->image_id = 0; |
1804 resource->bound_image_id = 0; | 2040 resource->bound_image_id = 0; |
1805 resource->dirty_image = false; | 2041 resource->dirty_image = false; |
1806 resource->allocated = false; | 2042 resource->allocated = false; |
1807 } | 2043 } |
1808 | 2044 |
1809 uint8_t* ResourceProvider::MapImage(ResourceId id) { | 2045 uint8_t* ResourceProvider::MapImage(const Resource* resource, int* stride) { |
1810 Resource* resource = GetResource(id); | |
1811 DCHECK(ReadLockFenceHasPassed(resource)); | 2046 DCHECK(ReadLockFenceHasPassed(resource)); |
1812 DCHECK(resource->origin == Resource::Internal); | 2047 DCHECK(resource->origin == Resource::Internal); |
1813 DCHECK_EQ(resource->exported_count, 0); | 2048 DCHECK_EQ(resource->exported_count, 0); |
1814 | 2049 |
1815 if (resource->type == GLTexture) { | 2050 if (resource->type == GLTexture) { |
1816 DCHECK(resource->image_id); | 2051 DCHECK(resource->image_id); |
1817 GLES2Interface* gl = ContextGL(); | 2052 GLES2Interface* gl = ContextGL(); |
1818 DCHECK(gl); | 2053 DCHECK(gl); |
| 2054 gl->GetImageParameterivCHROMIUM( |
| 2055 resource->image_id, GL_IMAGE_ROWBYTES_CHROMIUM, stride); |
1819 return static_cast<uint8_t*>( | 2056 return static_cast<uint8_t*>( |
1820 gl->MapImageCHROMIUM(resource->image_id, GL_READ_WRITE)); | 2057 gl->MapImageCHROMIUM(resource->image_id, GL_READ_WRITE)); |
1821 } | 2058 } |
1822 DCHECK_EQ(Bitmap, resource->type); | 2059 DCHECK_EQ(Bitmap, resource->type); |
| 2060 *stride = 0; |
1823 return resource->pixels; | 2061 return resource->pixels; |
1824 } | 2062 } |
1825 | 2063 |
1826 void ResourceProvider::UnmapImage(ResourceId id) { | 2064 void ResourceProvider::UnmapImage(const Resource* resource) { |
1827 Resource* resource = GetResource(id); | |
1828 DCHECK(resource->origin == Resource::Internal); | 2065 DCHECK(resource->origin == Resource::Internal); |
1829 DCHECK_EQ(resource->exported_count, 0); | 2066 DCHECK_EQ(resource->exported_count, 0); |
1830 | 2067 |
1831 if (resource->image_id) { | 2068 if (resource->image_id) { |
1832 GLES2Interface* gl = ContextGL(); | 2069 GLES2Interface* gl = ContextGL(); |
1833 DCHECK(gl); | 2070 DCHECK(gl); |
1834 gl->UnmapImageCHROMIUM(resource->image_id); | 2071 gl->UnmapImageCHROMIUM(resource->image_id); |
1835 resource->dirty_image = true; | |
1836 } | 2072 } |
1837 } | 2073 } |
1838 | 2074 |
1839 int ResourceProvider::GetImageStride(ResourceId id) { | |
1840 Resource* resource = GetResource(id); | |
1841 DCHECK(resource->origin == Resource::Internal); | |
1842 DCHECK_EQ(resource->exported_count, 0); | |
1843 | |
1844 int stride = 0; | |
1845 | |
1846 if (resource->image_id) { | |
1847 GLES2Interface* gl = ContextGL(); | |
1848 DCHECK(gl); | |
1849 gl->GetImageParameterivCHROMIUM( | |
1850 resource->image_id, GL_IMAGE_ROWBYTES_CHROMIUM, &stride); | |
1851 } | |
1852 | |
1853 return stride; | |
1854 } | |
1855 | |
1856 GLint ResourceProvider::GetActiveTextureUnit(GLES2Interface* gl) { | 2075 GLint ResourceProvider::GetActiveTextureUnit(GLES2Interface* gl) { |
1857 GLint active_unit = 0; | 2076 GLint active_unit = 0; |
1858 gl->GetIntegerv(GL_ACTIVE_TEXTURE, &active_unit); | 2077 gl->GetIntegerv(GL_ACTIVE_TEXTURE, &active_unit); |
1859 return active_unit; | 2078 return active_unit; |
1860 } | 2079 } |
1861 | 2080 |
1862 GLES2Interface* ResourceProvider::ContextGL() const { | 2081 GLES2Interface* ResourceProvider::ContextGL() const { |
1863 ContextProvider* context_provider = output_surface_->context_provider(); | 2082 ContextProvider* context_provider = output_surface_->context_provider(); |
1864 return context_provider ? context_provider->ContextGL() : NULL; | 2083 return context_provider ? context_provider->ContextGL() : NULL; |
1865 } | 2084 } |
1866 | 2085 |
| 2086 class GrContext* ResourceProvider::GrContext() const { |
| 2087 ContextProvider* context_provider = output_surface_->context_provider(); |
| 2088 return context_provider ? context_provider->GrContext() : NULL; |
| 2089 } |
| 2090 |
1867 } // namespace cc | 2091 } // namespace cc |
OLD | NEW |