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

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

Issue 562833004: cc: Move RasterBuffer implementations from ResourceProvider to RasterWorkerPool implementations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: move NullCanvas change to separate patch Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/resources/resource_provider.h" 5 #include "cc/resources/resource_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/containers/hash_tables.h" 10 #include "base/containers/hash_tables.h"
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" 26 #include "third_party/skia/include/core/SkSurface.h"
27 #include "third_party/skia/include/gpu/GrContext.h" 27 #include "third_party/skia/include/gpu/GrContext.h"
28 #include "third_party/skia/include/utils/SkNullCanvas.h"
29 #include "ui/gfx/frame_time.h" 28 #include "ui/gfx/frame_time.h"
30 #include "ui/gfx/rect.h" 29 #include "ui/gfx/rect.h"
31 #include "ui/gfx/vector2d.h" 30 #include "ui/gfx/vector2d.h"
32 31
33 using gpu::gles2::GLES2Interface; 32 using gpu::gles2::GLES2Interface;
34 33
35 namespace cc { 34 namespace cc {
36 35
37 class IdAllocator { 36 class IdAllocator {
38 public: 37 public:
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 return kBGRA_8888_GrPixelConfig; 104 return kBGRA_8888_GrPixelConfig;
106 case RGBA_4444: 105 case RGBA_4444:
107 return kRGBA_4444_GrPixelConfig; 106 return kRGBA_4444_GrPixelConfig;
108 default: 107 default:
109 break; 108 break;
110 } 109 }
111 DCHECK(false) << "Unsupported resource format."; 110 DCHECK(false) << "Unsupported resource format.";
112 return kSkia8888_GrPixelConfig; 111 return kSkia8888_GrPixelConfig;
113 } 112 }
114 113
115 void MakeBitmap(SkBitmap* bitmap,
116 uint8_t* buffer,
117 ResourceFormat format,
118 const gfx::Size& size,
119 int stride) {
120 switch (format) {
121 case RGBA_4444:
122 // Use the default stride if we will eventually convert this
123 // bitmap to 4444.
124 bitmap->allocN32Pixels(size.width(), size.height());
125 break;
126 case RGBA_8888:
127 case BGRA_8888: {
128 SkImageInfo info =
129 SkImageInfo::MakeN32Premul(size.width(), size.height());
130 if (0 == stride)
131 stride = info.minRowBytes();
132 bitmap->installPixels(info, buffer, stride);
133 break;
134 }
135 case ALPHA_8:
136 case LUMINANCE_8:
137 case RGB_565:
138 case ETC1:
139 NOTREACHED();
140 break;
141 }
142 }
143
144 void CopyBitmap(const SkBitmap& src, uint8_t* dst, SkColorType dst_color_type) {
145 SkImageInfo dst_info = src.info();
146 dst_info.fColorType = dst_color_type;
147 // TODO(kaanb): The GL pipeline assumes a 4-byte alignment for the
148 // bitmap data. There will be no need to call SkAlign4 once crbug.com/293728
149 // is fixed.
150 const size_t dst_row_bytes = SkAlign4(dst_info.minRowBytes());
151 CHECK_EQ(0u, dst_row_bytes % 4);
152 bool success = src.readPixels(dst_info, dst, dst_row_bytes, 0, 0);
153 CHECK_EQ(true, success);
154 }
155
156 class ScopedSetActiveTexture { 114 class ScopedSetActiveTexture {
157 public: 115 public:
158 ScopedSetActiveTexture(GLES2Interface* gl, GLenum unit) 116 ScopedSetActiveTexture(GLES2Interface* gl, GLenum unit)
159 : gl_(gl), unit_(unit) { 117 : gl_(gl), unit_(unit) {
160 DCHECK_EQ(GL_TEXTURE0, ResourceProvider::GetActiveTextureUnit(gl_)); 118 DCHECK_EQ(GL_TEXTURE0, ResourceProvider::GetActiveTextureUnit(gl_));
161 119
162 if (unit_ != GL_TEXTURE0) 120 if (unit_ != GL_TEXTURE0)
163 GLC(gl_, gl_->ActiveTexture(unit_)); 121 GLC(gl_, gl_->ActiveTexture(unit_));
164 } 122 }
165 123
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 texture_pool(0), 370 texture_pool(0),
413 wrap_mode(wrap_mode), 371 wrap_mode(wrap_mode),
414 hint(TextureHintImmutable), 372 hint(TextureHintImmutable),
415 type(Bitmap), 373 type(Bitmap),
416 format(RGBA_8888), 374 format(RGBA_8888),
417 shared_bitmap_id(bitmap_id), 375 shared_bitmap_id(bitmap_id),
418 shared_bitmap(NULL) { 376 shared_bitmap(NULL) {
419 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); 377 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT);
420 } 378 }
421 379
422 ResourceProvider::GpuRasterBuffer::GpuRasterBuffer(
423 const Resource* resource,
424 ResourceProvider* resource_provider,
425 bool use_distance_field_text)
426 : resource_(resource), resource_provider_(resource_provider) {
427 DCHECK_EQ(GLTexture, resource_->type);
428 DCHECK(resource_->gl_id);
429
430 class GrContext* gr_context = resource_provider_->GrContext();
431 // TODO(alokp): Implement TestContextProvider::GrContext().
432 if (gr_context) {
433 GrBackendTextureDesc desc;
434 desc.fFlags = kRenderTarget_GrBackendTextureFlag;
435 desc.fWidth = resource_->size.width();
436 desc.fHeight = resource_->size.height();
437 desc.fConfig = ToGrPixelConfig(resource_->format);
438 desc.fOrigin = kTopLeft_GrSurfaceOrigin;
439 desc.fTextureHandle = resource_->gl_id;
440 skia::RefPtr<GrTexture> gr_texture =
441 skia::AdoptRef(gr_context->wrapBackendTexture(desc));
442 SkSurface::TextRenderMode text_render_mode =
443 use_distance_field_text ? SkSurface::kDistanceField_TextRenderMode
444 : SkSurface::kStandard_TextRenderMode;
445 surface_ = skia::AdoptRef(SkSurface::NewRenderTargetDirect(
446 gr_texture->asRenderTarget(), text_render_mode));
447 }
448 }
449
450 ResourceProvider::GpuRasterBuffer::~GpuRasterBuffer() {
451 }
452
453 skia::RefPtr<SkCanvas> ResourceProvider::GpuRasterBuffer::AcquireSkCanvas() {
454 // Note that this function is called from a worker thread.
455 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"),
456 "ResourceProvider::GpuRasterBuffer::AcquireSkCanvas");
457
458 skia::RefPtr<SkCanvas> canvas = surface_
459 ? skia::SharePtr(surface_->getCanvas())
460 : skia::AdoptRef(SkCreateNullCanvas());
461 canvas->save();
462 return canvas;
463 }
464
465 void ResourceProvider::GpuRasterBuffer::ReleaseSkCanvas(
466 const skia::RefPtr<SkCanvas>& canvas) {
467 // Note that this function is called from a worker thread.
468 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"),
469 "ResourceProvider::GpuRasterBuffer::ReleaseSkCanvas");
470
471 canvas->restore();
472 }
473
474 ResourceProvider::ImageRasterBuffer::ImageRasterBuffer(
475 const Resource* resource,
476 ResourceProvider* resource_provider)
477 : resource_(resource),
478 resource_provider_(resource_provider),
479 mapped_buffer_(NULL),
480 raster_bitmap_changed_(false),
481 stride_(0) {
482 }
483
484 ResourceProvider::ImageRasterBuffer::~ImageRasterBuffer() {
485 }
486
487 void ResourceProvider::ImageRasterBuffer::MapBuffer() {
488 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"),
489 "ResourceProvider::ImageRasterBuffer::MapBuffer");
490
491 DCHECK(!mapped_buffer_);
492
493 stride_ = 0;
494 mapped_buffer_ = resource_provider_->MapImage(resource_, &stride_);
495 raster_bitmap_changed_ = false;
496 }
497
498 bool ResourceProvider::ImageRasterBuffer::UnmapBuffer() {
499 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"),
500 "ResourceProvider::ImageRasterBuffer::UnmapBuffer");
501
502 if (mapped_buffer_) {
503 resource_provider_->UnmapImage(resource_);
504 mapped_buffer_ = NULL;
505 }
506 return raster_bitmap_changed_;
507 }
508
509 skia::RefPtr<SkCanvas> ResourceProvider::ImageRasterBuffer::AcquireSkCanvas() {
510 // Note that this function is called from a worker thread.
511 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"),
512 "ResourceProvider::ImageRasterBuffer::AcquireSkCanvas");
513
514 if (!mapped_buffer_)
515 return skia::AdoptRef(SkCreateNullCanvas());
516
517 MakeBitmap(&raster_bitmap_,
518 mapped_buffer_,
519 resource_->format,
520 resource_->size,
521 stride_);
522 raster_bitmap_changed_ = true;
523 return skia::AdoptRef(new SkCanvas(raster_bitmap_));
524 }
525
526 void ResourceProvider::ImageRasterBuffer::ReleaseSkCanvas(
527 const skia::RefPtr<SkCanvas>& canvas) {
528 // Note that this function is called from a worker thread.
529 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"),
530 "ResourceProvider::ImageRasterBuffer::ReleaseSkCanvas");
531
532 SkColorType buffer_colorType = ResourceFormatToSkColorType(resource_->format);
533 if (mapped_buffer_ && (buffer_colorType != raster_bitmap_.colorType()))
534 CopyBitmap(raster_bitmap_, mapped_buffer_, buffer_colorType);
535 raster_bitmap_.reset();
536 }
537
538 ResourceProvider::PixelRasterBuffer::PixelRasterBuffer(
539 const Resource* resource,
540 ResourceProvider* resource_provider)
541 : resource_(resource),
542 resource_provider_(resource_provider),
543 mapped_buffer_(NULL),
544 raster_bitmap_changed_(false),
545 stride_(0) {
546 }
547
548 ResourceProvider::PixelRasterBuffer::~PixelRasterBuffer() {
549 }
550
551 void ResourceProvider::PixelRasterBuffer::MapBuffer() {
552 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"),
553 "ResourceProvider::PixelRasterBuffer::MapBuffer");
554
555 DCHECK(!mapped_buffer_);
556
557 stride_ = 0;
558 mapped_buffer_ = resource_provider_->MapPixelBuffer(resource_, &stride_);
559 raster_bitmap_changed_ = false;
560 }
561
562 bool ResourceProvider::PixelRasterBuffer::UnmapBuffer() {
563 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"),
564 "ResourceProvider::PixelRasterBuffer::UnmapBuffer");
565
566 if (mapped_buffer_) {
567 resource_provider_->UnmapPixelBuffer(resource_);
568 mapped_buffer_ = NULL;
569 }
570 return raster_bitmap_changed_;
571 }
572
573 skia::RefPtr<SkCanvas> ResourceProvider::PixelRasterBuffer::AcquireSkCanvas() {
574 // Note that this function is called from a worker thread.
575 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"),
576 "ResourceProvider::PixelRasterBuffer::AcquireSkCanvas");
577
578 if (!mapped_buffer_)
579 return skia::AdoptRef(SkCreateNullCanvas());
580
581 MakeBitmap(&raster_bitmap_,
582 mapped_buffer_,
583 resource_->format,
584 resource_->size,
585 stride_);
586 raster_bitmap_changed_ = true;
587 return skia::AdoptRef(new SkCanvas(raster_bitmap_));
588 }
589
590 void ResourceProvider::PixelRasterBuffer::ReleaseSkCanvas(
591 const skia::RefPtr<SkCanvas>& canvas) {
592 // Note that this function is called from a worker thread.
593 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"),
594 "ResourceProvider::PixelRasterBuffer::ReleaseSkCanvas");
595
596 SkColorType buffer_colorType = ResourceFormatToSkColorType(resource_->format);
597 if (mapped_buffer_ && (buffer_colorType != raster_bitmap_.colorType()))
598 CopyBitmap(raster_bitmap_, mapped_buffer_, buffer_colorType);
599 raster_bitmap_.reset();
600 }
601
602 ResourceProvider::Child::Child() : marked_for_deletion(false) {} 380 ResourceProvider::Child::Child() : marked_for_deletion(false) {}
603 381
604 ResourceProvider::Child::~Child() {} 382 ResourceProvider::Child::~Child() {}
605 383
606 scoped_ptr<ResourceProvider> ResourceProvider::Create( 384 scoped_ptr<ResourceProvider> ResourceProvider::Create(
607 OutputSurface* output_surface, 385 OutputSurface* output_surface,
608 SharedBitmapManager* shared_bitmap_manager, 386 SharedBitmapManager* shared_bitmap_manager,
609 BlockingTaskRunner* blocking_main_thread_task_runner, 387 BlockingTaskRunner* blocking_main_thread_task_runner,
610 int highp_threshold_min, 388 int highp_threshold_min,
611 bool use_rgba_4444_texture_format, 389 bool use_rgba_4444_texture_format,
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 void ResourceProvider::DeleteResourceInternal(ResourceMap::iterator it, 625 void ResourceProvider::DeleteResourceInternal(ResourceMap::iterator it,
848 DeleteStyle style) { 626 DeleteStyle style) {
849 TRACE_EVENT0("cc", "ResourceProvider::DeleteResourceInternal"); 627 TRACE_EVENT0("cc", "ResourceProvider::DeleteResourceInternal");
850 Resource* resource = &it->second; 628 Resource* resource = &it->second;
851 bool lost_resource = resource->lost; 629 bool lost_resource = resource->lost;
852 630
853 DCHECK(resource->exported_count == 0 || style != Normal); 631 DCHECK(resource->exported_count == 0 || style != Normal);
854 if (style == ForShutdown && resource->exported_count > 0) 632 if (style == ForShutdown && resource->exported_count > 0)
855 lost_resource = true; 633 lost_resource = true;
856 634
857 resource->gpu_raster_buffer.reset();
858 resource->image_raster_buffer.reset();
859 resource->pixel_raster_buffer.reset();
860
861 if (resource->image_id) { 635 if (resource->image_id) {
862 DCHECK(resource->origin == Resource::Internal); 636 DCHECK(resource->origin == Resource::Internal);
863 GLES2Interface* gl = ContextGL(); 637 GLES2Interface* gl = ContextGL();
864 DCHECK(gl); 638 DCHECK(gl);
865 GLC(gl, gl->DestroyImageCHROMIUM(resource->image_id)); 639 GLC(gl, gl->DestroyImageCHROMIUM(resource->image_id));
866 } 640 }
867 if (resource->gl_upload_query_id) { 641 if (resource->gl_upload_query_id) {
868 DCHECK(resource->origin == Resource::Internal); 642 DCHECK(resource->origin == Resource::Internal);
869 GLES2Interface* gl = ContextGL(); 643 GLES2Interface* gl = ContextGL();
870 DCHECK(gl); 644 DCHECK(gl);
(...skipping 880 matching lines...) Expand 10 before | Expand all | Expand 10 after
1751 child_info->return_callback.Run(to_return, 1525 child_info->return_callback.Run(to_return,
1752 blocking_main_thread_task_runner_); 1526 blocking_main_thread_task_runner_);
1753 1527
1754 if (child_info->marked_for_deletion && 1528 if (child_info->marked_for_deletion &&
1755 child_info->parent_to_child_map.empty()) { 1529 child_info->parent_to_child_map.empty()) {
1756 DCHECK(child_info->child_to_parent_map.empty()); 1530 DCHECK(child_info->child_to_parent_map.empty());
1757 children_.erase(child_it); 1531 children_.erase(child_it);
1758 } 1532 }
1759 } 1533 }
1760 1534
1761 RasterBuffer* ResourceProvider::AcquireGpuRasterBuffer(ResourceId id) { 1535 void ResourceProvider::AcquirePixelBuffer(ResourceId id) {
1762 // Resource needs to be locked for write since GpuRasterBuffer writes
1763 // directly to it.
1764 LockForWrite(id);
1765 Resource* resource = GetResource(id);
1766 if (!resource->gpu_raster_buffer.get()) {
1767 resource->gpu_raster_buffer.reset(
1768 new GpuRasterBuffer(resource, this, use_distance_field_text_));
1769 }
1770 return resource->gpu_raster_buffer.get();
1771 }
1772
1773 void ResourceProvider::ReleaseGpuRasterBuffer(ResourceId id) {
1774 Resource* resource = GetResource(id);
1775 DCHECK(resource->gpu_raster_buffer.get());
1776 UnlockForWrite(id);
1777 }
1778
1779 RasterBuffer* ResourceProvider::AcquireImageRasterBuffer(ResourceId id) {
1780 Resource* resource = GetResource(id);
1781 AcquireImage(resource);
1782 if (!resource->image_raster_buffer.get())
1783 resource->image_raster_buffer.reset(new ImageRasterBuffer(resource, this));
1784 resource->image_raster_buffer->MapBuffer();
1785 return resource->image_raster_buffer.get();
1786 }
1787
1788 bool ResourceProvider::ReleaseImageRasterBuffer(ResourceId id) {
1789 Resource* resource = GetResource(id);
1790 resource->dirty_image = true;
1791 return resource->image_raster_buffer->UnmapBuffer();
1792 }
1793
1794 RasterBuffer* ResourceProvider::AcquirePixelRasterBuffer(ResourceId id) {
1795 Resource* resource = GetResource(id);
1796 AcquirePixelBuffer(resource);
1797 resource->pixel_raster_buffer.reset(new PixelRasterBuffer(resource, this));
1798 resource->pixel_raster_buffer->MapBuffer();
1799 return resource->pixel_raster_buffer.get();
1800 }
1801
1802 bool ResourceProvider::ReleasePixelRasterBuffer(ResourceId id) {
1803 Resource* resource = GetResource(id);
1804 DCHECK(resource->pixel_raster_buffer.get());
1805 bool raster_bitmap_changed = resource->pixel_raster_buffer->UnmapBuffer();
1806 resource->pixel_raster_buffer.reset();
1807 ReleasePixelBuffer(resource);
1808 return raster_bitmap_changed;
1809 }
1810
1811 void ResourceProvider::AcquirePixelBuffer(Resource* resource) {
1812 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), 1536 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"),
1813 "ResourceProvider::AcquirePixelBuffer"); 1537 "ResourceProvider::AcquirePixelBuffer");
1814 1538
1539 Resource* resource = GetResource(id);
1815 DCHECK(resource->origin == Resource::Internal); 1540 DCHECK(resource->origin == Resource::Internal);
1816 DCHECK_EQ(resource->exported_count, 0); 1541 DCHECK_EQ(resource->exported_count, 0);
1817 DCHECK(!resource->image_id); 1542 DCHECK(!resource->image_id);
1818 DCHECK_NE(ETC1, resource->format); 1543 DCHECK_NE(ETC1, resource->format);
1819 1544
1820 DCHECK_EQ(GLTexture, resource->type); 1545 DCHECK_EQ(GLTexture, resource->type);
1821 GLES2Interface* gl = ContextGL(); 1546 GLES2Interface* gl = ContextGL();
1822 DCHECK(gl); 1547 DCHECK(gl);
1823 if (!resource->gl_pixel_buffer_id) 1548 if (!resource->gl_pixel_buffer_id)
1824 resource->gl_pixel_buffer_id = buffer_id_allocator_->NextId(); 1549 resource->gl_pixel_buffer_id = buffer_id_allocator_->NextId();
1825 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 1550 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
1826 resource->gl_pixel_buffer_id); 1551 resource->gl_pixel_buffer_id);
1827 unsigned bytes_per_pixel = BitsPerPixel(resource->format) / 8; 1552 unsigned bytes_per_pixel = BitsPerPixel(resource->format) / 8;
1828 gl->BufferData(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 1553 gl->BufferData(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
1829 resource->size.height() * 1554 resource->size.height() *
1830 RoundUp(bytes_per_pixel * resource->size.width(), 4u), 1555 RoundUp(bytes_per_pixel * resource->size.width(), 4u),
1831 NULL, 1556 NULL,
1832 GL_DYNAMIC_DRAW); 1557 GL_DYNAMIC_DRAW);
1833 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); 1558 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0);
1834 } 1559 }
1835 1560
1836 void ResourceProvider::ReleasePixelBuffer(Resource* resource) { 1561 void ResourceProvider::ReleasePixelBuffer(ResourceId id) {
1837 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), 1562 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"),
1838 "ResourceProvider::ReleasePixelBuffer"); 1563 "ResourceProvider::ReleasePixelBuffer");
1839 1564
1565 Resource* resource = GetResource(id);
1840 DCHECK(resource->origin == Resource::Internal); 1566 DCHECK(resource->origin == Resource::Internal);
1841 DCHECK_EQ(resource->exported_count, 0); 1567 DCHECK_EQ(resource->exported_count, 0);
1842 DCHECK(!resource->image_id); 1568 DCHECK(!resource->image_id);
1843 1569
1844 // The pixel buffer can be released while there is a pending "set pixels" 1570 // The pixel buffer can be released while there is a pending "set pixels"
1845 // if completion has been forced. Any shared memory associated with this 1571 // if completion has been forced. Any shared memory associated with this
1846 // pixel buffer will not be freed until the waitAsyncTexImage2DCHROMIUM 1572 // pixel buffer will not be freed until the waitAsyncTexImage2DCHROMIUM
1847 // command has been processed on the service side. It is also safe to 1573 // command has been processed on the service side. It is also safe to
1848 // reuse any query id associated with this resource before they complete 1574 // reuse any query id associated with this resource before they complete
1849 // as each new query has a unique submit count. 1575 // as each new query has a unique submit count.
1850 if (resource->pending_set_pixels) { 1576 if (resource->pending_set_pixels) {
1851 DCHECK(resource->set_pixels_completion_forced); 1577 DCHECK(resource->set_pixels_completion_forced);
1852 resource->pending_set_pixels = false; 1578 resource->pending_set_pixels = false;
1853 resource->locked_for_write = false; 1579 resource->locked_for_write = false;
1854 } 1580 }
1855 1581
1856 DCHECK_EQ(GLTexture, resource->type); 1582 DCHECK_EQ(GLTexture, resource->type);
1857 if (!resource->gl_pixel_buffer_id) 1583 if (!resource->gl_pixel_buffer_id)
1858 return; 1584 return;
1859 GLES2Interface* gl = ContextGL(); 1585 GLES2Interface* gl = ContextGL();
1860 DCHECK(gl); 1586 DCHECK(gl);
1861 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 1587 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
1862 resource->gl_pixel_buffer_id); 1588 resource->gl_pixel_buffer_id);
1863 gl->BufferData( 1589 gl->BufferData(
1864 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0, NULL, GL_DYNAMIC_DRAW); 1590 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0, NULL, GL_DYNAMIC_DRAW);
1865 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); 1591 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0);
1866 } 1592 }
1867 1593
1868 uint8_t* ResourceProvider::MapPixelBuffer(const Resource* resource, 1594 uint8_t* ResourceProvider::MapPixelBuffer(ResourceId id, int* stride) {
1869 int* stride) {
1870 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), 1595 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"),
1871 "ResourceProvider::MapPixelBuffer"); 1596 "ResourceProvider::MapPixelBuffer");
1872 1597
1598 Resource* resource = GetResource(id);
1873 DCHECK(resource->origin == Resource::Internal); 1599 DCHECK(resource->origin == Resource::Internal);
1874 DCHECK_EQ(resource->exported_count, 0); 1600 DCHECK_EQ(resource->exported_count, 0);
1875 DCHECK(!resource->image_id); 1601 DCHECK(!resource->image_id);
1876 1602
1877 *stride = 0; 1603 *stride = 0;
1878 DCHECK_EQ(GLTexture, resource->type); 1604 DCHECK_EQ(GLTexture, resource->type);
1879 GLES2Interface* gl = ContextGL(); 1605 GLES2Interface* gl = ContextGL();
1880 DCHECK(gl); 1606 DCHECK(gl);
1881 DCHECK(resource->gl_pixel_buffer_id); 1607 DCHECK(resource->gl_pixel_buffer_id);
1882 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 1608 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
1883 resource->gl_pixel_buffer_id); 1609 resource->gl_pixel_buffer_id);
1884 uint8_t* image = static_cast<uint8_t*>(gl->MapBufferCHROMIUM( 1610 uint8_t* image = static_cast<uint8_t*>(gl->MapBufferCHROMIUM(
1885 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, GL_WRITE_ONLY)); 1611 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, GL_WRITE_ONLY));
1886 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); 1612 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0);
1887 // Buffer is required to be 4-byte aligned. 1613 // Buffer is required to be 4-byte aligned.
1888 CHECK(!(reinterpret_cast<intptr_t>(image) & 3)); 1614 CHECK(!(reinterpret_cast<intptr_t>(image) & 3));
1889 return image; 1615 return image;
1890 } 1616 }
1891 1617
1892 void ResourceProvider::UnmapPixelBuffer(const Resource* resource) { 1618 void ResourceProvider::UnmapPixelBuffer(ResourceId id) {
1893 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), 1619 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"),
1894 "ResourceProvider::UnmapPixelBuffer"); 1620 "ResourceProvider::UnmapPixelBuffer");
1895 1621
1622 Resource* resource = GetResource(id);
1896 DCHECK(resource->origin == Resource::Internal); 1623 DCHECK(resource->origin == Resource::Internal);
1897 DCHECK_EQ(resource->exported_count, 0); 1624 DCHECK_EQ(resource->exported_count, 0);
1898 DCHECK(!resource->image_id); 1625 DCHECK(!resource->image_id);
1899 1626
1900 DCHECK_EQ(GLTexture, resource->type); 1627 DCHECK_EQ(GLTexture, resource->type);
1901 GLES2Interface* gl = ContextGL(); 1628 GLES2Interface* gl = ContextGL();
1902 DCHECK(gl); 1629 DCHECK(gl);
1903 DCHECK(resource->gl_pixel_buffer_id); 1630 DCHECK(resource->gl_pixel_buffer_id);
1904 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 1631 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
1905 resource->gl_pixel_buffer_id); 1632 resource->gl_pixel_buffer_id);
1906 gl->UnmapBufferCHROMIUM(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM); 1633 gl->UnmapBufferCHROMIUM(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM);
1907 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); 1634 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0);
1908 } 1635 }
1909 1636
1910 GLenum ResourceProvider::BindForSampling( 1637 GLenum ResourceProvider::BindForSampling(ResourceId resource_id,
1911 ResourceProvider::ResourceId resource_id, 1638 GLenum unit,
1912 GLenum unit, 1639 GLenum filter) {
1913 GLenum filter) {
1914 DCHECK(thread_checker_.CalledOnValidThread()); 1640 DCHECK(thread_checker_.CalledOnValidThread());
1915 GLES2Interface* gl = ContextGL(); 1641 GLES2Interface* gl = ContextGL();
1916 ResourceMap::iterator it = resources_.find(resource_id); 1642 ResourceMap::iterator it = resources_.find(resource_id);
1917 DCHECK(it != resources_.end()); 1643 DCHECK(it != resources_.end());
1918 Resource* resource = &it->second; 1644 Resource* resource = &it->second;
1919 DCHECK(resource->lock_for_read_count); 1645 DCHECK(resource->lock_for_read_count);
1920 DCHECK(!resource->locked_for_write || resource->set_pixels_completion_forced); 1646 DCHECK(!resource->locked_for_write || resource->set_pixels_completion_forced);
1921 1647
1922 ScopedSetActiveTexture scoped_active_tex(gl, unit); 1648 ScopedSetActiveTexture scoped_active_tex(gl, unit);
1923 GLenum target = resource->target; 1649 GLenum target = resource->target;
(...skipping 10 matching lines...) Expand all
1934 return target; 1660 return target;
1935 } 1661 }
1936 1662
1937 void ResourceProvider::BeginSetPixels(ResourceId id) { 1663 void ResourceProvider::BeginSetPixels(ResourceId id) {
1938 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), 1664 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"),
1939 "ResourceProvider::BeginSetPixels"); 1665 "ResourceProvider::BeginSetPixels");
1940 1666
1941 Resource* resource = GetResource(id); 1667 Resource* resource = GetResource(id);
1942 DCHECK(!resource->pending_set_pixels); 1668 DCHECK(!resource->pending_set_pixels);
1943 1669
1944 DCHECK(resource->pixel_raster_buffer.get());
1945 bool raster_bitmap_changed = resource->pixel_raster_buffer->UnmapBuffer();
1946 if (!raster_bitmap_changed)
1947 return;
1948
1949 LazyCreate(resource); 1670 LazyCreate(resource);
1950 DCHECK(resource->origin == Resource::Internal); 1671 DCHECK(resource->origin == Resource::Internal);
1951 DCHECK(resource->gl_id || resource->allocated); 1672 DCHECK(resource->gl_id || resource->allocated);
1952 DCHECK(ReadLockFenceHasPassed(resource)); 1673 DCHECK(ReadLockFenceHasPassed(resource));
1953 DCHECK(!resource->image_id); 1674 DCHECK(!resource->image_id);
1954 1675
1955 bool allocate = !resource->allocated; 1676 bool allocate = !resource->allocated;
1956 resource->allocated = true; 1677 resource->allocated = true;
1957 LockForWrite(id); 1678 LockForWrite(id);
1958 1679
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1996 resource->pending_set_pixels = true; 1717 resource->pending_set_pixels = true;
1997 resource->set_pixels_completion_forced = false; 1718 resource->set_pixels_completion_forced = false;
1998 } 1719 }
1999 1720
2000 void ResourceProvider::ForceSetPixelsToComplete(ResourceId id) { 1721 void ResourceProvider::ForceSetPixelsToComplete(ResourceId id) {
2001 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), 1722 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"),
2002 "ResourceProvider::ForceSetPixelsToComplete"); 1723 "ResourceProvider::ForceSetPixelsToComplete");
2003 1724
2004 Resource* resource = GetResource(id); 1725 Resource* resource = GetResource(id);
2005 1726
2006 if (!resource->pending_set_pixels)
2007 return;
2008
2009 DCHECK(resource->locked_for_write); 1727 DCHECK(resource->locked_for_write);
1728 DCHECK(resource->pending_set_pixels);
2010 DCHECK(!resource->set_pixels_completion_forced); 1729 DCHECK(!resource->set_pixels_completion_forced);
2011 1730
2012 if (resource->gl_id) { 1731 if (resource->gl_id) {
2013 GLES2Interface* gl = ContextGL(); 1732 GLES2Interface* gl = ContextGL();
2014 GLC(gl, gl->BindTexture(GL_TEXTURE_2D, resource->gl_id)); 1733 GLC(gl, gl->BindTexture(GL_TEXTURE_2D, resource->gl_id));
2015 GLC(gl, gl->WaitAsyncTexImage2DCHROMIUM(GL_TEXTURE_2D)); 1734 GLC(gl, gl->WaitAsyncTexImage2DCHROMIUM(GL_TEXTURE_2D));
2016 GLC(gl, gl->BindTexture(GL_TEXTURE_2D, 0)); 1735 GLC(gl, gl->BindTexture(GL_TEXTURE_2D, 0));
2017 } 1736 }
2018 1737
2019 resource->set_pixels_completion_forced = true; 1738 resource->set_pixels_completion_forced = true;
2020 } 1739 }
2021 1740
2022 bool ResourceProvider::DidSetPixelsComplete(ResourceId id) { 1741 bool ResourceProvider::DidSetPixelsComplete(ResourceId id) {
2023 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), 1742 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"),
2024 "ResourceProvider::DidSetPixelsComplete"); 1743 "ResourceProvider::DidSetPixelsComplete");
2025 1744
2026 Resource* resource = GetResource(id); 1745 Resource* resource = GetResource(id);
2027 1746
2028 // Upload can be avoided as a result of raster bitmap not being modified.
2029 // Assume the upload was completed in that case.
2030 if (!resource->pending_set_pixels)
2031 return true;
2032
2033 DCHECK(resource->locked_for_write); 1747 DCHECK(resource->locked_for_write);
1748 DCHECK(resource->pending_set_pixels);
2034 1749
2035 if (resource->gl_id) { 1750 if (resource->gl_id) {
2036 GLES2Interface* gl = ContextGL(); 1751 GLES2Interface* gl = ContextGL();
2037 DCHECK(gl); 1752 DCHECK(gl);
2038 DCHECK(resource->gl_upload_query_id); 1753 DCHECK(resource->gl_upload_query_id);
2039 GLuint complete = 1; 1754 GLuint complete = 1;
2040 gl->GetQueryObjectuivEXT( 1755 gl->GetQueryObjectuivEXT(
2041 resource->gl_upload_query_id, GL_QUERY_RESULT_AVAILABLE_EXT, &complete); 1756 resource->gl_upload_query_id, GL_QUERY_RESULT_AVAILABLE_EXT, &complete);
2042 if (!complete) 1757 if (!complete)
2043 return false; 1758 return false;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
2097 GL_FRAMEBUFFER_ATTACHMENT_ANGLE)); 1812 GL_FRAMEBUFFER_ATTACHMENT_ANGLE));
2098 } 1813 }
2099 } 1814 }
2100 1815
2101 void ResourceProvider::AllocateForTesting(ResourceId id) { 1816 void ResourceProvider::AllocateForTesting(ResourceId id) {
2102 LazyAllocate(GetResource(id)); 1817 LazyAllocate(GetResource(id));
2103 } 1818 }
2104 1819
2105 void ResourceProvider::LazyAllocate(Resource* resource) { 1820 void ResourceProvider::LazyAllocate(Resource* resource) {
2106 DCHECK(resource); 1821 DCHECK(resource);
1822 if (resource->allocated)
1823 return;
2107 LazyCreate(resource); 1824 LazyCreate(resource);
2108 1825 if (!resource->gl_id)
2109 DCHECK(resource->gl_id || resource->allocated);
2110 if (resource->allocated || !resource->gl_id)
2111 return; 1826 return;
2112 resource->allocated = true; 1827 resource->allocated = true;
2113 GLES2Interface* gl = ContextGL(); 1828 GLES2Interface* gl = ContextGL();
2114 gfx::Size& size = resource->size; 1829 gfx::Size& size = resource->size;
2115 DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D)); 1830 DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D));
2116 ResourceFormat format = resource->format; 1831 ResourceFormat format = resource->format;
2117 GLC(gl, gl->BindTexture(GL_TEXTURE_2D, resource->gl_id)); 1832 GLC(gl, gl->BindTexture(GL_TEXTURE_2D, resource->gl_id));
2118 if (use_texture_storage_ext_ && 1833 if (use_texture_storage_ext_ &&
2119 IsFormatSupportedForStorage(format, use_texture_format_bgra_) && 1834 IsFormatSupportedForStorage(format, use_texture_format_bgra_) &&
2120 (resource->hint & TextureHintImmutable)) { 1835 (resource->hint & TextureHintImmutable)) {
(...skipping 24 matching lines...) Expand all
2145 DCHECK(resource->image_id); 1860 DCHECK(resource->image_id);
2146 1861
2147 // Release image currently bound to texture. 1862 // Release image currently bound to texture.
2148 if (resource->bound_image_id) 1863 if (resource->bound_image_id)
2149 gl->ReleaseTexImage2DCHROMIUM(resource->target, resource->bound_image_id); 1864 gl->ReleaseTexImage2DCHROMIUM(resource->target, resource->bound_image_id);
2150 gl->BindTexImage2DCHROMIUM(resource->target, resource->image_id); 1865 gl->BindTexImage2DCHROMIUM(resource->target, resource->image_id);
2151 resource->bound_image_id = resource->image_id; 1866 resource->bound_image_id = resource->image_id;
2152 resource->dirty_image = false; 1867 resource->dirty_image = false;
2153 } 1868 }
2154 1869
2155 void ResourceProvider::EnableReadLockFences(ResourceProvider::ResourceId id) { 1870 void ResourceProvider::EnableReadLockFences(ResourceId id) {
2156 Resource* resource = GetResource(id); 1871 Resource* resource = GetResource(id);
2157 resource->read_lock_fences_enabled = true; 1872 resource->read_lock_fences_enabled = true;
2158 } 1873 }
2159 1874
2160 void ResourceProvider::AcquireImage(Resource* resource) { 1875 void ResourceProvider::AcquireImage(ResourceId id) {
1876 Resource* resource = GetResource(id);
2161 DCHECK(resource->origin == Resource::Internal); 1877 DCHECK(resource->origin == Resource::Internal);
2162 DCHECK_EQ(resource->exported_count, 0); 1878 DCHECK_EQ(resource->exported_count, 0);
2163 1879
2164 if (resource->type != GLTexture) 1880 if (resource->type != GLTexture)
2165 return; 1881 return;
2166 1882
2167 if (resource->image_id) 1883 if (resource->image_id)
2168 return; 1884 return;
2169 1885
2170 resource->allocated = true; 1886 resource->allocated = true;
2171 GLES2Interface* gl = ContextGL(); 1887 GLES2Interface* gl = ContextGL();
2172 DCHECK(gl); 1888 DCHECK(gl);
2173 resource->image_id = 1889 resource->image_id =
2174 gl->CreateImageCHROMIUM(resource->size.width(), 1890 gl->CreateImageCHROMIUM(resource->size.width(),
2175 resource->size.height(), 1891 resource->size.height(),
2176 TextureToStorageFormat(resource->format), 1892 TextureToStorageFormat(resource->format),
2177 GL_IMAGE_MAP_CHROMIUM); 1893 GL_IMAGE_MAP_CHROMIUM);
2178 DCHECK(resource->image_id); 1894 DCHECK(resource->image_id);
2179 } 1895 }
2180 1896
2181 void ResourceProvider::ReleaseImage(Resource* resource) { 1897 void ResourceProvider::ReleaseImage(ResourceId id) {
1898 Resource* resource = GetResource(id);
2182 DCHECK(resource->origin == Resource::Internal); 1899 DCHECK(resource->origin == Resource::Internal);
2183 DCHECK_EQ(resource->exported_count, 0); 1900 DCHECK_EQ(resource->exported_count, 0);
2184 1901
2185 if (!resource->image_id) 1902 if (!resource->image_id)
2186 return; 1903 return;
2187 1904
2188 GLES2Interface* gl = ContextGL(); 1905 GLES2Interface* gl = ContextGL();
2189 DCHECK(gl); 1906 DCHECK(gl);
2190 gl->DestroyImageCHROMIUM(resource->image_id); 1907 gl->DestroyImageCHROMIUM(resource->image_id);
2191 resource->image_id = 0; 1908 resource->image_id = 0;
2192 resource->bound_image_id = 0; 1909 resource->bound_image_id = 0;
2193 resource->dirty_image = false; 1910 resource->dirty_image = false;
2194 resource->allocated = false; 1911 resource->allocated = false;
2195 } 1912 }
2196 1913
2197 uint8_t* ResourceProvider::MapImage(const Resource* resource, int* stride) { 1914 uint8_t* ResourceProvider::MapImage(ResourceId id, int* stride) {
1915 Resource* resource = GetResource(id);
2198 DCHECK(ReadLockFenceHasPassed(resource)); 1916 DCHECK(ReadLockFenceHasPassed(resource));
2199 DCHECK(resource->origin == Resource::Internal); 1917 DCHECK(resource->origin == Resource::Internal);
2200 DCHECK_EQ(resource->exported_count, 0); 1918 DCHECK_EQ(resource->exported_count, 0);
1919 LockForWrite(id);
2201 1920
2202 if (resource->type == GLTexture) { 1921 if (resource->type == GLTexture) {
2203 DCHECK(resource->image_id); 1922 DCHECK(resource->image_id);
2204 GLES2Interface* gl = ContextGL(); 1923 GLES2Interface* gl = ContextGL();
2205 DCHECK(gl); 1924 DCHECK(gl);
2206 // MapImageCHROMIUM should be called prior to GetImageParameterivCHROMIUM. 1925 // MapImageCHROMIUM should be called prior to GetImageParameterivCHROMIUM.
2207 uint8_t* pixels = 1926 uint8_t* pixels =
2208 static_cast<uint8_t*>(gl->MapImageCHROMIUM(resource->image_id)); 1927 static_cast<uint8_t*>(gl->MapImageCHROMIUM(resource->image_id));
2209 gl->GetImageParameterivCHROMIUM( 1928 gl->GetImageParameterivCHROMIUM(
2210 resource->image_id, GL_IMAGE_ROWBYTES_CHROMIUM, stride); 1929 resource->image_id, GL_IMAGE_ROWBYTES_CHROMIUM, stride);
2211 return pixels; 1930 return pixels;
2212 } 1931 }
2213 DCHECK_EQ(Bitmap, resource->type); 1932 DCHECK_EQ(Bitmap, resource->type);
2214 *stride = 0; 1933 *stride = 0;
2215 return resource->pixels; 1934 return resource->pixels;
2216 } 1935 }
2217 1936
2218 void ResourceProvider::UnmapImage(const Resource* resource) { 1937 void ResourceProvider::UnmapImage(ResourceId id) {
1938 Resource* resource = GetResource(id);
2219 DCHECK(resource->origin == Resource::Internal); 1939 DCHECK(resource->origin == Resource::Internal);
2220 DCHECK_EQ(resource->exported_count, 0); 1940 DCHECK_EQ(resource->exported_count, 0);
1941 DCHECK(resource->locked_for_write);
2221 1942
2222 if (resource->image_id) { 1943 if (resource->image_id) {
2223 GLES2Interface* gl = ContextGL(); 1944 GLES2Interface* gl = ContextGL();
2224 DCHECK(gl); 1945 DCHECK(gl);
2225 gl->UnmapImageCHROMIUM(resource->image_id); 1946 gl->UnmapImageCHROMIUM(resource->image_id);
1947 resource->dirty_image = true;
2226 } 1948 }
1949
1950 UnlockForWrite(id);
1951 }
1952
1953 void ResourceProvider::AcquireSkSurface(ResourceId id) {
1954 Resource* resource = GetResource(id);
1955 DCHECK(resource->origin == Resource::Internal);
1956 DCHECK_EQ(resource->exported_count, 0);
1957
1958 if (resource->type != GLTexture)
1959 return;
1960
1961 if (resource->sk_surface)
1962 return;
1963
1964 class GrContext* gr_context = GrContext();
1965 // TODO(alokp): Implement TestContextProvider::GrContext().
1966 if (!gr_context)
1967 return;
1968
1969 LazyAllocate(resource);
1970
1971 GrBackendTextureDesc desc;
1972 desc.fFlags = kRenderTarget_GrBackendTextureFlag;
1973 desc.fWidth = resource->size.width();
1974 desc.fHeight = resource->size.height();
1975 desc.fConfig = ToGrPixelConfig(resource->format);
1976 desc.fOrigin = kTopLeft_GrSurfaceOrigin;
1977 desc.fTextureHandle = resource->gl_id;
1978 skia::RefPtr<GrTexture> gr_texture =
1979 skia::AdoptRef(gr_context->wrapBackendTexture(desc));
1980 SkSurface::TextRenderMode text_render_mode =
1981 use_distance_field_text_ ? SkSurface::kDistanceField_TextRenderMode
1982 : SkSurface::kStandard_TextRenderMode;
1983 resource->sk_surface = skia::AdoptRef(SkSurface::NewRenderTargetDirect(
1984 gr_texture->asRenderTarget(), text_render_mode));
1985 }
1986
1987 void ResourceProvider::ReleaseSkSurface(ResourceId id) {
1988 Resource* resource = GetResource(id);
1989 DCHECK(resource->origin == Resource::Internal);
1990 DCHECK_EQ(resource->exported_count, 0);
1991
1992 resource->sk_surface.clear();
1993 }
1994
1995 SkSurface* ResourceProvider::LockForWriteToSkSurface(ResourceId id) {
1996 Resource* resource = GetResource(id);
1997 DCHECK(resource->origin == Resource::Internal);
1998 DCHECK_EQ(resource->exported_count, 0);
1999
2000 LockForWrite(id);
2001 return resource->sk_surface.get();
2002 }
2003
2004 void ResourceProvider::UnlockForWriteToSkSurface(ResourceId id) {
2005 UnlockForWrite(id);
2227 } 2006 }
2228 2007
2229 void ResourceProvider::CopyResource(ResourceId source_id, ResourceId dest_id) { 2008 void ResourceProvider::CopyResource(ResourceId source_id, ResourceId dest_id) {
2230 TRACE_EVENT0("cc", "ResourceProvider::CopyResource"); 2009 TRACE_EVENT0("cc", "ResourceProvider::CopyResource");
2231 2010
2232 Resource* source_resource = GetResource(source_id); 2011 Resource* source_resource = GetResource(source_id);
2233 DCHECK(!source_resource->lock_for_read_count); 2012 DCHECK(!source_resource->lock_for_read_count);
2234 DCHECK(source_resource->origin == Resource::Internal); 2013 DCHECK(source_resource->origin == Resource::Internal);
2235 DCHECK_EQ(source_resource->exported_count, 0); 2014 DCHECK_EQ(source_resource->exported_count, 0);
2236 DCHECK(source_resource->allocated); 2015 DCHECK(source_resource->allocated);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
2307 ContextProvider* context_provider = output_surface_->context_provider(); 2086 ContextProvider* context_provider = output_surface_->context_provider();
2308 return context_provider ? context_provider->ContextGL() : NULL; 2087 return context_provider ? context_provider->ContextGL() : NULL;
2309 } 2088 }
2310 2089
2311 class GrContext* ResourceProvider::GrContext() const { 2090 class GrContext* ResourceProvider::GrContext() const {
2312 ContextProvider* context_provider = output_surface_->context_provider(); 2091 ContextProvider* context_provider = output_surface_->context_provider();
2313 return context_provider ? context_provider->GrContext() : NULL; 2092 return context_provider ? context_provider->GrContext() : NULL;
2314 } 2093 }
2315 2094
2316 } // namespace cc 2095 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698