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

Side by Side Diff: cc/tiles/tile_manager.cc

Issue 2003353003: cc: Ensure members needed on task completion get called on valid thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove_task_new_state_in_dtor
Patch Set: feedback Created 4 years, 7 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/tiles/tile_manager.h" 5 #include "cc/tiles/tile_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
11 #include <limits> 11 #include <limits>
12 #include <string> 12 #include <string>
13 13
14 #include "base/bind.h" 14 #include "base/bind.h"
15 #include "base/json/json_writer.h" 15 #include "base/json/json_writer.h"
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "base/memory/ptr_util.h" 18 #include "base/memory/ptr_util.h"
19 #include "base/metrics/histogram.h" 19 #include "base/metrics/histogram.h"
20 #include "base/numerics/safe_conversions.h" 20 #include "base/numerics/safe_conversions.h"
21 #include "base/threading/thread_checker.h"
21 #include "base/trace_event/trace_event_argument.h" 22 #include "base/trace_event/trace_event_argument.h"
22 #include "cc/base/histograms.h" 23 #include "cc/base/histograms.h"
23 #include "cc/debug/devtools_instrumentation.h" 24 #include "cc/debug/devtools_instrumentation.h"
24 #include "cc/debug/frame_viewer_instrumentation.h" 25 #include "cc/debug/frame_viewer_instrumentation.h"
25 #include "cc/debug/traced_value.h" 26 #include "cc/debug/traced_value.h"
26 #include "cc/layers/picture_layer_impl.h" 27 #include "cc/layers/picture_layer_impl.h"
27 #include "cc/raster/raster_buffer.h" 28 #include "cc/raster/raster_buffer.h"
28 #include "cc/raster/task_category.h" 29 #include "cc/raster/task_category.h"
29 #include "cc/tiles/tile.h" 30 #include "cc/tiles/tile.h"
30 #include "ui/gfx/geometry/rect_conversions.h" 31 #include "ui/gfx/geometry/rect_conversions.h"
31 32
32 namespace cc { 33 namespace cc {
33 namespace { 34 namespace {
34 35
35 // Flag to indicate whether we should try and detect that 36 // Flag to indicate whether we should try and detect that
36 // a tile is of solid color. 37 // a tile is of solid color.
37 const bool kUseColorEstimator = true; 38 const bool kUseColorEstimator = true;
38 39
39 DEFINE_SCOPED_UMA_HISTOGRAM_AREA_TIMER( 40 DEFINE_SCOPED_UMA_HISTOGRAM_AREA_TIMER(
40 ScopedRasterTaskTimer, 41 ScopedRasterTaskTimer,
41 "Compositing.%s.RasterTask.RasterUs", 42 "Compositing.%s.RasterTask.RasterUs",
42 "Compositing.%s.RasterTask.RasterPixelsPerMs"); 43 "Compositing.%s.RasterTask.RasterPixelsPerMs");
43 44
44 // TODO(prashant.n): Separate out members needed in RunOnWorkerThread() and
45 // OnTaskCompleted() in RasterTaskImpl. crbug.com/613812.
46 class RasterTaskImpl : public TileTask { 45 class RasterTaskImpl : public TileTask {
47 public: 46 public:
48 RasterTaskImpl(TileManager* tile_manager, 47 RasterTaskImpl(TileManager* tile_manager,
vmpstr 2016/05/26 19:37:45 Quite a few of these variables are coming from the
prashant.n 2016/05/26 22:02:18 I'll check and modify.
48 Tile* tile,
49 Resource* resource, 49 Resource* resource,
50 scoped_refptr<RasterSource> raster_source, 50 scoped_refptr<RasterSource> raster_source,
51 const gfx::Rect& content_rect, 51 const gfx::Rect& content_rect,
52 const gfx::Rect& invalid_content_rect, 52 const gfx::Rect& invalid_content_rect,
53 float contents_scale, 53 float contents_scale,
54 const RasterSource::PlaybackSettings& playback_settings, 54 const RasterSource::PlaybackSettings& playback_settings,
55 TileResolution tile_resolution, 55 TileResolution tile_resolution,
56 int layer_id, 56 int layer_id,
57 uint64_t source_prepare_tiles_id, 57 uint64_t source_prepare_tiles_id,
58 Tile* tile, 58 void* tile_ptr,
59 uint64_t new_content_id, 59 uint64_t new_content_id,
60 uint64_t previous_content_id, 60 uint64_t previous_content_id,
61 uint64_t resource_content_id, 61 uint64_t resource_content_id,
62 int source_frame_number, 62 int source_frame_number,
63 std::unique_ptr<RasterBuffer> raster_buffer, 63 std::unique_ptr<RasterBuffer> raster_buffer,
64 TileTask::Vector* dependencies, 64 TileTask::Vector* dependencies,
65 bool supports_concurrent_execution) 65 bool supports_concurrent_execution)
66 : TileTask(supports_concurrent_execution, dependencies), 66 : TileTask(supports_concurrent_execution, dependencies),
67 tile_manager_(tile_manager), 67 tile_manager_(tile_manager),
68 tile_(tile),
68 resource_(resource), 69 resource_(resource),
69 raster_source_(std::move(raster_source)), 70 raster_source_(std::move(raster_source)),
70 content_rect_(content_rect), 71 content_rect_(content_rect),
71 invalid_content_rect_(invalid_content_rect), 72 invalid_content_rect_(invalid_content_rect),
72 contents_scale_(contents_scale), 73 contents_scale_(contents_scale),
73 playback_settings_(playback_settings), 74 playback_settings_(playback_settings),
74 tile_resolution_(tile_resolution), 75 tile_resolution_(tile_resolution),
75 layer_id_(layer_id), 76 layer_id_(layer_id),
76 source_prepare_tiles_id_(source_prepare_tiles_id), 77 source_prepare_tiles_id_(source_prepare_tiles_id),
77 tile_(tile), 78 tile_ptr_(tile_ptr),
78 new_content_id_(new_content_id), 79 new_content_id_(new_content_id),
79 previous_content_id_(previous_content_id), 80 previous_content_id_(previous_content_id),
80 resource_content_id_(resource_content_id), 81 resource_content_id_(resource_content_id),
81 source_frame_number_(source_frame_number), 82 source_frame_number_(source_frame_number),
82 raster_buffer_(std::move(raster_buffer)) {} 83 raster_buffer_(std::move(raster_buffer)) {}
83 84
84 // Overridden from Task: 85 // Overridden from Task:
85 void RunOnWorkerThread() override { 86 void RunOnWorkerThread() override {
86 TRACE_EVENT1("cc", "RasterizerTaskImpl::RunOnWorkerThread", 87 TRACE_EVENT1("cc", "RasterizerTaskImpl::RunOnWorkerThread",
87 "source_prepare_tiles_id", source_prepare_tiles_id_); 88 "source_prepare_tiles_id", source_prepare_tiles_id_);
88 89
89 DCHECK(raster_source_.get()); 90 DCHECK(raster_source_.get());
90 DCHECK(raster_buffer_); 91 DCHECK(raster_buffer_);
91 92
92 frame_viewer_instrumentation::ScopedRasterTask raster_task( 93 frame_viewer_instrumentation::ScopedRasterTask raster_task(
93 tile_, tile_resolution_, source_frame_number_, layer_id_); 94 tile_ptr_, tile_resolution_, source_frame_number_, layer_id_);
94 ScopedRasterTaskTimer timer; 95 ScopedRasterTaskTimer timer;
95 timer.SetArea(content_rect_.size().GetArea()); 96 timer.SetArea(content_rect_.size().GetArea());
96 97
97 DCHECK(raster_source_); 98 DCHECK(raster_source_);
98 99
99 raster_buffer_->Playback(raster_source_.get(), content_rect_, 100 raster_buffer_->Playback(raster_source_.get(), content_rect_,
100 invalid_content_rect_, new_content_id_, 101 invalid_content_rect_, new_content_id_,
101 contents_scale_, playback_settings_); 102 contents_scale_, playback_settings_);
102 } 103 }
103 104
104 // Overridden from TileTask: 105 // Overridden from TileTask:
105 void OnTaskCompleted() override { 106 void OnTaskCompleted() override {
107 DCHECK(origin_thread_checker_.CalledOnValidThread());
108
106 tile_manager_->OnRasterTaskCompleted(std::move(raster_buffer_), tile_, 109 tile_manager_->OnRasterTaskCompleted(std::move(raster_buffer_), tile_,
107 resource_, state().IsCanceled()); 110 resource_, state().IsCanceled());
108 } 111 }
109 112
110 protected: 113 protected:
111 ~RasterTaskImpl() override { DCHECK(!raster_buffer_); } 114 ~RasterTaskImpl() override { DCHECK(!raster_buffer_); }
112 115
113 private: 116 private:
117 base::ThreadChecker origin_thread_checker_;
vmpstr 2016/05/26 19:37:45 How does this "bind" to the correct thread? Since
prashant.n 2016/05/26 22:02:18 In ctor it will be called once. https://code.googl
118
119 // The following members are needed for processing completion of this task on
120 // origin thread. These are not thread-safe and should be accessed only in
121 // origin thread. Ensure their access by checking CalledOnValidThread().
114 TileManager* tile_manager_; 122 TileManager* tile_manager_;
vmpstr 2016/05/26 19:37:45 I was thinking more explicit struct OriginThreadD
prashant.n 2016/05/26 22:02:18 How about the way I implemented in patchset 2. Cal
prashant.n 2016/05/27 05:05:08 I'll keep with comments now. Later if needed we ca
123 Tile* tile_;
115 Resource* resource_; 124 Resource* resource_;
125
126 // The following members should be used for running the task.
116 scoped_refptr<RasterSource> raster_source_; 127 scoped_refptr<RasterSource> raster_source_;
117 gfx::Rect content_rect_; 128 gfx::Rect content_rect_;
118 gfx::Rect invalid_content_rect_; 129 gfx::Rect invalid_content_rect_;
119 float contents_scale_; 130 float contents_scale_;
120 RasterSource::PlaybackSettings playback_settings_; 131 RasterSource::PlaybackSettings playback_settings_;
121 TileResolution tile_resolution_; 132 TileResolution tile_resolution_;
122 int layer_id_; 133 int layer_id_;
123 uint64_t source_prepare_tiles_id_; 134 uint64_t source_prepare_tiles_id_;
124 Tile* tile_; 135 void* tile_ptr_;
reveman 2016/05/26 19:21:58 Can you change this to a Tile::Id? https://code.go
vmpstr 2016/05/26 19:37:45 I think the tracing thing uses the address of the
reveman 2016/05/26 19:45:04 Ok, we should probably change that to use the Tile
prashant.n 2016/05/26 22:02:18 Same comment like vmpstr@. For time being I'll ren
125 uint64_t new_content_id_; 136 uint64_t new_content_id_;
126 uint64_t previous_content_id_; 137 uint64_t previous_content_id_;
127 uint64_t resource_content_id_; 138 uint64_t resource_content_id_;
128 int source_frame_number_; 139 int source_frame_number_;
129 std::unique_ptr<RasterBuffer> raster_buffer_; 140 std::unique_ptr<RasterBuffer> raster_buffer_;
130 141
131 DISALLOW_COPY_AND_ASSIGN(RasterTaskImpl); 142 DISALLOW_COPY_AND_ASSIGN(RasterTaskImpl);
132 }; 143 };
133 144
134 TaskCategory TaskCategoryForTileTask(TileTask* task, 145 TaskCategory TaskCategoryForTileTask(TileTask* task,
(...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after
934 ++it; 945 ++it;
935 else 946 else
936 it = images.erase(it); 947 it = images.erase(it);
937 } 948 }
938 949
939 bool supports_concurrent_execution = !use_gpu_rasterization_; 950 bool supports_concurrent_execution = !use_gpu_rasterization_;
940 std::unique_ptr<RasterBuffer> raster_buffer = 951 std::unique_ptr<RasterBuffer> raster_buffer =
941 tile_task_manager_->GetRasterBufferProvider()->AcquireBufferForRaster( 952 tile_task_manager_->GetRasterBufferProvider()->AcquireBufferForRaster(
942 resource, resource_content_id, tile->invalidated_id()); 953 resource, resource_content_id, tile->invalidated_id());
943 return make_scoped_refptr(new RasterTaskImpl( 954 return make_scoped_refptr(new RasterTaskImpl(
944 this, resource, prioritized_tile.raster_source(), tile->content_rect(), 955 this, tile, resource, prioritized_tile.raster_source(),
945 tile->invalidated_content_rect(), tile->contents_scale(), 956 tile->content_rect(), tile->invalidated_content_rect(),
946 playback_settings, prioritized_tile.priority().resolution, 957 tile->contents_scale(), playback_settings,
947 tile->layer_id(), prepare_tiles_count_, tile, tile->id(), 958 prioritized_tile.priority().resolution, tile->layer_id(),
959 prepare_tiles_count_, static_cast<void*>(tile), tile->id(),
948 tile->invalidated_id(), resource_content_id, tile->source_frame_number(), 960 tile->invalidated_id(), resource_content_id, tile->source_frame_number(),
949 std::move(raster_buffer), &decode_tasks, supports_concurrent_execution)); 961 std::move(raster_buffer), &decode_tasks, supports_concurrent_execution));
950 } 962 }
951 963
952 void TileManager::OnRasterTaskCompleted( 964 void TileManager::OnRasterTaskCompleted(
953 std::unique_ptr<RasterBuffer> raster_buffer, 965 std::unique_ptr<RasterBuffer> raster_buffer,
954 Tile* tile, 966 Tile* tile,
955 Resource* resource, 967 Resource* resource,
956 bool was_canceled) { 968 bool was_canceled) {
957 DCHECK(tile); 969 DCHECK(tile);
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
1281 void TileManager::Signals::reset() { 1293 void TileManager::Signals::reset() {
1282 ready_to_activate = false; 1294 ready_to_activate = false;
1283 did_notify_ready_to_activate = false; 1295 did_notify_ready_to_activate = false;
1284 ready_to_draw = false; 1296 ready_to_draw = false;
1285 did_notify_ready_to_draw = false; 1297 did_notify_ready_to_draw = false;
1286 all_tile_tasks_completed = false; 1298 all_tile_tasks_completed = false;
1287 did_notify_all_tile_tasks_completed = false; 1299 did_notify_all_tile_tasks_completed = false;
1288 } 1300 }
1289 1301
1290 } // namespace cc 1302 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698