| OLD | NEW | 
|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/raster/zero_copy_raster_buffer_provider.h" | 5 #include "cc/raster/zero_copy_raster_buffer_provider.h" | 
| 6 | 6 | 
| 7 #include <stdint.h> | 7 #include <stdint.h> | 
| 8 | 8 | 
| 9 #include <algorithm> | 9 #include <algorithm> | 
| 10 | 10 | 
| 11 #include "base/macros.h" | 11 #include "base/macros.h" | 
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" | 
| 13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" | 
| 14 #include "base/trace_event/trace_event.h" | 14 #include "base/trace_event/trace_event.h" | 
| 15 #include "base/trace_event/trace_event_argument.h" | 15 #include "base/trace_event/trace_event_argument.h" | 
| 16 #include "cc/resources/layer_tree_resource_provider.h" | 16 #include "cc/resources/layer_tree_resource_provider.h" | 
| 17 #include "cc/resources/resource.h" | 17 #include "cc/resources/resource.h" | 
| 18 #include "components/viz/common/resources/platform_color.h" | 18 #include "components/viz/common/resources/platform_color.h" | 
| 19 #include "ui/gfx/buffer_format_util.h" | 19 #include "ui/gfx/buffer_format_util.h" | 
| 20 #include "ui/gfx/gpu_memory_buffer.h" | 20 #include "ui/gfx/gpu_memory_buffer.h" | 
| 21 | 21 | 
| 22 namespace cc { | 22 namespace cc { | 
| 23 namespace { | 23 namespace { | 
| 24 | 24 | 
| 25 class RasterBufferImpl : public RasterBuffer { | 25 class ZeroCopyRasterBufferImpl : public RasterBuffer { | 
| 26  public: | 26  public: | 
| 27   RasterBufferImpl(LayerTreeResourceProvider* resource_provider, | 27   ZeroCopyRasterBufferImpl(LayerTreeResourceProvider* resource_provider, | 
| 28                    const Resource* resource) | 28                            const Resource* resource) | 
| 29       : lock_(resource_provider, resource->id()), resource_(resource) {} | 29       : lock_(resource_provider, resource->id()), resource_(resource) {} | 
| 30 | 30 | 
| 31   // Overridden from RasterBuffer: | 31   // Overridden from RasterBuffer: | 
| 32   void Playback( | 32   void Playback( | 
| 33       const RasterSource* raster_source, | 33       const RasterSource* raster_source, | 
| 34       const gfx::Rect& raster_full_rect, | 34       const gfx::Rect& raster_full_rect, | 
| 35       const gfx::Rect& raster_dirty_rect, | 35       const gfx::Rect& raster_dirty_rect, | 
| 36       uint64_t new_content_id, | 36       uint64_t new_content_id, | 
| 37       const gfx::AxisTransform2d& transform, | 37       const gfx::AxisTransform2d& transform, | 
| 38       const RasterSource::PlaybackSettings& playback_settings) override { | 38       const RasterSource::PlaybackSettings& playback_settings) override { | 
| (...skipping 14 matching lines...) Expand all  Loading... | 
| 53         buffer->memory(0), resource_->format(), resource_->size(), | 53         buffer->memory(0), resource_->format(), resource_->size(), | 
| 54         buffer->stride(0), raster_source, raster_full_rect, raster_full_rect, | 54         buffer->stride(0), raster_source, raster_full_rect, raster_full_rect, | 
| 55         transform, lock_.color_space_for_raster(), playback_settings); | 55         transform, lock_.color_space_for_raster(), playback_settings); | 
| 56     buffer->Unmap(); | 56     buffer->Unmap(); | 
| 57   } | 57   } | 
| 58 | 58 | 
| 59  private: | 59  private: | 
| 60   LayerTreeResourceProvider::ScopedWriteLockGpuMemoryBuffer lock_; | 60   LayerTreeResourceProvider::ScopedWriteLockGpuMemoryBuffer lock_; | 
| 61   const Resource* resource_; | 61   const Resource* resource_; | 
| 62 | 62 | 
| 63   DISALLOW_COPY_AND_ASSIGN(RasterBufferImpl); | 63   DISALLOW_COPY_AND_ASSIGN(ZeroCopyRasterBufferImpl); | 
| 64 }; | 64 }; | 
| 65 | 65 | 
| 66 }  // namespace | 66 }  // namespace | 
| 67 | 67 | 
| 68 // static | 68 // static | 
| 69 std::unique_ptr<RasterBufferProvider> ZeroCopyRasterBufferProvider::Create( | 69 std::unique_ptr<RasterBufferProvider> ZeroCopyRasterBufferProvider::Create( | 
| 70     LayerTreeResourceProvider* resource_provider, | 70     LayerTreeResourceProvider* resource_provider, | 
| 71     viz::ResourceFormat preferred_tile_format) { | 71     viz::ResourceFormat preferred_tile_format) { | 
| 72   return base::WrapUnique<RasterBufferProvider>( | 72   return base::WrapUnique<RasterBufferProvider>( | 
| 73       new ZeroCopyRasterBufferProvider(resource_provider, | 73       new ZeroCopyRasterBufferProvider(resource_provider, | 
| 74                                        preferred_tile_format)); | 74                                        preferred_tile_format)); | 
| 75 } | 75 } | 
| 76 | 76 | 
| 77 ZeroCopyRasterBufferProvider::ZeroCopyRasterBufferProvider( | 77 ZeroCopyRasterBufferProvider::ZeroCopyRasterBufferProvider( | 
| 78     LayerTreeResourceProvider* resource_provider, | 78     LayerTreeResourceProvider* resource_provider, | 
| 79     viz::ResourceFormat preferred_tile_format) | 79     viz::ResourceFormat preferred_tile_format) | 
| 80     : resource_provider_(resource_provider), | 80     : resource_provider_(resource_provider), | 
| 81       preferred_tile_format_(preferred_tile_format) {} | 81       preferred_tile_format_(preferred_tile_format) {} | 
| 82 | 82 | 
| 83 ZeroCopyRasterBufferProvider::~ZeroCopyRasterBufferProvider() {} | 83 ZeroCopyRasterBufferProvider::~ZeroCopyRasterBufferProvider() {} | 
| 84 | 84 | 
| 85 std::unique_ptr<RasterBuffer> | 85 std::unique_ptr<RasterBuffer> | 
| 86 ZeroCopyRasterBufferProvider::AcquireBufferForRaster( | 86 ZeroCopyRasterBufferProvider::AcquireBufferForRaster( | 
| 87     const Resource* resource, | 87     const Resource* resource, | 
| 88     uint64_t resource_content_id, | 88     uint64_t resource_content_id, | 
| 89     uint64_t previous_content_id) { | 89     uint64_t previous_content_id) { | 
| 90   return base::WrapUnique<RasterBuffer>( | 90   return base::WrapUnique<RasterBuffer>( | 
| 91       new RasterBufferImpl(resource_provider_, resource)); | 91       new ZeroCopyRasterBufferImpl(resource_provider_, resource)); | 
| 92 } | 92 } | 
| 93 | 93 | 
| 94 void ZeroCopyRasterBufferProvider::ReleaseBufferForRaster( | 94 void ZeroCopyRasterBufferProvider::ReleaseBufferForRaster( | 
| 95     std::unique_ptr<RasterBuffer> buffer) { | 95     std::unique_ptr<RasterBuffer> buffer) { | 
| 96   // Nothing to do here. RasterBufferImpl destructor cleans up after itself. | 96   // Nothing to do here. ZeroCopyRasterBufferImpl destructor cleans up | 
|  | 97   // after itself. | 
| 97 } | 98 } | 
| 98 | 99 | 
| 99 void ZeroCopyRasterBufferProvider::OrderingBarrier() { | 100 void ZeroCopyRasterBufferProvider::OrderingBarrier() { | 
| 100   // No need to sync resources as this provider does not use GL context. | 101   // No need to sync resources as this provider does not use GL context. | 
| 101 } | 102 } | 
| 102 | 103 | 
| 103 void ZeroCopyRasterBufferProvider::Flush() {} | 104 void ZeroCopyRasterBufferProvider::Flush() {} | 
| 104 | 105 | 
| 105 viz::ResourceFormat ZeroCopyRasterBufferProvider::GetResourceFormat( | 106 viz::ResourceFormat ZeroCopyRasterBufferProvider::GetResourceFormat( | 
| 106     bool must_support_alpha) const { | 107     bool must_support_alpha) const { | 
| (...skipping 26 matching lines...) Expand all  Loading... | 
| 133     const ResourceProvider::ResourceIdArray& resource_ids, | 134     const ResourceProvider::ResourceIdArray& resource_ids, | 
| 134     const base::Closure& callback, | 135     const base::Closure& callback, | 
| 135     uint64_t pending_callback_id) const { | 136     uint64_t pending_callback_id) const { | 
| 136   // Zero-copy resources are immediately ready to draw. | 137   // Zero-copy resources are immediately ready to draw. | 
| 137   return 0; | 138   return 0; | 
| 138 } | 139 } | 
| 139 | 140 | 
| 140 void ZeroCopyRasterBufferProvider::Shutdown() {} | 141 void ZeroCopyRasterBufferProvider::Shutdown() {} | 
| 141 | 142 | 
| 142 }  // namespace cc | 143 }  // namespace cc | 
| OLD | NEW | 
|---|