| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "cc/raster/gpu_tile_task_worker_pool.h" | |
| 6 | |
| 7 #include <stdint.h> | |
| 8 | |
| 9 #include <algorithm> | |
| 10 | |
| 11 #include "base/macros.h" | |
| 12 #include "base/memory/ptr_util.h" | |
| 13 #include "base/trace_event/trace_event.h" | |
| 14 #include "cc/playback/raster_source.h" | |
| 15 #include "cc/raster/gpu_rasterizer.h" | |
| 16 #include "cc/raster/scoped_gpu_raster.h" | |
| 17 #include "cc/resources/resource.h" | |
| 18 #include "gpu/command_buffer/client/gles2_interface.h" | |
| 19 #include "third_party/skia/include/core/SkMultiPictureDraw.h" | |
| 20 #include "third_party/skia/include/core/SkPictureRecorder.h" | |
| 21 #include "third_party/skia/include/core/SkSurface.h" | |
| 22 #include "third_party/skia/include/gpu/GrContext.h" | |
| 23 | |
| 24 namespace cc { | |
| 25 namespace { | |
| 26 | |
| 27 class RasterBufferImpl : public RasterBuffer { | |
| 28 public: | |
| 29 RasterBufferImpl(GpuRasterizer* rasterizer, | |
| 30 const Resource* resource, | |
| 31 uint64_t resource_content_id, | |
| 32 uint64_t previous_content_id) | |
| 33 : rasterizer_(rasterizer), | |
| 34 lock_(rasterizer->resource_provider(), resource->id()), | |
| 35 resource_has_previous_content_( | |
| 36 resource_content_id && resource_content_id == previous_content_id) { | |
| 37 } | |
| 38 | |
| 39 // Overridden from RasterBuffer: | |
| 40 void Playback( | |
| 41 const RasterSource* raster_source, | |
| 42 const gfx::Rect& raster_full_rect, | |
| 43 const gfx::Rect& raster_dirty_rect, | |
| 44 uint64_t new_content_id, | |
| 45 float scale, | |
| 46 const RasterSource::PlaybackSettings& playback_settings) override { | |
| 47 TRACE_EVENT0("cc", "RasterBufferImpl::Playback"); | |
| 48 // GPU raster doesn't do low res tiles, so should always include images. | |
| 49 DCHECK(!playback_settings.skip_images); | |
| 50 ContextProvider* context_provider = rasterizer_->resource_provider() | |
| 51 ->output_surface() | |
| 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 } | |
| 80 | |
| 81 private: | |
| 82 GpuRasterizer* rasterizer_; | |
| 83 ResourceProvider::ScopedWriteLockGr lock_; | |
| 84 bool resource_has_previous_content_; | |
| 85 | |
| 86 DISALLOW_COPY_AND_ASSIGN(RasterBufferImpl); | |
| 87 }; | |
| 88 | |
| 89 } // namespace | |
| 90 | |
| 91 // static | |
| 92 std::unique_ptr<TileTaskWorkerPool> GpuTileTaskWorkerPool::Create( | |
| 93 base::SequencedTaskRunner* task_runner, | |
| 94 TaskGraphRunner* task_graph_runner, | |
| 95 ContextProvider* context_provider, | |
| 96 ResourceProvider* resource_provider, | |
| 97 bool use_distance_field_text, | |
| 98 int gpu_rasterization_msaa_sample_count) { | |
| 99 return base::WrapUnique<TileTaskWorkerPool>(new GpuTileTaskWorkerPool( | |
| 100 task_runner, task_graph_runner, context_provider, resource_provider, | |
| 101 use_distance_field_text, gpu_rasterization_msaa_sample_count)); | |
| 102 } | |
| 103 | |
| 104 GpuTileTaskWorkerPool::GpuTileTaskWorkerPool( | |
| 105 base::SequencedTaskRunner* task_runner, | |
| 106 TaskGraphRunner* task_graph_runner, | |
| 107 ContextProvider* context_provider, | |
| 108 ResourceProvider* resource_provider, | |
| 109 bool use_distance_field_text, | |
| 110 int gpu_rasterization_msaa_sample_count) | |
| 111 : task_runner_(task_runner), | |
| 112 task_graph_runner_(task_graph_runner), | |
| 113 namespace_token_(task_graph_runner_->GetNamespaceToken()), | |
| 114 rasterizer_(new GpuRasterizer(context_provider, | |
| 115 resource_provider, | |
| 116 use_distance_field_text, | |
| 117 gpu_rasterization_msaa_sample_count)) {} | |
| 118 | |
| 119 GpuTileTaskWorkerPool::~GpuTileTaskWorkerPool() { | |
| 120 DCHECK_EQ(0u, completed_tasks_.size()); | |
| 121 } | |
| 122 | |
| 123 void GpuTileTaskWorkerPool::Shutdown() { | |
| 124 TRACE_EVENT0("cc", "GpuTileTaskWorkerPool::Shutdown"); | |
| 125 | |
| 126 TaskGraph empty; | |
| 127 task_graph_runner_->ScheduleTasks(namespace_token_, &empty); | |
| 128 task_graph_runner_->WaitForTasksToFinishRunning(namespace_token_); | |
| 129 } | |
| 130 | |
| 131 void GpuTileTaskWorkerPool::ScheduleTasks(TaskGraph* graph) { | |
| 132 TRACE_EVENT0("cc", "GpuTileTaskWorkerPool::ScheduleTasks"); | |
| 133 | |
| 134 ScheduleTasksOnOriginThread(this, graph); | |
| 135 | |
| 136 // Barrier to sync any new resources to the worker context. | |
| 137 rasterizer_->resource_provider() | |
| 138 ->output_surface() | |
| 139 ->context_provider() | |
| 140 ->ContextGL() | |
| 141 ->OrderingBarrierCHROMIUM(); | |
| 142 | |
| 143 task_graph_runner_->ScheduleTasks(namespace_token_, graph); | |
| 144 } | |
| 145 | |
| 146 void GpuTileTaskWorkerPool::CheckForCompletedTasks() { | |
| 147 TRACE_EVENT0("cc", "GpuTileTaskWorkerPool::CheckForCompletedTasks"); | |
| 148 | |
| 149 task_graph_runner_->CollectCompletedTasks(namespace_token_, | |
| 150 &completed_tasks_); | |
| 151 CompleteTasks(completed_tasks_); | |
| 152 completed_tasks_.clear(); | |
| 153 } | |
| 154 | |
| 155 ResourceFormat GpuTileTaskWorkerPool::GetResourceFormat( | |
| 156 bool must_support_alpha) const { | |
| 157 return rasterizer_->resource_provider()->best_render_buffer_format(); | |
| 158 } | |
| 159 | |
| 160 bool GpuTileTaskWorkerPool::GetResourceRequiresSwizzle( | |
| 161 bool must_support_alpha) const { | |
| 162 // This doesn't require a swizzle because we rasterize to the correct format. | |
| 163 return false; | |
| 164 } | |
| 165 | |
| 166 RasterBufferProvider* GpuTileTaskWorkerPool::AsRasterBufferProvider() { | |
| 167 return this; | |
| 168 } | |
| 169 | |
| 170 void GpuTileTaskWorkerPool::CompleteTasks(const Task::Vector& tasks) { | |
| 171 for (auto& task : tasks) { | |
| 172 TileTask* tile_task = static_cast<TileTask*>(task.get()); | |
| 173 | |
| 174 tile_task->WillComplete(); | |
| 175 tile_task->CompleteOnOriginThread(this); | |
| 176 tile_task->DidComplete(); | |
| 177 } | |
| 178 completed_tasks_.clear(); | |
| 179 } | |
| 180 | |
| 181 std::unique_ptr<RasterBuffer> GpuTileTaskWorkerPool::AcquireBufferForRaster( | |
| 182 const Resource* resource, | |
| 183 uint64_t resource_content_id, | |
| 184 uint64_t previous_content_id) { | |
| 185 return std::unique_ptr<RasterBuffer>(new RasterBufferImpl( | |
| 186 rasterizer_.get(), resource, resource_content_id, previous_content_id)); | |
| 187 } | |
| 188 | |
| 189 void GpuTileTaskWorkerPool::ReleaseBufferForRaster( | |
| 190 std::unique_ptr<RasterBuffer> buffer) { | |
| 191 // Nothing to do here. RasterBufferImpl destructor cleans up after itself. | |
| 192 } | |
| 193 | |
| 194 } // namespace cc | |
| OLD | NEW |