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

Side by Side Diff: content/browser/compositor/delegated_frame_layer_host.cc

Issue 417943004: Use Surfaces to hold delegated renderer contents. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
OLDNEW
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 "content/browser/compositor/delegated_frame_host.h" 5 #include "content/browser/compositor/delegated_frame_layer_host.h"
6 6
7 #include "base/callback_helpers.h" 7 #include "base/callback_helpers.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "cc/output/compositor_frame.h" 9 #include "cc/output/compositor_frame.h"
10 #include "cc/output/compositor_frame_ack.h" 10 #include "cc/output/compositor_frame_ack.h"
11 #include "cc/output/copy_output_request.h" 11 #include "cc/output/copy_output_request.h"
12 #include "cc/resources/single_release_callback.h" 12 #include "cc/resources/single_release_callback.h"
13 #include "cc/resources/texture_mailbox.h" 13 #include "cc/resources/texture_mailbox.h"
14 #include "cc/surfaces/surface_factory.h"
14 #include "content/browser/compositor/resize_lock.h" 15 #include "content/browser/compositor/resize_lock.h"
15 #include "content/common/gpu/client/gl_helper.h" 16 #include "content/common/gpu/client/gl_helper.h"
16 #include "content/public/browser/render_widget_host_view_frame_subscriber.h" 17 #include "content/public/browser/render_widget_host_view_frame_subscriber.h"
17 #include "content/public/common/content_switches.h" 18 #include "content/public/common/content_switches.h"
18 #include "media/base/video_frame.h" 19 #include "media/base/video_frame.h"
19 #include "media/base/video_util.h" 20 #include "media/base/video_util.h"
20 #include "skia/ext/image_operations.h" 21 #include "skia/ext/image_operations.h"
21 22
22 namespace content { 23 namespace content {
23 24
24 //////////////////////////////////////////////////////////////////////////////// 25 ////////////////////////////////////////////////////////////////////////////////
25 // DelegatedFrameHostClient 26 // DelegatedFrameLayerHost
26 27
27 bool DelegatedFrameHostClient::ShouldCreateResizeLock() { 28 DelegatedFrameLayerHost::DelegatedFrameLayerHost(
28 // On Windows and Linux, holding pointer moves will not help throttling 29 DelegatedFrameHostClient* client)
29 // resizes.
30 // TODO(piman): on Windows we need to block (nested message loop?) the
31 // WM_SIZE event. On Linux we need to throttle at the WM level using
32 // _NET_WM_SYNC_REQUEST.
33 // TODO(ccameron): Mac browser window resizing is incompletely implemented.
34 #if !defined(OS_CHROMEOS)
35 return false;
36 #else
37 return GetDelegatedFrameHost()->ShouldCreateResizeLock();
38 #endif
39 }
40
41 void DelegatedFrameHostClient::RequestCopyOfOutput(
42 scoped_ptr<cc::CopyOutputRequest> request) {
43 GetDelegatedFrameHost()->RequestCopyOfOutput(request.Pass());
44 }
45
46 ////////////////////////////////////////////////////////////////////////////////
47 // DelegatedFrameHost
48
49 DelegatedFrameHost::DelegatedFrameHost(DelegatedFrameHostClient* client)
50 : client_(client), 30 : client_(client),
51 last_output_surface_id_(0), 31 last_output_surface_id_(0),
52 pending_delegated_ack_count_(0), 32 pending_delegated_ack_count_(0),
53 skipped_frames_(false), 33 skipped_frames_(false),
54 can_lock_compositor_(YES_CAN_LOCK), 34 can_lock_compositor_(YES_CAN_LOCK),
55 delegated_frame_evictor_(new DelegatedFrameEvictor(this)) { 35 delegated_frame_evictor_(new DelegatedFrameEvictor(this)) {
56 ImageTransportFactory::GetInstance()->AddObserver(this); 36 ImageTransportFactory::GetInstance()->AddObserver(this);
57 } 37 }
58 38
59 void DelegatedFrameHost::WasShown() { 39 void DelegatedFrameLayerHost::WasShown() {
60 delegated_frame_evictor_->SetVisible(true); 40 delegated_frame_evictor_->SetVisible(true);
61 41
62 if (!released_front_lock_.get()) { 42 if (!released_front_lock_.get()) {
63 ui::Compositor* compositor = client_->GetCompositor(); 43 ui::Compositor* compositor = client_->GetCompositor();
64 if (compositor) 44 if (compositor)
65 released_front_lock_ = compositor->GetCompositorLock(); 45 released_front_lock_ = compositor->GetCompositorLock();
66 } 46 }
67 } 47 }
68 48
69 void DelegatedFrameHost::WasHidden() { 49 void DelegatedFrameLayerHost::WasHidden() {
70 delegated_frame_evictor_->SetVisible(false); 50 delegated_frame_evictor_->SetVisible(false);
71 released_front_lock_ = NULL; 51 released_front_lock_ = NULL;
72 } 52 }
73 53
74 void DelegatedFrameHost::MaybeCreateResizeLock() { 54 void DelegatedFrameLayerHost::MaybeCreateResizeLock() {
75 if (!client_->ShouldCreateResizeLock()) 55 if (!client_->ShouldCreateResizeLock())
76 return; 56 return;
77 DCHECK(client_->GetCompositor()); 57 DCHECK(client_->GetCompositor());
78 58
79 // Listen to changes in the compositor lock state. 59 // Listen to changes in the compositor lock state.
80 ui::Compositor* compositor = client_->GetCompositor(); 60 ui::Compositor* compositor = client_->GetCompositor();
81 if (!compositor->HasObserver(this)) 61 if (!compositor->HasObserver(this))
82 compositor->AddObserver(this); 62 compositor->AddObserver(this);
83 63
84 bool defer_compositor_lock = 64 bool defer_compositor_lock =
85 can_lock_compositor_ == NO_PENDING_RENDERER_FRAME || 65 can_lock_compositor_ == NO_PENDING_RENDERER_FRAME ||
86 can_lock_compositor_ == NO_PENDING_COMMIT; 66 can_lock_compositor_ == NO_PENDING_COMMIT;
87 67
88 if (can_lock_compositor_ == YES_CAN_LOCK) 68 if (can_lock_compositor_ == YES_CAN_LOCK)
89 can_lock_compositor_ = YES_DID_LOCK; 69 can_lock_compositor_ = YES_DID_LOCK;
90 70
91 resize_lock_ = client_->CreateResizeLock(defer_compositor_lock); 71 resize_lock_ = client_->CreateResizeLock(defer_compositor_lock);
92 } 72 }
93 73
94 bool DelegatedFrameHost::ShouldCreateResizeLock() { 74 bool DelegatedFrameLayerHost::ShouldCreateResizeLock() {
95 RenderWidgetHostImpl* host = client_->GetHost(); 75 RenderWidgetHostImpl* host = client_->GetHost();
96 76
97 if (resize_lock_) 77 if (resize_lock_)
98 return false; 78 return false;
99 79
100 if (host->should_auto_resize()) 80 if (host->should_auto_resize())
101 return false; 81 return false;
102 82
103 gfx::Size desired_size = client_->DesiredFrameSize(); 83 gfx::Size desired_size = client_->DesiredFrameSize();
104 if (desired_size == current_frame_size_in_dip_ || desired_size.IsEmpty()) 84 if (desired_size == current_frame_size_in_dip_ || desired_size.IsEmpty())
105 return false; 85 return false;
106 86
107 ui::Compositor* compositor = client_->GetCompositor(); 87 ui::Compositor* compositor = client_->GetCompositor();
108 if (!compositor) 88 if (!compositor)
109 return false; 89 return false;
110 90
111 return true; 91 return true;
112 } 92 }
113 93
114 void DelegatedFrameHost::RequestCopyOfOutput( 94 void DelegatedFrameLayerHost::RequestCopyOfOutput(
115 scoped_ptr<cc::CopyOutputRequest> request) { 95 scoped_ptr<cc::CopyOutputRequest> request) {
116 client_->GetLayer()->RequestCopyOfOutput(request.Pass()); 96 client_->GetLayer()->RequestCopyOfOutput(request.Pass());
117 } 97 }
118 98
119 void DelegatedFrameHost::CopyFromCompositingSurface( 99 void DelegatedFrameLayerHost::CopyFromCompositingSurface(
120 const gfx::Rect& src_subrect, 100 const gfx::Rect& src_subrect,
121 const gfx::Size& dst_size, 101 const gfx::Size& dst_size,
122 const base::Callback<void(bool, const SkBitmap&)>& callback, 102 const base::Callback<void(bool, const SkBitmap&)>& callback,
123 const SkColorType color_type) { 103 const SkColorType color_type) {
124 // Only ARGB888 and RGB565 supported as of now. 104 // Only ARGB888 and RGB565 supported as of now.
125 bool format_support = ((color_type == kRGB_565_SkColorType) || 105 bool format_support = ((color_type == kRGB_565_SkColorType) ||
126 (color_type == kN32_SkColorType)); 106 (color_type == kN32_SkColorType));
127 DCHECK(format_support); 107 DCHECK(format_support);
128 if (!CanCopyToBitmap()) { 108 if (!CanCopyToBitmap()) {
129 callback.Run(false, SkBitmap()); 109 callback.Run(false, SkBitmap());
130 return; 110 return;
131 } 111 }
132 112
133 const gfx::Size& dst_size_in_pixel = 113 const gfx::Size& dst_size_in_pixel =
134 client_->ConvertViewSizeToPixel(dst_size); 114 client_->ConvertViewSizeToPixel(dst_size);
135 scoped_ptr<cc::CopyOutputRequest> request = 115 scoped_ptr<cc::CopyOutputRequest> request =
136 cc::CopyOutputRequest::CreateRequest(base::Bind( 116 cc::CopyOutputRequest::CreateRequest(base::Bind(
137 &DelegatedFrameHost::CopyFromCompositingSurfaceHasResult, 117 &DelegatedFrameLayerHost::CopyFromCompositingSurfaceHasResult,
138 dst_size_in_pixel, 118 dst_size_in_pixel,
139 color_type, 119 color_type,
140 callback)); 120 callback));
141 gfx::Rect src_subrect_in_pixel = 121 gfx::Rect src_subrect_in_pixel =
142 ConvertRectToPixel(client_->CurrentDeviceScaleFactor(), src_subrect); 122 ConvertRectToPixel(client_->CurrentDeviceScaleFactor(), src_subrect);
143 request->set_area(src_subrect_in_pixel); 123 request->set_area(src_subrect_in_pixel);
144 client_->RequestCopyOfOutput(request.Pass()); 124 client_->RequestCopyOfOutput(request.Pass());
145 } 125 }
146 126
147 void DelegatedFrameHost::CopyFromCompositingSurfaceToVideoFrame( 127 void DelegatedFrameLayerHost::CopyFromCompositingSurfaceToVideoFrame(
148 const gfx::Rect& src_subrect, 128 const gfx::Rect& src_subrect,
149 const scoped_refptr<media::VideoFrame>& target, 129 const scoped_refptr<media::VideoFrame>& target,
150 const base::Callback<void(bool)>& callback) { 130 const base::Callback<void(bool)>& callback) {
151 if (!CanCopyToVideoFrame()) { 131 if (!CanCopyToVideoFrame()) {
152 callback.Run(false); 132 callback.Run(false);
153 return; 133 return;
154 } 134 }
155 135
156 // Try get a texture to reuse. 136 // Try get a texture to reuse.
157 scoped_refptr<OwnedMailbox> subscriber_texture; 137 scoped_refptr<OwnedMailbox> subscriber_texture;
158 if (frame_subscriber_) { 138 if (frame_subscriber_) {
159 if (!idle_frame_subscriber_textures_.empty()) { 139 if (!idle_frame_subscriber_textures_.empty()) {
160 subscriber_texture = idle_frame_subscriber_textures_.back(); 140 subscriber_texture = idle_frame_subscriber_textures_.back();
161 idle_frame_subscriber_textures_.pop_back(); 141 idle_frame_subscriber_textures_.pop_back();
162 } else if (GLHelper* helper = 142 } else if (GLHelper* helper =
163 ImageTransportFactory::GetInstance()->GetGLHelper()) { 143 ImageTransportFactory::GetInstance()->GetGLHelper()) {
164 subscriber_texture = new OwnedMailbox(helper); 144 subscriber_texture = new OwnedMailbox(helper);
165 } 145 }
166 } 146 }
167 147
168 scoped_ptr<cc::CopyOutputRequest> request = 148 scoped_ptr<cc::CopyOutputRequest> request =
169 cc::CopyOutputRequest::CreateRequest(base::Bind( 149 cc::CopyOutputRequest::CreateRequest(base::Bind(
170 &DelegatedFrameHost:: 150 &DelegatedFrameLayerHost::CopyFromCompositingSurfaceHasResultForVideo,
171 CopyFromCompositingSurfaceHasResultForVideo,
172 AsWeakPtr(), // For caching the ReadbackYUVInterface on this class. 151 AsWeakPtr(), // For caching the ReadbackYUVInterface on this class.
173 subscriber_texture, 152 subscriber_texture,
174 target, 153 target,
175 callback)); 154 callback));
176 gfx::Rect src_subrect_in_pixel = 155 gfx::Rect src_subrect_in_pixel =
177 ConvertRectToPixel(client_->CurrentDeviceScaleFactor(), src_subrect); 156 ConvertRectToPixel(client_->CurrentDeviceScaleFactor(), src_subrect);
178 request->set_area(src_subrect_in_pixel); 157 request->set_area(src_subrect_in_pixel);
179 if (subscriber_texture.get()) { 158 if (subscriber_texture.get()) {
180 request->SetTextureMailbox( 159 request->SetTextureMailbox(
181 cc::TextureMailbox(subscriber_texture->mailbox(), 160 cc::TextureMailbox(subscriber_texture->mailbox(),
182 subscriber_texture->target(), 161 subscriber_texture->target(),
183 subscriber_texture->sync_point())); 162 subscriber_texture->sync_point()));
184 } 163 }
185 client_->RequestCopyOfOutput(request.Pass()); 164 client_->RequestCopyOfOutput(request.Pass());
186 } 165 }
187 166
188 bool DelegatedFrameHost::CanCopyToBitmap() const { 167 bool DelegatedFrameLayerHost::CanCopyToBitmap() const {
189 return client_->GetCompositor() && 168 return client_->GetCompositor() &&
190 client_->GetLayer()->has_external_content(); 169 client_->GetLayer()->has_external_content();
191 } 170 }
192 171
193 bool DelegatedFrameHost::CanCopyToVideoFrame() const { 172 bool DelegatedFrameLayerHost::CanCopyToVideoFrame() const {
194 return client_->GetCompositor() && 173 return client_->GetCompositor() &&
195 client_->GetLayer()->has_external_content(); 174 client_->GetLayer()->has_external_content();
196 } 175 }
197 176
198 bool DelegatedFrameHost::CanSubscribeFrame() const { 177 bool DelegatedFrameLayerHost::CanSubscribeFrame() const {
199 return true; 178 return true;
200 } 179 }
201 180
202 void DelegatedFrameHost::BeginFrameSubscription( 181 void DelegatedFrameLayerHost::BeginFrameSubscription(
203 scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber) { 182 scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber) {
204 frame_subscriber_ = subscriber.Pass(); 183 frame_subscriber_ = subscriber.Pass();
205 } 184 }
206 185
207 void DelegatedFrameHost::EndFrameSubscription() { 186 void DelegatedFrameLayerHost::EndFrameSubscription() {
208 idle_frame_subscriber_textures_.clear(); 187 idle_frame_subscriber_textures_.clear();
209 frame_subscriber_.reset(); 188 frame_subscriber_.reset();
210 } 189 }
211 190
212 bool DelegatedFrameHost::ShouldSkipFrame(gfx::Size size_in_dip) const { 191 bool DelegatedFrameLayerHost::HasFrameSubscriber() const {
192 return frame_subscriber_;
193 }
194
195 bool DelegatedFrameLayerHost::ShouldSkipFrame(gfx::Size size_in_dip) const {
213 // Should skip a frame only when another frame from the renderer is guaranteed 196 // Should skip a frame only when another frame from the renderer is guaranteed
214 // to replace it. Otherwise may cause hangs when the renderer is waiting for 197 // to replace it. Otherwise may cause hangs when the renderer is waiting for
215 // the completion of latency infos (such as when taking a Snapshot.) 198 // the completion of latency infos (such as when taking a Snapshot.)
216 if (can_lock_compositor_ == NO_PENDING_RENDERER_FRAME || 199 if (can_lock_compositor_ == NO_PENDING_RENDERER_FRAME ||
217 can_lock_compositor_ == NO_PENDING_COMMIT || 200 can_lock_compositor_ == NO_PENDING_COMMIT || !resize_lock_.get())
218 !resize_lock_.get())
219 return false; 201 return false;
220 202
221 return size_in_dip != resize_lock_->expected_size(); 203 return size_in_dip != resize_lock_->expected_size();
222 } 204 }
223 205
224 void DelegatedFrameHost::WasResized() { 206 void DelegatedFrameLayerHost::WasResized() {
225 MaybeCreateResizeLock(); 207 MaybeCreateResizeLock();
226 } 208 }
227 209
228 gfx::Size DelegatedFrameHost::GetRequestedRendererSize() const { 210 gfx::Size DelegatedFrameLayerHost::GetRequestedRendererSize() const {
229 if (resize_lock_) 211 if (resize_lock_)
230 return resize_lock_->expected_size(); 212 return resize_lock_->expected_size();
231 else 213 else
232 return client_->DesiredFrameSize(); 214 return client_->DesiredFrameSize();
233 } 215 }
234 216
235 void DelegatedFrameHost::CheckResizeLock() { 217 void DelegatedFrameLayerHost::CheckResizeLock() {
236 if (!resize_lock_ || 218 if (!resize_lock_ ||
237 resize_lock_->expected_size() != current_frame_size_in_dip_) 219 resize_lock_->expected_size() != current_frame_size_in_dip_)
238 return; 220 return;
239 221
240 // Since we got the size we were looking for, unlock the compositor. But delay 222 // Since we got the size we were looking for, unlock the compositor. But delay
241 // the release of the lock until we've kicked a frame with the new texture, to 223 // the release of the lock until we've kicked a frame with the new texture, to
242 // avoid resizing the UI before we have a chance to draw a "good" frame. 224 // avoid resizing the UI before we have a chance to draw a "good" frame.
243 resize_lock_->UnlockCompositor(); 225 resize_lock_->UnlockCompositor();
244 ui::Compositor* compositor = client_->GetCompositor(); 226 ui::Compositor* compositor = client_->GetCompositor();
245 if (compositor) { 227 if (compositor) {
246 if (!compositor->HasObserver(this)) 228 if (!compositor->HasObserver(this))
247 compositor->AddObserver(this); 229 compositor->AddObserver(this);
248 } 230 }
249 } 231 }
250 232
251 void DelegatedFrameHost::DidReceiveFrameFromRenderer() { 233 void DelegatedFrameLayerHost::DidReceiveFrameFromRenderer() {
252 if (frame_subscriber() && CanCopyToVideoFrame()) { 234 if (frame_subscriber() && CanCopyToVideoFrame()) {
253 const base::TimeTicks present_time = base::TimeTicks::Now(); 235 const base::TimeTicks present_time = base::TimeTicks::Now();
254 scoped_refptr<media::VideoFrame> frame; 236 scoped_refptr<media::VideoFrame> frame;
255 RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback callback; 237 RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback callback;
256 if (frame_subscriber()->ShouldCaptureFrame(present_time, 238 if (frame_subscriber()->ShouldCaptureFrame(
257 &frame, &callback)) { 239 present_time, &frame, &callback)) {
258 CopyFromCompositingSurfaceToVideoFrame( 240 CopyFromCompositingSurfaceToVideoFrame(
259 gfx::Rect(current_frame_size_in_dip_), 241 gfx::Rect(current_frame_size_in_dip_),
260 frame, 242 frame,
261 base::Bind(callback, present_time)); 243 base::Bind(callback, present_time));
262 } 244 }
263 } 245 }
264 } 246 }
265 247
266 void DelegatedFrameHost::SwapDelegatedFrame( 248 void DelegatedFrameLayerHost::SwapDelegatedFrame(
267 uint32 output_surface_id, 249 uint32 output_surface_id,
268 scoped_ptr<cc::DelegatedFrameData> frame_data, 250 scoped_ptr<cc::DelegatedFrameData> frame_data,
269 float frame_device_scale_factor, 251 float frame_device_scale_factor,
270 const std::vector<ui::LatencyInfo>& latency_info) { 252 const std::vector<ui::LatencyInfo>& latency_info) {
271 RenderWidgetHostImpl* host = client_->GetHost(); 253 RenderWidgetHostImpl* host = client_->GetHost();
272 DCHECK(!frame_data->render_pass_list.empty()); 254 DCHECK(!frame_data->render_pass_list.empty());
273 255
274 cc::RenderPass* root_pass = frame_data->render_pass_list.back(); 256 cc::RenderPass* root_pass = frame_data->render_pass_list.back();
275 257
276 gfx::Size frame_size = root_pass->output_rect.size(); 258 gfx::Size frame_size = root_pass->output_rect.size();
277 gfx::Size frame_size_in_dip = 259 gfx::Size frame_size_in_dip =
278 ConvertSizeToDIP(frame_device_scale_factor, frame_size); 260 ConvertSizeToDIP(frame_device_scale_factor, frame_size);
279 261
280 gfx::Rect damage_rect = gfx::ToEnclosingRect(root_pass->damage_rect); 262 gfx::Rect damage_rect = gfx::ToEnclosingRect(root_pass->damage_rect);
281 damage_rect.Intersect(gfx::Rect(frame_size)); 263 damage_rect.Intersect(gfx::Rect(frame_size));
282 gfx::Rect damage_rect_in_dip = 264 gfx::Rect damage_rect_in_dip =
283 ConvertRectToDIP(frame_device_scale_factor, damage_rect); 265 ConvertRectToDIP(frame_device_scale_factor, damage_rect);
284 266
285 if (ShouldSkipFrame(frame_size_in_dip)) { 267 if (ShouldSkipFrame(frame_size_in_dip)) {
286 cc::CompositorFrameAck ack; 268 cc::CompositorFrameAck ack;
287 cc::TransferableResource::ReturnResources(frame_data->resource_list, 269 cc::TransferableResource::ReturnResources(frame_data->resource_list,
288 &ack.resources); 270 &ack.resources);
289 271
290 skipped_latency_info_list_.insert(skipped_latency_info_list_.end(), 272 skipped_latency_info_list_.insert(skipped_latency_info_list_.end(),
291 latency_info.begin(), latency_info.end()); 273 latency_info.begin(),
274 latency_info.end());
292 275
293 RenderWidgetHostImpl::SendSwapCompositorFrameAck( 276 RenderWidgetHostImpl::SendSwapCompositorFrameAck(
294 host->GetRoutingID(), output_surface_id, 277 host->GetRoutingID(),
295 host->GetProcess()->GetID(), ack); 278 output_surface_id,
279 host->GetProcess()->GetID(),
280 ack);
296 skipped_frames_ = true; 281 skipped_frames_ = true;
297 return; 282 return;
298 } 283 }
299 284
300 if (skipped_frames_) { 285 if (skipped_frames_) {
301 skipped_frames_ = false; 286 skipped_frames_ = false;
302 damage_rect = gfx::Rect(frame_size); 287 damage_rect = gfx::Rect(frame_size);
303 damage_rect_in_dip = gfx::Rect(frame_size_in_dip); 288 damage_rect_in_dip = gfx::Rect(frame_size_in_dip);
304 289
305 // Give the same damage rect to the compositor. 290 // Give the same damage rect to the compositor.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 347
363 ui::Compositor* compositor = client_->GetCompositor(); 348 ui::Compositor* compositor = client_->GetCompositor();
364 if (!compositor) { 349 if (!compositor) {
365 SendDelegatedFrameAck(output_surface_id); 350 SendDelegatedFrameAck(output_surface_id);
366 } else { 351 } else {
367 std::vector<ui::LatencyInfo>::const_iterator it; 352 std::vector<ui::LatencyInfo>::const_iterator it;
368 for (it = latency_info.begin(); it != latency_info.end(); ++it) 353 for (it = latency_info.begin(); it != latency_info.end(); ++it)
369 compositor->SetLatencyInfo(*it); 354 compositor->SetLatencyInfo(*it);
370 // If we've previously skipped any latency infos add them. 355 // If we've previously skipped any latency infos add them.
371 for (it = skipped_latency_info_list_.begin(); 356 for (it = skipped_latency_info_list_.begin();
372 it != skipped_latency_info_list_.end(); 357 it != skipped_latency_info_list_.end();
373 ++it) 358 ++it)
374 compositor->SetLatencyInfo(*it); 359 compositor->SetLatencyInfo(*it);
375 skipped_latency_info_list_.clear(); 360 skipped_latency_info_list_.clear();
376 AddOnCommitCallbackAndDisableLocks( 361 AddOnCommitCallbackAndDisableLocks(
377 base::Bind(&DelegatedFrameHost::SendDelegatedFrameAck, 362 base::Bind(&DelegatedFrameLayerHost::SendDelegatedFrameAck,
378 AsWeakPtr(), 363 AsWeakPtr(),
379 output_surface_id)); 364 output_surface_id));
380 } 365 }
381 DidReceiveFrameFromRenderer(); 366 DidReceiveFrameFromRenderer();
382 if (frame_provider_.get()) 367 if (frame_provider_.get())
383 delegated_frame_evictor_->SwappedFrame(!host->is_hidden()); 368 delegated_frame_evictor_->SwappedFrame(!host->is_hidden());
384 // Note: the frame may have been evicted immediately. 369 // Note: the frame may have been evicted immediately.
385 } 370 }
386 371
387 void DelegatedFrameHost::SendDelegatedFrameAck(uint32 output_surface_id) { 372 void DelegatedFrameLayerHost::SetLayerOwner(ui::LayerOwner* layer_owner) {
373 layer_owner->set_layer_owner_delegate(this);
374 }
375
376 cc::DelegatedFrameProvider* DelegatedFrameLayerHost::FrameProviderForTesting()
377 const {
378 return frame_provider_.get();
379 }
380
381 void DelegatedFrameLayerHost::OnCompositingDidCommitForTesting(
382 ui::Compositor* compositor) {
383 OnCompositingDidCommit(compositor);
384 }
385
386 void DelegatedFrameLayerHost::SendDelegatedFrameAck(uint32 output_surface_id) {
388 RenderWidgetHostImpl* host = client_->GetHost(); 387 RenderWidgetHostImpl* host = client_->GetHost();
389 cc::CompositorFrameAck ack; 388 cc::CompositorFrameAck ack;
390 if (resource_collection_) 389 if (resource_collection_)
391 resource_collection_->TakeUnusedResourcesForChildCompositor(&ack.resources); 390 resource_collection_->TakeUnusedResourcesForChildCompositor(&ack.resources);
392 RenderWidgetHostImpl::SendSwapCompositorFrameAck(host->GetRoutingID(), 391 RenderWidgetHostImpl::SendSwapCompositorFrameAck(host->GetRoutingID(),
393 output_surface_id, 392 output_surface_id,
394 host->GetProcess()->GetID(), 393 host->GetProcess()->GetID(),
395 ack); 394 ack);
396 DCHECK_GT(pending_delegated_ack_count_, 0); 395 DCHECK_GT(pending_delegated_ack_count_, 0);
397 pending_delegated_ack_count_--; 396 pending_delegated_ack_count_--;
398 } 397 }
399 398
400 void DelegatedFrameHost::UnusedResourcesAreAvailable() { 399 void DelegatedFrameLayerHost::UnusedResourcesAreAvailable() {
401 if (pending_delegated_ack_count_) 400 if (pending_delegated_ack_count_)
402 return; 401 return;
403 402
404 SendReturnedDelegatedResources(last_output_surface_id_); 403 SendReturnedDelegatedResources(last_output_surface_id_);
405 } 404 }
406 405
407 void DelegatedFrameHost::SendReturnedDelegatedResources( 406 void DelegatedFrameLayerHost::SendReturnedDelegatedResources(
408 uint32 output_surface_id) { 407 uint32 output_surface_id) {
409 RenderWidgetHostImpl* host = client_->GetHost(); 408 RenderWidgetHostImpl* host = client_->GetHost();
410 DCHECK(resource_collection_); 409 DCHECK(resource_collection_);
411 410
412 cc::CompositorFrameAck ack; 411 cc::CompositorFrameAck ack;
413 resource_collection_->TakeUnusedResourcesForChildCompositor(&ack.resources); 412 resource_collection_->TakeUnusedResourcesForChildCompositor(&ack.resources);
414 DCHECK(!ack.resources.empty()); 413 DCHECK(!ack.resources.empty());
415 414
416 RenderWidgetHostImpl::SendReclaimCompositorResources( 415 RenderWidgetHostImpl::SendReclaimCompositorResources(
417 host->GetRoutingID(), 416 host->GetRoutingID(),
418 output_surface_id, 417 output_surface_id,
419 host->GetProcess()->GetID(), 418 host->GetProcess()->GetID(),
420 ack); 419 ack);
421 } 420 }
422 421
423 void DelegatedFrameHost::EvictDelegatedFrame() { 422 void DelegatedFrameLayerHost::EvictDelegatedFrame() {
424 client_->GetLayer()->SetShowPaintedContent(); 423 client_->GetLayer()->SetShowPaintedContent();
425 frame_provider_ = NULL; 424 frame_provider_ = NULL;
426 delegated_frame_evictor_->DiscardedFrame(); 425 delegated_frame_evictor_->DiscardedFrame();
427 } 426 }
428 427
429 // static 428 // static
430 void DelegatedFrameHost::CopyFromCompositingSurfaceHasResult( 429 void DelegatedFrameLayerHost::CopyFromCompositingSurfaceHasResult(
431 const gfx::Size& dst_size_in_pixel, 430 const gfx::Size& dst_size_in_pixel,
432 const SkColorType color_type, 431 const SkColorType color_type,
433 const base::Callback<void(bool, const SkBitmap&)>& callback, 432 const base::Callback<void(bool, const SkBitmap&)>& callback,
434 scoped_ptr<cc::CopyOutputResult> result) { 433 scoped_ptr<cc::CopyOutputResult> result) {
435 if (result->IsEmpty() || result->size().IsEmpty()) { 434 if (result->IsEmpty() || result->size().IsEmpty()) {
436 callback.Run(false, SkBitmap()); 435 callback.Run(false, SkBitmap());
437 return; 436 return;
438 } 437 }
439 438
440 if (result->HasTexture()) { 439 if (result->HasTexture()) {
441 PrepareTextureCopyOutputResult(dst_size_in_pixel, color_type, 440 PrepareTextureCopyOutputResult(
442 callback, 441 dst_size_in_pixel, color_type, callback, result.Pass());
443 result.Pass());
444 return; 442 return;
445 } 443 }
446 444
447 DCHECK(result->HasBitmap()); 445 DCHECK(result->HasBitmap());
448 PrepareBitmapCopyOutputResult(dst_size_in_pixel, color_type, callback, 446 PrepareBitmapCopyOutputResult(
449 result.Pass()); 447 dst_size_in_pixel, color_type, callback, result.Pass());
450 } 448 }
451 449
452 static void CopyFromCompositingSurfaceFinished( 450 static void CopyFromCompositingSurfaceFinished(
453 const base::Callback<void(bool, const SkBitmap&)>& callback, 451 const base::Callback<void(bool, const SkBitmap&)>& callback,
454 scoped_ptr<cc::SingleReleaseCallback> release_callback, 452 scoped_ptr<cc::SingleReleaseCallback> release_callback,
455 scoped_ptr<SkBitmap> bitmap, 453 scoped_ptr<SkBitmap> bitmap,
456 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock, 454 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock,
457 bool result) { 455 bool result) {
458 bitmap_pixels_lock.reset(); 456 bitmap_pixels_lock.reset();
459 457
460 uint32 sync_point = 0; 458 uint32 sync_point = 0;
461 if (result) { 459 if (result) {
462 GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper(); 460 GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper();
463 sync_point = gl_helper->InsertSyncPoint(); 461 sync_point = gl_helper->InsertSyncPoint();
464 } 462 }
465 bool lost_resource = sync_point == 0; 463 bool lost_resource = sync_point == 0;
466 release_callback->Run(sync_point, lost_resource); 464 release_callback->Run(sync_point, lost_resource);
467 465
468 callback.Run(result, *bitmap); 466 callback.Run(result, *bitmap);
469 } 467 }
470 468
471 // static 469 // static
472 void DelegatedFrameHost::PrepareTextureCopyOutputResult( 470 void DelegatedFrameLayerHost::PrepareTextureCopyOutputResult(
473 const gfx::Size& dst_size_in_pixel, 471 const gfx::Size& dst_size_in_pixel,
474 const SkColorType color_type, 472 const SkColorType color_type,
475 const base::Callback<void(bool, const SkBitmap&)>& callback, 473 const base::Callback<void(bool, const SkBitmap&)>& callback,
476 scoped_ptr<cc::CopyOutputResult> result) { 474 scoped_ptr<cc::CopyOutputResult> result) {
477 DCHECK(result->HasTexture()); 475 DCHECK(result->HasTexture());
478 base::ScopedClosureRunner scoped_callback_runner( 476 base::ScopedClosureRunner scoped_callback_runner(
479 base::Bind(callback, false, SkBitmap())); 477 base::Bind(callback, false, SkBitmap()));
480 478
481 scoped_ptr<SkBitmap> bitmap(new SkBitmap); 479 scoped_ptr<SkBitmap> bitmap(new SkBitmap);
482 if (!bitmap->allocPixels(SkImageInfo::Make(dst_size_in_pixel.width(), 480 if (!bitmap->allocPixels(SkImageInfo::Make(dst_size_in_pixel.width(),
(...skipping 28 matching lines...) Expand all
511 color_type, 509 color_type,
512 base::Bind(&CopyFromCompositingSurfaceFinished, 510 base::Bind(&CopyFromCompositingSurfaceFinished,
513 callback, 511 callback,
514 base::Passed(&release_callback), 512 base::Passed(&release_callback),
515 base::Passed(&bitmap), 513 base::Passed(&bitmap),
516 base::Passed(&bitmap_pixels_lock)), 514 base::Passed(&bitmap_pixels_lock)),
517 GLHelper::SCALER_QUALITY_FAST); 515 GLHelper::SCALER_QUALITY_FAST);
518 } 516 }
519 517
520 // static 518 // static
521 void DelegatedFrameHost::PrepareBitmapCopyOutputResult( 519 void DelegatedFrameLayerHost::PrepareBitmapCopyOutputResult(
522 const gfx::Size& dst_size_in_pixel, 520 const gfx::Size& dst_size_in_pixel,
523 const SkColorType color_type, 521 const SkColorType color_type,
524 const base::Callback<void(bool, const SkBitmap&)>& callback, 522 const base::Callback<void(bool, const SkBitmap&)>& callback,
525 scoped_ptr<cc::CopyOutputResult> result) { 523 scoped_ptr<cc::CopyOutputResult> result) {
526 if (color_type != kN32_SkColorType) { 524 if (color_type != kN32_SkColorType) {
527 NOTIMPLEMENTED(); 525 NOTIMPLEMENTED();
528 callback.Run(false, SkBitmap()); 526 callback.Run(false, SkBitmap());
529 return; 527 return;
530 } 528 }
531 DCHECK(result->HasBitmap()); 529 DCHECK(result->HasBitmap());
532 scoped_ptr<SkBitmap> source = result->TakeBitmap(); 530 scoped_ptr<SkBitmap> source = result->TakeBitmap();
533 DCHECK(source); 531 DCHECK(source);
534 SkBitmap bitmap = skia::ImageOperations::Resize( 532 SkBitmap bitmap =
535 *source, 533 skia::ImageOperations::Resize(*source,
536 skia::ImageOperations::RESIZE_BEST, 534 skia::ImageOperations::RESIZE_BEST,
537 dst_size_in_pixel.width(), 535 dst_size_in_pixel.width(),
538 dst_size_in_pixel.height()); 536 dst_size_in_pixel.height());
539 callback.Run(true, bitmap); 537 callback.Run(true, bitmap);
540 } 538 }
541 539
542 // static 540 // static
543 void DelegatedFrameHost::ReturnSubscriberTexture( 541 void DelegatedFrameLayerHost::ReturnSubscriberTexture(
544 base::WeakPtr<DelegatedFrameHost> dfh, 542 base::WeakPtr<DelegatedFrameLayerHost> dfh,
545 scoped_refptr<OwnedMailbox> subscriber_texture, 543 scoped_refptr<OwnedMailbox> subscriber_texture,
546 uint32 sync_point) { 544 uint32 sync_point) {
547 if (!subscriber_texture.get()) 545 if (!subscriber_texture.get())
548 return; 546 return;
549 if (!dfh) 547 if (!dfh)
550 return; 548 return;
551 549
552 subscriber_texture->UpdateSyncPoint(sync_point); 550 subscriber_texture->UpdateSyncPoint(sync_point);
553 551
554 if (dfh->frame_subscriber_ && subscriber_texture->texture_id()) 552 if (dfh->frame_subscriber_ && subscriber_texture->texture_id())
555 dfh->idle_frame_subscriber_textures_.push_back(subscriber_texture); 553 dfh->idle_frame_subscriber_textures_.push_back(subscriber_texture);
556 } 554 }
557 555
558 void DelegatedFrameHost::CopyFromCompositingSurfaceFinishedForVideo( 556 void DelegatedFrameLayerHost::CopyFromCompositingSurfaceFinishedForVideo(
559 base::WeakPtr<DelegatedFrameHost> dfh, 557 base::WeakPtr<DelegatedFrameLayerHost> dfh,
560 const base::Callback<void(bool)>& callback, 558 const base::Callback<void(bool)>& callback,
561 scoped_refptr<OwnedMailbox> subscriber_texture, 559 scoped_refptr<OwnedMailbox> subscriber_texture,
562 scoped_ptr<cc::SingleReleaseCallback> release_callback, 560 scoped_ptr<cc::SingleReleaseCallback> release_callback,
563 bool result) { 561 bool result) {
564 callback.Run(result); 562 callback.Run(result);
565 563
566 uint32 sync_point = 0; 564 uint32 sync_point = 0;
567 if (result) { 565 if (result) {
568 GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper(); 566 GLHelper* gl_helper = ImageTransportFactory::GetInstance()->GetGLHelper();
569 sync_point = gl_helper->InsertSyncPoint(); 567 sync_point = gl_helper->InsertSyncPoint();
570 } 568 }
571 if (release_callback) { 569 if (release_callback) {
572 // A release callback means the texture came from the compositor, so there 570 // A release callback means the texture came from the compositor, so there
573 // should be no |subscriber_texture|. 571 // should be no |subscriber_texture|.
574 DCHECK(!subscriber_texture); 572 DCHECK(!subscriber_texture);
575 bool lost_resource = sync_point == 0; 573 bool lost_resource = sync_point == 0;
576 release_callback->Run(sync_point, lost_resource); 574 release_callback->Run(sync_point, lost_resource);
577 } 575 }
578 ReturnSubscriberTexture(dfh, subscriber_texture, sync_point); 576 ReturnSubscriberTexture(dfh, subscriber_texture, sync_point);
579 } 577 }
580 578
581 // static 579 // static
582 void DelegatedFrameHost::CopyFromCompositingSurfaceHasResultForVideo( 580 void DelegatedFrameLayerHost::CopyFromCompositingSurfaceHasResultForVideo(
583 base::WeakPtr<DelegatedFrameHost> dfh, 581 base::WeakPtr<DelegatedFrameLayerHost> dfh,
584 scoped_refptr<OwnedMailbox> subscriber_texture, 582 scoped_refptr<OwnedMailbox> subscriber_texture,
585 scoped_refptr<media::VideoFrame> video_frame, 583 scoped_refptr<media::VideoFrame> video_frame,
586 const base::Callback<void(bool)>& callback, 584 const base::Callback<void(bool)>& callback,
587 scoped_ptr<cc::CopyOutputResult> result) { 585 scoped_ptr<cc::CopyOutputResult> result) {
588 base::ScopedClosureRunner scoped_callback_runner(base::Bind(callback, false)); 586 base::ScopedClosureRunner scoped_callback_runner(base::Bind(callback, false));
589 base::ScopedClosureRunner scoped_return_subscriber_texture( 587 base::ScopedClosureRunner scoped_return_subscriber_texture(
590 base::Bind(&ReturnSubscriberTexture, dfh, subscriber_texture, 0)); 588 base::Bind(&ReturnSubscriberTexture, dfh, subscriber_texture, 0));
591 589
592 if (!dfh) 590 if (!dfh)
593 return; 591 return;
594 if (result->IsEmpty()) 592 if (result->IsEmpty())
595 return; 593 return;
596 if (result->size().IsEmpty()) 594 if (result->size().IsEmpty())
597 return; 595 return;
598 596
599 // Compute the dest size we want after the letterboxing resize. Make the 597 // Compute the dest size we want after the letterboxing resize. Make the
600 // coordinates and sizes even because we letterbox in YUV space 598 // coordinates and sizes even because we letterbox in YUV space
601 // (see CopyRGBToVideoFrame). They need to be even for the UV samples to 599 // (see CopyRGBToVideoFrame). They need to be even for the UV samples to
602 // line up correctly. 600 // line up correctly.
603 // The video frame's coded_size() and the result's size() are both physical 601 // The video frame's coded_size() and the result's size() are both physical
604 // pixels. 602 // pixels.
605 gfx::Rect region_in_frame = 603 gfx::Rect region_in_frame = media::ComputeLetterboxRegion(
606 media::ComputeLetterboxRegion(gfx::Rect(video_frame->coded_size()), 604 gfx::Rect(video_frame->coded_size()), result->size());
607 result->size());
608 region_in_frame = gfx::Rect(region_in_frame.x() & ~1, 605 region_in_frame = gfx::Rect(region_in_frame.x() & ~1,
609 region_in_frame.y() & ~1, 606 region_in_frame.y() & ~1,
610 region_in_frame.width() & ~1, 607 region_in_frame.width() & ~1,
611 region_in_frame.height() & ~1); 608 region_in_frame.height() & ~1);
612 if (region_in_frame.IsEmpty()) 609 if (region_in_frame.IsEmpty())
613 return; 610 return;
614 611
615 if (!result->HasTexture()) { 612 if (!result->HasTexture()) {
616 DCHECK(result->HasBitmap()); 613 DCHECK(result->HasBitmap());
617 scoped_ptr<SkBitmap> bitmap = result->TakeBitmap(); 614 scoped_ptr<SkBitmap> bitmap = result->TakeBitmap();
618 // Scale the bitmap to the required size, if necessary. 615 // Scale the bitmap to the required size, if necessary.
619 SkBitmap scaled_bitmap; 616 SkBitmap scaled_bitmap;
620 if (result->size().width() != region_in_frame.width() || 617 if (result->size().width() != region_in_frame.width() ||
621 result->size().height() != region_in_frame.height()) { 618 result->size().height() != region_in_frame.height()) {
622 skia::ImageOperations::ResizeMethod method = 619 skia::ImageOperations::ResizeMethod method =
623 skia::ImageOperations::RESIZE_GOOD; 620 skia::ImageOperations::RESIZE_GOOD;
624 scaled_bitmap = skia::ImageOperations::Resize(*bitmap.get(), method, 621 scaled_bitmap = skia::ImageOperations::Resize(*bitmap.get(),
622 method,
625 region_in_frame.width(), 623 region_in_frame.width(),
626 region_in_frame.height()); 624 region_in_frame.height());
627 } else { 625 } else {
628 scaled_bitmap = *bitmap.get(); 626 scaled_bitmap = *bitmap.get();
629 } 627 }
630 628
631 { 629 {
632 SkAutoLockPixels scaled_bitmap_locker(scaled_bitmap); 630 SkAutoLockPixels scaled_bitmap_locker(scaled_bitmap);
633 631
634 media::CopyRGBToVideoFrame( 632 media::CopyRGBToVideoFrame(
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 video_frame->coded_size(), 683 video_frame->coded_size(),
686 region_in_frame, 684 region_in_frame,
687 true, 685 true,
688 true)); 686 true));
689 yuv_readback_pipeline = dfh->yuv_readback_pipeline_.get(); 687 yuv_readback_pipeline = dfh->yuv_readback_pipeline_.get();
690 } 688 }
691 689
692 ignore_result(scoped_callback_runner.Release()); 690 ignore_result(scoped_callback_runner.Release());
693 ignore_result(scoped_return_subscriber_texture.Release()); 691 ignore_result(scoped_return_subscriber_texture.Release());
694 base::Callback<void(bool result)> finished_callback = base::Bind( 692 base::Callback<void(bool result)> finished_callback = base::Bind(
695 &DelegatedFrameHost::CopyFromCompositingSurfaceFinishedForVideo, 693 &DelegatedFrameLayerHost::CopyFromCompositingSurfaceFinishedForVideo,
696 dfh->AsWeakPtr(), 694 dfh->AsWeakPtr(),
697 callback, 695 callback,
698 subscriber_texture, 696 subscriber_texture,
699 base::Passed(&release_callback)); 697 base::Passed(&release_callback));
700 yuv_readback_pipeline->ReadbackYUV(texture_mailbox.mailbox(), 698 yuv_readback_pipeline->ReadbackYUV(texture_mailbox.mailbox(),
701 texture_mailbox.sync_point(), 699 texture_mailbox.sync_point(),
702 video_frame.get(), 700 video_frame.get(),
703 finished_callback); 701 finished_callback);
704 } 702 }
705 703
706 //////////////////////////////////////////////////////////////////////////////// 704 ////////////////////////////////////////////////////////////////////////////////
707 // DelegatedFrameHost, ui::CompositorObserver implementation: 705 // DelegatedFrameLayerHost, ui::CompositorObserver implementation:
708 706
709 void DelegatedFrameHost::OnCompositingDidCommit( 707 void DelegatedFrameLayerHost::OnCompositingDidCommit(
710 ui::Compositor* compositor) { 708 ui::Compositor* compositor) {
711 RenderWidgetHostImpl* host = client_->GetHost(); 709 RenderWidgetHostImpl* host = client_->GetHost();
712 if (can_lock_compositor_ == NO_PENDING_COMMIT) { 710 if (can_lock_compositor_ == NO_PENDING_COMMIT) {
713 can_lock_compositor_ = YES_CAN_LOCK; 711 can_lock_compositor_ = YES_CAN_LOCK;
714 if (resize_lock_.get() && resize_lock_->GrabDeferredLock()) 712 if (resize_lock_.get() && resize_lock_->GrabDeferredLock())
715 can_lock_compositor_ = YES_DID_LOCK; 713 can_lock_compositor_ = YES_DID_LOCK;
716 } 714 }
717 RunOnCommitCallbacks(); 715 RunOnCommitCallbacks();
718 if (resize_lock_ && 716 if (resize_lock_ &&
719 resize_lock_->expected_size() == current_frame_size_in_dip_) { 717 resize_lock_->expected_size() == current_frame_size_in_dip_) {
720 resize_lock_.reset(); 718 resize_lock_.reset();
721 host->WasResized(); 719 host->WasResized();
722 // We may have had a resize while we had the lock (e.g. if the lock expired, 720 // We may have had a resize while we had the lock (e.g. if the lock expired,
723 // or if the UI still gave us some resizes), so make sure we grab a new lock 721 // or if the UI still gave us some resizes), so make sure we grab a new lock
724 // if necessary. 722 // if necessary.
725 MaybeCreateResizeLock(); 723 MaybeCreateResizeLock();
726 } 724 }
727 } 725 }
728 726
729 void DelegatedFrameHost::OnCompositingStarted( 727 void DelegatedFrameLayerHost::OnCompositingStarted(ui::Compositor* compositor,
730 ui::Compositor* compositor, base::TimeTicks start_time) { 728 base::TimeTicks start_time) {
731 last_draw_ended_ = start_time; 729 last_draw_ended_ = start_time;
732 } 730 }
733 731
734 void DelegatedFrameHost::OnCompositingEnded( 732 void DelegatedFrameLayerHost::OnCompositingEnded(ui::Compositor* compositor) {
735 ui::Compositor* compositor) {
736 } 733 }
737 734
738 void DelegatedFrameHost::OnCompositingAborted(ui::Compositor* compositor) { 735 void DelegatedFrameLayerHost::OnCompositingAborted(ui::Compositor* compositor) {
739 } 736 }
740 737
741 void DelegatedFrameHost::OnCompositingLockStateChanged( 738 void DelegatedFrameLayerHost::OnCompositingLockStateChanged(
742 ui::Compositor* compositor) { 739 ui::Compositor* compositor) {
743 // A compositor lock that is part of a resize lock timed out. We 740 // A compositor lock that is part of a resize lock timed out. We
744 // should display a renderer frame. 741 // should display a renderer frame.
745 if (!compositor->IsLocked() && can_lock_compositor_ == YES_DID_LOCK) { 742 if (!compositor->IsLocked() && can_lock_compositor_ == YES_DID_LOCK) {
746 can_lock_compositor_ = NO_PENDING_RENDERER_FRAME; 743 can_lock_compositor_ = NO_PENDING_RENDERER_FRAME;
747 } 744 }
748 } 745 }
749 746
750 void DelegatedFrameHost::OnUpdateVSyncParameters( 747 void DelegatedFrameLayerHost::OnUpdateVSyncParameters(
751 base::TimeTicks timebase, 748 base::TimeTicks timebase,
752 base::TimeDelta interval) { 749 base::TimeDelta interval) {
753 RenderWidgetHostImpl* host = client_->GetHost(); 750 RenderWidgetHostImpl* host = client_->GetHost();
754 if (client_->IsVisible()) 751 if (client_->IsVisible())
755 host->UpdateVSyncParameters(timebase, interval); 752 host->UpdateVSyncParameters(timebase, interval);
756 } 753 }
757 754
758 //////////////////////////////////////////////////////////////////////////////// 755 ////////////////////////////////////////////////////////////////////////////////
759 // RenderWidgetHostViewAura, ImageTransportFactoryObserver implementation: 756 // RenderWidgetHostViewAura, ImageTransportFactoryObserver implementation:
760 757
761 void DelegatedFrameHost::OnLostResources() { 758 void DelegatedFrameLayerHost::OnLostResources() {
762 RenderWidgetHostImpl* host = client_->GetHost(); 759 RenderWidgetHostImpl* host = client_->GetHost();
763 if (frame_provider_.get()) 760 if (frame_provider_.get())
764 EvictDelegatedFrame(); 761 EvictDelegatedFrame();
765 idle_frame_subscriber_textures_.clear(); 762 idle_frame_subscriber_textures_.clear();
766 yuv_readback_pipeline_.reset(); 763 yuv_readback_pipeline_.reset();
767 764
768 host->ScheduleComposite(); 765 host->ScheduleComposite();
769 } 766 }
770 767
771 //////////////////////////////////////////////////////////////////////////////// 768 ////////////////////////////////////////////////////////////////////////////////
772 // DelegatedFrameHost, private: 769 // DelegatedFrameLayerHost, private:
773 770
774 DelegatedFrameHost::~DelegatedFrameHost() { 771 DelegatedFrameLayerHost::~DelegatedFrameLayerHost() {
775 ImageTransportFactory::GetInstance()->RemoveObserver(this); 772 ImageTransportFactory::GetInstance()->RemoveObserver(this);
776 773
777 if (resource_collection_.get()) 774 if (resource_collection_.get())
778 resource_collection_->SetClient(NULL); 775 resource_collection_->SetClient(NULL);
779 776
780 DCHECK(!vsync_manager_); 777 DCHECK(!vsync_manager_);
781 } 778 }
782 779
783 void DelegatedFrameHost::RunOnCommitCallbacks() { 780 void DelegatedFrameLayerHost::RunOnCommitCallbacks() {
784 for (std::vector<base::Closure>::const_iterator 781 for (std::vector<base::Closure>::const_iterator it =
785 it = on_compositing_did_commit_callbacks_.begin(); 782 on_compositing_did_commit_callbacks_.begin();
786 it != on_compositing_did_commit_callbacks_.end(); ++it) { 783 it != on_compositing_did_commit_callbacks_.end();
784 ++it) {
787 it->Run(); 785 it->Run();
788 } 786 }
789 on_compositing_did_commit_callbacks_.clear(); 787 on_compositing_did_commit_callbacks_.clear();
790 } 788 }
791 789
792 void DelegatedFrameHost::AddOnCommitCallbackAndDisableLocks( 790 void DelegatedFrameLayerHost::AddOnCommitCallbackAndDisableLocks(
793 const base::Closure& callback) { 791 const base::Closure& callback) {
794 ui::Compositor* compositor = client_->GetCompositor(); 792 ui::Compositor* compositor = client_->GetCompositor();
795 DCHECK(compositor); 793 DCHECK(compositor);
796 794
797 if (!compositor->HasObserver(this)) 795 if (!compositor->HasObserver(this))
798 compositor->AddObserver(this); 796 compositor->AddObserver(this);
799 797
800 can_lock_compositor_ = NO_PENDING_COMMIT; 798 can_lock_compositor_ = NO_PENDING_COMMIT;
801 on_compositing_did_commit_callbacks_.push_back(callback); 799 on_compositing_did_commit_callbacks_.push_back(callback);
802 } 800 }
803 801
804 void DelegatedFrameHost::AddedToWindow() { 802 void DelegatedFrameLayerHost::AddedToWindow() {
805 ui::Compositor* compositor = client_->GetCompositor(); 803 ui::Compositor* compositor = client_->GetCompositor();
806 if (compositor) { 804 if (compositor) {
807 DCHECK(!vsync_manager_); 805 DCHECK(!vsync_manager_);
808 vsync_manager_ = compositor->vsync_manager(); 806 vsync_manager_ = compositor->vsync_manager();
809 vsync_manager_->AddObserver(this); 807 vsync_manager_->AddObserver(this);
810 } 808 }
811 } 809 }
812 810
813 void DelegatedFrameHost::RemovingFromWindow() { 811 void DelegatedFrameLayerHost::RemovingFromWindow() {
814 RunOnCommitCallbacks(); 812 RunOnCommitCallbacks();
815 resize_lock_.reset(); 813 resize_lock_.reset();
816 client_->GetHost()->WasResized(); 814 client_->GetHost()->WasResized();
817 ui::Compositor* compositor = client_->GetCompositor(); 815 ui::Compositor* compositor = client_->GetCompositor();
818 if (compositor && compositor->HasObserver(this)) 816 if (compositor && compositor->HasObserver(this))
819 compositor->RemoveObserver(this); 817 compositor->RemoveObserver(this);
820 818
821 if (vsync_manager_) { 819 if (vsync_manager_) {
822 vsync_manager_->RemoveObserver(this); 820 vsync_manager_->RemoveObserver(this);
823 vsync_manager_ = NULL; 821 vsync_manager_ = NULL;
824 } 822 }
825 } 823 }
826 824
827 void DelegatedFrameHost::LockResources() { 825 void DelegatedFrameLayerHost::LockResources() {
828 DCHECK(frame_provider_); 826 DCHECK(frame_provider_);
829 delegated_frame_evictor_->LockFrame(); 827 delegated_frame_evictor_->LockFrame();
830 } 828 }
831 829
832 void DelegatedFrameHost::UnlockResources() { 830 void DelegatedFrameLayerHost::UnlockResources() {
833 DCHECK(frame_provider_); 831 DCHECK(frame_provider_);
834 delegated_frame_evictor_->UnlockFrame(); 832 delegated_frame_evictor_->UnlockFrame();
835 } 833 }
836 834
837 //////////////////////////////////////////////////////////////////////////////// 835 ////////////////////////////////////////////////////////////////////////////////
838 // DelegatedFrameHost, ui::LayerOwnerDelegate implementation: 836 // DelegatedFrameLayerHost, ui::LayerOwnerDelegate implementation:
839 837
840 void DelegatedFrameHost::OnLayerRecreated(ui::Layer* old_layer, 838 void DelegatedFrameLayerHost::OnLayerRecreated(ui::Layer* old_layer,
841 ui::Layer* new_layer) { 839 ui::Layer* new_layer) {
842 // The new_layer is the one that will be used by our Window, so that's the one 840 // The new_layer is the one that will be used by our Window, so that's the one
843 // that should keep our frame. old_layer will be returned to the 841 // that should keep our frame. old_layer will be returned to the
844 // RecreateLayer caller, and should have a copy. 842 // RecreateLayer caller, and should have a copy.
845 if (frame_provider_.get()) { 843 if (frame_provider_.get()) {
846 new_layer->SetShowDelegatedContent(frame_provider_.get(), 844 new_layer->SetShowDelegatedContent(frame_provider_.get(),
847 current_frame_size_in_dip_); 845 current_frame_size_in_dip_);
848 } 846 }
849 } 847 }
850 848
851 } // namespace content 849 } // namespace content
852
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698