OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/gpu_raster_buffer_provider.h" | 5 #include "cc/raster/gpu_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/trace_event/trace_event.h" | 13 #include "base/trace_event/trace_event.h" |
14 #include "cc/playback/raster_source.h" | 14 #include "cc/playback/raster_source.h" |
15 #include "cc/raster/gpu_rasterizer.h" | 15 #include "cc/raster/gpu_rasterizer.h" |
16 #include "cc/raster/scoped_gpu_raster.h" | 16 #include "cc/raster/scoped_gpu_raster.h" |
17 #include "cc/resources/resource.h" | 17 #include "cc/resources/resource.h" |
18 #include "gpu/command_buffer/client/gles2_interface.h" | 18 #include "gpu/command_buffer/client/gles2_interface.h" |
19 #include "third_party/skia/include/core/SkMultiPictureDraw.h" | 19 #include "third_party/skia/include/core/SkMultiPictureDraw.h" |
20 #include "third_party/skia/include/core/SkPictureRecorder.h" | 20 #include "third_party/skia/include/core/SkPictureRecorder.h" |
21 #include "third_party/skia/include/core/SkSurface.h" | 21 #include "third_party/skia/include/core/SkSurface.h" |
22 #include "third_party/skia/include/gpu/GrContext.h" | 22 #include "third_party/skia/include/gpu/GrContext.h" |
23 | 23 |
24 namespace cc { | 24 namespace cc { |
25 namespace { | 25 namespace { |
26 | 26 |
27 class RasterBufferImpl : public RasterBuffer { | 27 class RasterBufferImpl : public RasterBuffer { |
28 public: | 28 public: |
29 RasterBufferImpl(GpuRasterizer* rasterizer, | 29 RasterBufferImpl(GpuRasterBufferProvider* client, |
30 const Resource* resource, | 30 std::unique_ptr<ResourceProvider::ScopedWriteLockGr> lock, |
31 uint64_t resource_content_id, | 31 bool resource_has_previous_content) |
32 uint64_t previous_content_id) | 32 : client_(client), |
33 : rasterizer_(rasterizer), | 33 lock_(std::move(lock)), |
34 lock_(rasterizer->resource_provider(), resource->id()), | 34 resource_has_previous_content_(resource_has_previous_content) {} |
35 resource_has_previous_content_( | |
36 resource_content_id && resource_content_id == previous_content_id) { | |
37 } | |
38 | 35 |
39 // Overridden from RasterBuffer: | 36 // Overridden from RasterBuffer: |
40 void Playback( | 37 void Playback( |
41 const RasterSource* raster_source, | 38 const RasterSource* raster_source, |
42 const gfx::Rect& raster_full_rect, | 39 const gfx::Rect& raster_full_rect, |
43 const gfx::Rect& raster_dirty_rect, | 40 const gfx::Rect& raster_dirty_rect, |
44 uint64_t new_content_id, | 41 uint64_t new_content_id, |
45 float scale, | 42 float scale, |
46 const RasterSource::PlaybackSettings& playback_settings) override { | 43 const RasterSource::PlaybackSettings& playback_settings) override { |
47 TRACE_EVENT0("cc", "RasterBufferImpl::Playback"); | 44 TRACE_EVENT0("cc", "RasterBufferImpl::Playback"); |
48 // GPU raster doesn't do low res tiles, so should always include images. | 45 client_->PlaybackOnWorkerThread(lock_.get(), resource_has_previous_content_, |
49 DCHECK(!playback_settings.skip_images); | 46 raster_source, raster_full_rect, |
50 ContextProvider* context_provider = rasterizer_->resource_provider() | 47 raster_dirty_rect, new_content_id, scale, |
51 ->output_surface() | 48 playback_settings); |
52 ->worker_context_provider(); | |
53 DCHECK(context_provider); | |
54 | |
55 ContextProvider::ScopedContextLock scoped_context(context_provider); | |
56 | |
57 gfx::Rect playback_rect = raster_full_rect; | |
58 if (resource_has_previous_content_) { | |
59 playback_rect.Intersect(raster_dirty_rect); | |
60 } | |
61 DCHECK(!playback_rect.IsEmpty()) | |
62 << "Why are we rastering a tile that's not dirty?"; | |
63 | |
64 // TODO(danakj): Implement partial raster with raster_dirty_rect. | |
65 // Rasterize source into resource. | |
66 rasterizer_->RasterizeSource(&lock_, raster_source, raster_full_rect, | |
67 playback_rect, scale, playback_settings); | |
68 | |
69 gpu::gles2::GLES2Interface* gl = scoped_context.ContextGL(); | |
70 const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM(); | |
71 | |
72 // Barrier to sync worker context output to cc context. | |
73 gl->OrderingBarrierCHROMIUM(); | |
74 | |
75 // Generate sync token after the barrier for cross context synchronization. | |
76 gpu::SyncToken sync_token; | |
77 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, sync_token.GetData()); | |
78 lock_.UpdateResourceSyncToken(sync_token); | |
79 } | 49 } |
80 | 50 |
81 private: | 51 private: |
82 GpuRasterizer* rasterizer_; | 52 GpuRasterBufferProvider* client_; |
83 ResourceProvider::ScopedWriteLockGr lock_; | 53 std::unique_ptr<ResourceProvider::ScopedWriteLockGr> lock_; |
84 bool resource_has_previous_content_; | 54 bool resource_has_previous_content_; |
85 | 55 |
86 DISALLOW_COPY_AND_ASSIGN(RasterBufferImpl); | 56 DISALLOW_COPY_AND_ASSIGN(RasterBufferImpl); |
87 }; | 57 }; |
88 | 58 |
89 } // namespace | 59 } // namespace |
90 | 60 |
91 // static | 61 // static |
92 std::unique_ptr<RasterBufferProvider> GpuRasterBufferProvider::Create( | 62 std::unique_ptr<RasterBufferProvider> GpuRasterBufferProvider::Create( |
93 ContextProvider* context_provider, | 63 ContextProvider* context_provider, |
94 ResourceProvider* resource_provider, | 64 ResourceProvider* resource_provider, |
95 bool use_distance_field_text, | 65 bool use_distance_field_text, |
96 int gpu_rasterization_msaa_sample_count) { | 66 int gpu_rasterization_msaa_sample_count, |
| 67 bool async_worker_context_enabled) { |
97 return base::WrapUnique<RasterBufferProvider>(new GpuRasterBufferProvider( | 68 return base::WrapUnique<RasterBufferProvider>(new GpuRasterBufferProvider( |
98 context_provider, resource_provider, use_distance_field_text, | 69 context_provider, resource_provider, use_distance_field_text, |
99 gpu_rasterization_msaa_sample_count)); | 70 gpu_rasterization_msaa_sample_count, async_worker_context_enabled)); |
100 } | 71 } |
101 | 72 |
102 GpuRasterBufferProvider::GpuRasterBufferProvider( | 73 GpuRasterBufferProvider::GpuRasterBufferProvider( |
103 ContextProvider* context_provider, | 74 ContextProvider* context_provider, |
104 ResourceProvider* resource_provider, | 75 ResourceProvider* resource_provider, |
105 bool use_distance_field_text, | 76 bool use_distance_field_text, |
106 int gpu_rasterization_msaa_sample_count) | 77 int gpu_rasterization_msaa_sample_count, |
| 78 bool async_worker_context_enabled) |
107 : rasterizer_(new GpuRasterizer(context_provider, | 79 : rasterizer_(new GpuRasterizer(context_provider, |
108 resource_provider, | 80 resource_provider, |
109 use_distance_field_text, | 81 use_distance_field_text, |
110 gpu_rasterization_msaa_sample_count)) {} | 82 gpu_rasterization_msaa_sample_count)), |
| 83 async_worker_context_enabled_(async_worker_context_enabled) {} |
111 | 84 |
112 GpuRasterBufferProvider::~GpuRasterBufferProvider() {} | 85 GpuRasterBufferProvider::~GpuRasterBufferProvider() {} |
113 | 86 |
114 std::unique_ptr<RasterBuffer> GpuRasterBufferProvider::AcquireBufferForRaster( | 87 std::unique_ptr<RasterBuffer> GpuRasterBufferProvider::AcquireBufferForRaster( |
115 const Resource* resource, | 88 const Resource* resource, |
116 uint64_t resource_content_id, | 89 uint64_t resource_content_id, |
117 uint64_t previous_content_id) { | 90 uint64_t previous_content_id) { |
| 91 bool resource_has_previous_content = |
| 92 resource_content_id && resource_content_id == previous_content_id; |
118 return std::unique_ptr<RasterBuffer>(new RasterBufferImpl( | 93 return std::unique_ptr<RasterBuffer>(new RasterBufferImpl( |
119 rasterizer_.get(), resource, resource_content_id, previous_content_id)); | 94 this, base::WrapUnique(new ResourceProvider::ScopedWriteLockGr( |
| 95 rasterizer_->resource_provider(), resource->id(), |
| 96 async_worker_context_enabled_)), |
| 97 resource_has_previous_content)); |
120 } | 98 } |
121 | 99 |
122 void GpuRasterBufferProvider::ReleaseBufferForRaster( | 100 void GpuRasterBufferProvider::ReleaseBufferForRaster( |
123 std::unique_ptr<RasterBuffer> buffer) { | 101 std::unique_ptr<RasterBuffer> buffer) { |
124 // Nothing to do here. RasterBufferImpl destructor cleans up after itself. | 102 // Nothing to do here. RasterBufferImpl destructor cleans up after itself. |
125 } | 103 } |
126 | 104 |
127 void GpuRasterBufferProvider::OrderingBarrier() { | 105 void GpuRasterBufferProvider::OrderingBarrier() { |
128 TRACE_EVENT0("cc", "GpuRasterBufferProvider::OrderingBarrier"); | 106 TRACE_EVENT0("cc", "GpuRasterBufferProvider::OrderingBarrier"); |
129 | 107 |
130 rasterizer_->resource_provider() | 108 gpu::gles2::GLES2Interface* gl = rasterizer_->resource_provider() |
131 ->output_surface() | 109 ->output_surface() |
132 ->context_provider() | 110 ->context_provider() |
133 ->ContextGL() | 111 ->ContextGL(); |
134 ->OrderingBarrierCHROMIUM(); | 112 |
| 113 // Synchronize with compositor. |
| 114 GLuint64 fence = gl->InsertFenceSyncCHROMIUM(); |
| 115 gl->OrderingBarrierCHROMIUM(); |
| 116 gl->GenUnverifiedSyncTokenCHROMIUM(fence, sync_token_.GetData()); |
135 } | 117 } |
136 | 118 |
137 ResourceFormat GpuRasterBufferProvider::GetResourceFormat( | 119 ResourceFormat GpuRasterBufferProvider::GetResourceFormat( |
138 bool must_support_alpha) const { | 120 bool must_support_alpha) const { |
139 return rasterizer_->resource_provider()->best_render_buffer_format(); | 121 return rasterizer_->resource_provider()->best_render_buffer_format(); |
140 } | 122 } |
141 | 123 |
142 bool GpuRasterBufferProvider::GetResourceRequiresSwizzle( | 124 bool GpuRasterBufferProvider::GetResourceRequiresSwizzle( |
143 bool must_support_alpha) const { | 125 bool must_support_alpha) const { |
144 // This doesn't require a swizzle because we rasterize to the correct format. | 126 // This doesn't require a swizzle because we rasterize to the correct format. |
145 return false; | 127 return false; |
146 } | 128 } |
147 | 129 |
148 void GpuRasterBufferProvider::Shutdown() {} | 130 void GpuRasterBufferProvider::Shutdown() {} |
149 | 131 |
| 132 void GpuRasterBufferProvider::PlaybackOnWorkerThread( |
| 133 ResourceProvider::ScopedWriteLockGr* lock, |
| 134 bool resource_has_previous_content, |
| 135 const RasterSource* raster_source, |
| 136 const gfx::Rect& raster_full_rect, |
| 137 const gfx::Rect& raster_dirty_rect, |
| 138 uint64_t new_content_id, |
| 139 float scale, |
| 140 const RasterSource::PlaybackSettings& playback_settings) { |
| 141 // GPU raster doesn't do low res tiles, so should always include images. |
| 142 DCHECK(!playback_settings.skip_images); |
| 143 ContextProvider* context_provider = rasterizer_->resource_provider() |
| 144 ->output_surface() |
| 145 ->worker_context_provider(); |
| 146 DCHECK(context_provider); |
| 147 |
| 148 ContextProvider::ScopedContextLock scoped_context(context_provider); |
| 149 gpu::gles2::GLES2Interface* gl = scoped_context.ContextGL(); |
| 150 |
| 151 gfx::Rect playback_rect = raster_full_rect; |
| 152 if (resource_has_previous_content) { |
| 153 playback_rect.Intersect(raster_dirty_rect); |
| 154 } |
| 155 DCHECK(!playback_rect.IsEmpty()) |
| 156 << "Why are we rastering a tile that's not dirty?"; |
| 157 |
| 158 // Synchronize with compositor if worker context is async. |
| 159 DCHECK(sync_token_.HasData()); |
| 160 gl->WaitSyncTokenCHROMIUM(sync_token_.GetData()); |
| 161 |
| 162 // TODO(danakj): Implement partial raster with raster_dirty_rect. |
| 163 // Rasterize source into resource. |
| 164 rasterizer_->RasterizeSource(lock, raster_source, raster_full_rect, |
| 165 playback_rect, scale, playback_settings); |
| 166 |
| 167 const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM(); |
| 168 |
| 169 // Barrier to sync worker context output to cc context. |
| 170 gl->OrderingBarrierCHROMIUM(); |
| 171 |
| 172 // Generate sync token after the barrier for cross context synchronization. |
| 173 gpu::SyncToken sync_token; |
| 174 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, sync_token.GetData()); |
| 175 lock->UpdateResourceSyncToken(sync_token); |
| 176 } |
| 177 |
150 } // namespace cc | 178 } // namespace cc |
OLD | NEW |