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

Side by Side Diff: content/browser/renderer_host/delegated_frame_host.cc

Issue 1841153002: BrowserCompositorMac, ResizeLock, DelegatedFrameHost => content/browser/renderer_host (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed Mac Build Created 4 years, 8 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
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/renderer_host/delegated_frame_host.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/callback_helpers.h" 12 #include "base/callback_helpers.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/time/default_tick_clock.h" 14 #include "base/time/default_tick_clock.h"
15 #include "cc/output/compositor_frame.h" 15 #include "cc/output/compositor_frame.h"
16 #include "cc/output/compositor_frame_ack.h" 16 #include "cc/output/compositor_frame_ack.h"
17 #include "cc/output/copy_output_request.h" 17 #include "cc/output/copy_output_request.h"
18 #include "cc/resources/single_release_callback.h" 18 #include "cc/resources/single_release_callback.h"
19 #include "cc/resources/texture_mailbox.h" 19 #include "cc/resources/texture_mailbox.h"
20 #include "cc/surfaces/surface.h" 20 #include "cc/surfaces/surface.h"
21 #include "cc/surfaces/surface_factory.h" 21 #include "cc/surfaces/surface_factory.h"
22 #include "cc/surfaces/surface_hittest.h" 22 #include "cc/surfaces/surface_hittest.h"
23 #include "cc/surfaces/surface_manager.h" 23 #include "cc/surfaces/surface_manager.h"
24 #include "content/browser/compositor/gl_helper.h" 24 #include "content/browser/compositor/gl_helper.h"
25 #include "content/browser/compositor/resize_lock.h"
26 #include "content/browser/compositor/surface_utils.h" 25 #include "content/browser/compositor/surface_utils.h"
27 #include "content/browser/gpu/compositor_util.h" 26 #include "content/browser/gpu/compositor_util.h"
27 #include "content/browser/renderer_host/resize_lock.h"
28 #include "content/public/browser/render_widget_host_view_frame_subscriber.h" 28 #include "content/public/browser/render_widget_host_view_frame_subscriber.h"
29 #include "content/public/common/content_switches.h" 29 #include "content/public/common/content_switches.h"
30 #include "media/base/video_frame.h" 30 #include "media/base/video_frame.h"
31 #include "media/base/video_util.h" 31 #include "media/base/video_util.h"
32 #include "skia/ext/image_operations.h" 32 #include "skia/ext/image_operations.h"
33 #include "third_party/skia/include/core/SkCanvas.h" 33 #include "third_party/skia/include/core/SkCanvas.h"
34 #include "third_party/skia/include/core/SkPaint.h" 34 #include "third_party/skia/include/core/SkPaint.h"
35 #include "third_party/skia/include/effects/SkLumaColorFilter.h" 35 #include "third_party/skia/include/effects/SkLumaColorFilter.h"
36 #include "ui/gfx/geometry/dip_util.h" 36 #include "ui/gfx/geometry/dip_util.h"
37 37
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); 77 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
78 factory->AddObserver(this); 78 factory->AddObserver(this);
79 id_allocator_ = factory->GetContextFactory()->CreateSurfaceIdAllocator(); 79 id_allocator_ = factory->GetContextFactory()->CreateSurfaceIdAllocator();
80 factory->GetSurfaceManager()->RegisterSurfaceFactoryClient( 80 factory->GetSurfaceManager()->RegisterSurfaceFactoryClient(
81 id_allocator_->id_namespace(), this); 81 id_allocator_->id_namespace(), this);
82 } 82 }
83 83
84 void DelegatedFrameHost::WasShown(const ui::LatencyInfo& latency_info) { 84 void DelegatedFrameHost::WasShown(const ui::LatencyInfo& latency_info) {
85 delegated_frame_evictor_->SetVisible(true); 85 delegated_frame_evictor_->SetVisible(true);
86 86
87 if (surface_id_.is_null() && 87 if (surface_id_.is_null() && !released_front_lock_.get()) {
88 !released_front_lock_.get()) {
89 if (compositor_) 88 if (compositor_)
90 released_front_lock_ = compositor_->GetCompositorLock(); 89 released_front_lock_ = compositor_->GetCompositorLock();
91 } 90 }
92 91
93 if (compositor_) { 92 if (compositor_) {
94 compositor_->SetLatencyInfo(latency_info); 93 compositor_->SetLatencyInfo(latency_info);
95 } 94 }
96 } 95 }
97 96
98 bool DelegatedFrameHost::HasSavedFrame() { 97 bool DelegatedFrameHost::HasSavedFrame() {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 const gfx::Rect& src_subrect, 164 const gfx::Rect& src_subrect,
166 const scoped_refptr<media::VideoFrame>& target, 165 const scoped_refptr<media::VideoFrame>& target,
167 const base::Callback<void(const gfx::Rect&, bool)>& callback) { 166 const base::Callback<void(const gfx::Rect&, bool)>& callback) {
168 if (!CanCopyToVideoFrame()) { 167 if (!CanCopyToVideoFrame()) {
169 callback.Run(gfx::Rect(), false); 168 callback.Run(gfx::Rect(), false);
170 return; 169 return;
171 } 170 }
172 171
173 scoped_ptr<cc::CopyOutputRequest> request = 172 scoped_ptr<cc::CopyOutputRequest> request =
174 cc::CopyOutputRequest::CreateRequest(base::Bind( 173 cc::CopyOutputRequest::CreateRequest(base::Bind(
175 &DelegatedFrameHost:: 174 &DelegatedFrameHost::CopyFromCompositingSurfaceHasResultForVideo,
176 CopyFromCompositingSurfaceHasResultForVideo,
177 AsWeakPtr(), // For caching the ReadbackYUVInterface on this class. 175 AsWeakPtr(), // For caching the ReadbackYUVInterface on this class.
178 nullptr, 176 nullptr, target, callback));
179 target,
180 callback));
181 request->set_area(src_subrect); 177 request->set_area(src_subrect);
182 RequestCopyOfOutput(std::move(request)); 178 RequestCopyOfOutput(std::move(request));
183 } 179 }
184 180
185 bool DelegatedFrameHost::CanCopyToBitmap() const { 181 bool DelegatedFrameHost::CanCopyToBitmap() const {
186 return compositor_ && 182 return compositor_ &&
187 client_->DelegatedFrameHostGetLayer()->has_external_content(); 183 client_->DelegatedFrameHostGetLayer()->has_external_content();
188 } 184 }
189 185
190 bool DelegatedFrameHost::CanCopyToVideoFrame() const { 186 bool DelegatedFrameHost::CanCopyToVideoFrame() const {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 transform.GetInverse(&transform)) { 233 transform.GetInverse(&transform)) {
238 transform.TransformPoint(transformed_point); 234 transform.TransformPoint(transformed_point);
239 } 235 }
240 } 236 }
241 237
242 bool DelegatedFrameHost::ShouldSkipFrame(gfx::Size size_in_dip) const { 238 bool DelegatedFrameHost::ShouldSkipFrame(gfx::Size size_in_dip) const {
243 // Should skip a frame only when another frame from the renderer is guaranteed 239 // Should skip a frame only when another frame from the renderer is guaranteed
244 // to replace it. Otherwise may cause hangs when the renderer is waiting for 240 // to replace it. Otherwise may cause hangs when the renderer is waiting for
245 // the completion of latency infos (such as when taking a Snapshot.) 241 // the completion of latency infos (such as when taking a Snapshot.)
246 if (can_lock_compositor_ == NO_PENDING_RENDERER_FRAME || 242 if (can_lock_compositor_ == NO_PENDING_RENDERER_FRAME ||
247 can_lock_compositor_ == NO_PENDING_COMMIT || 243 can_lock_compositor_ == NO_PENDING_COMMIT || !resize_lock_.get())
248 !resize_lock_.get())
249 return false; 244 return false;
250 245
251 return size_in_dip != resize_lock_->expected_size(); 246 return size_in_dip != resize_lock_->expected_size();
252 } 247 }
253 248
254 void DelegatedFrameHost::WasResized() { 249 void DelegatedFrameHost::WasResized() {
255 if (client_->DelegatedFrameHostDesiredSizeInDIP() != 250 if (client_->DelegatedFrameHostDesiredSizeInDIP() !=
256 current_frame_size_in_dip_ && 251 current_frame_size_in_dip_ &&
257 !client_->DelegatedFrameHostIsVisible()) 252 !client_->DelegatedFrameHostIsVisible())
258 EvictDelegatedFrame(); 253 EvictDelegatedFrame();
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 base::TimeTicks present_time; 320 base::TimeTicks present_time;
326 if (vsync_interval_ <= base::TimeDelta()) { 321 if (vsync_interval_ <= base::TimeDelta()) {
327 present_time = now; 322 present_time = now;
328 } else { 323 } else {
329 const int64_t intervals_elapsed = (now - vsync_timebase_) / vsync_interval_; 324 const int64_t intervals_elapsed = (now - vsync_timebase_) / vsync_interval_;
330 present_time = vsync_timebase_ + (intervals_elapsed + 1) * vsync_interval_; 325 present_time = vsync_timebase_ + (intervals_elapsed + 1) * vsync_interval_;
331 } 326 }
332 327
333 scoped_refptr<media::VideoFrame> frame; 328 scoped_refptr<media::VideoFrame> frame;
334 RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback callback; 329 RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback callback;
335 if (!frame_subscriber()->ShouldCaptureFrame(damage_rect, present_time, 330 if (!frame_subscriber()->ShouldCaptureFrame(damage_rect, present_time, &frame,
336 &frame, &callback)) 331 &callback))
337 return; 332 return;
338 333
339 // Get a texture to re-use; else, create a new one. 334 // Get a texture to re-use; else, create a new one.
340 scoped_refptr<OwnedMailbox> subscriber_texture; 335 scoped_refptr<OwnedMailbox> subscriber_texture;
341 if (!idle_frame_subscriber_textures_.empty()) { 336 if (!idle_frame_subscriber_textures_.empty()) {
342 subscriber_texture = idle_frame_subscriber_textures_.back(); 337 subscriber_texture = idle_frame_subscriber_textures_.back();
343 idle_frame_subscriber_textures_.pop_back(); 338 idle_frame_subscriber_textures_.pop_back();
344 } else if (GLHelper* helper = 339 } else if (GLHelper* helper =
345 ImageTransportFactory::GetInstance()->GetGLHelper()) { 340 ImageTransportFactory::GetInstance()->GetGLHelper()) {
346 subscriber_texture = new OwnedMailbox(helper); 341 subscriber_texture = new OwnedMailbox(helper);
347 } 342 }
348 343
349 scoped_ptr<cc::CopyOutputRequest> request = 344 scoped_ptr<cc::CopyOutputRequest> request =
350 cc::CopyOutputRequest::CreateRequest(base::Bind( 345 cc::CopyOutputRequest::CreateRequest(base::Bind(
351 &DelegatedFrameHost::CopyFromCompositingSurfaceHasResultForVideo, 346 &DelegatedFrameHost::CopyFromCompositingSurfaceHasResultForVideo,
352 AsWeakPtr(), 347 AsWeakPtr(), subscriber_texture, frame,
353 subscriber_texture,
354 frame,
355 base::Bind(callback, present_time))); 348 base::Bind(callback, present_time)));
356 // Setting the source in this copy request asks that the layer abort any prior 349 // Setting the source in this copy request asks that the layer abort any prior
357 // uncommitted copy requests made on behalf of the same frame subscriber. 350 // uncommitted copy requests made on behalf of the same frame subscriber.
358 // This will not affect any of the copy requests spawned elsewhere from 351 // This will not affect any of the copy requests spawned elsewhere from
359 // DelegatedFrameHost (e.g., a call to CopyFromCompositingSurface() for 352 // DelegatedFrameHost (e.g., a call to CopyFromCompositingSurface() for
360 // screenshots) since those copy requests do not specify |frame_subscriber()| 353 // screenshots) since those copy requests do not specify |frame_subscriber()|
361 // as a source. 354 // as a source.
362 request->set_source(frame_subscriber()); 355 request->set_source(frame_subscriber());
363 if (subscriber_texture.get()) { 356 if (subscriber_texture.get()) {
364 request->SetTextureMailbox(cc::TextureMailbox( 357 request->SetTextureMailbox(cc::TextureMailbox(
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 438
446 background_color_ = frame->metadata.root_background_color; 439 background_color_ = frame->metadata.root_background_color;
447 440
448 if (frame_size.IsEmpty()) { 441 if (frame_size.IsEmpty()) {
449 DCHECK(frame_data->resource_list.empty()); 442 DCHECK(frame_data->resource_list.empty());
450 EvictDelegatedFrame(); 443 EvictDelegatedFrame();
451 } else { 444 } else {
452 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); 445 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
453 cc::SurfaceManager* manager = factory->GetSurfaceManager(); 446 cc::SurfaceManager* manager = factory->GetSurfaceManager();
454 if (!surface_factory_) { 447 if (!surface_factory_) {
455 surface_factory_ = 448 surface_factory_ = make_scoped_ptr(new cc::SurfaceFactory(manager, this));
456 make_scoped_ptr(new cc::SurfaceFactory(manager, this));
457 } 449 }
458 if (surface_id_.is_null() || frame_size != current_surface_size_ || 450 if (surface_id_.is_null() || frame_size != current_surface_size_ ||
459 frame_size_in_dip != current_frame_size_in_dip_) { 451 frame_size_in_dip != current_frame_size_in_dip_) {
460 if (!surface_id_.is_null()) 452 if (!surface_id_.is_null())
461 surface_factory_->Destroy(surface_id_); 453 surface_factory_->Destroy(surface_id_);
462 surface_id_ = id_allocator_->GenerateId(); 454 surface_id_ = id_allocator_->GenerateId();
463 surface_factory_->Create(surface_id_); 455 surface_factory_->Create(surface_id_);
464 // manager must outlive compositors using it. 456 // manager must outlive compositors using it.
465 client_->DelegatedFrameHostGetLayer()->SetShowSurface( 457 client_->DelegatedFrameHostGetLayer()->SetShowSurface(
466 surface_id_, 458 surface_id_, base::Bind(&SatisfyCallback, base::Unretained(manager)),
467 base::Bind(&SatisfyCallback, base::Unretained(manager)),
468 base::Bind(&RequireCallback, base::Unretained(manager)), frame_size, 459 base::Bind(&RequireCallback, base::Unretained(manager)), frame_size,
469 frame_device_scale_factor, frame_size_in_dip); 460 frame_device_scale_factor, frame_size_in_dip);
470 current_surface_size_ = frame_size; 461 current_surface_size_ = frame_size;
471 current_scale_factor_ = frame_device_scale_factor; 462 current_scale_factor_ = frame_device_scale_factor;
472 } 463 }
473 464
474 frame->metadata.latency_info.insert(frame->metadata.latency_info.end(), 465 frame->metadata.latency_info.insert(frame->metadata.latency_info.end(),
475 skipped_latency_info_list_.begin(), 466 skipped_latency_info_list_.begin(),
476 skipped_latency_info_list_.end()); 467 skipped_latency_info_list_.end());
477 skipped_latency_info_list_.clear(); 468 skipped_latency_info_list_.clear();
478 469
479 gfx::Size desired_size = client_->DelegatedFrameHostDesiredSizeInDIP(); 470 gfx::Size desired_size = client_->DelegatedFrameHostDesiredSizeInDIP();
480 if (desired_size != frame_size_in_dip && !desired_size.IsEmpty()) 471 if (desired_size != frame_size_in_dip && !desired_size.IsEmpty())
481 skip_frame = true; 472 skip_frame = true;
482 473
483 cc::SurfaceFactory::DrawCallback ack_callback; 474 cc::SurfaceFactory::DrawCallback ack_callback;
484 if (compositor_ && !skip_frame) { 475 if (compositor_ && !skip_frame) {
485 ack_callback = base::Bind(&DelegatedFrameHost::SurfaceDrawn, 476 ack_callback = base::Bind(&DelegatedFrameHost::SurfaceDrawn, AsWeakPtr(),
486 AsWeakPtr(), output_surface_id); 477 output_surface_id);
487 } 478 }
488 surface_factory_->SubmitCompositorFrame(surface_id_, std::move(frame), 479 surface_factory_->SubmitCompositorFrame(surface_id_, std::move(frame),
489 ack_callback); 480 ack_callback);
490 } 481 }
491 released_front_lock_ = NULL; 482 released_front_lock_ = NULL;
492 current_frame_size_in_dip_ = frame_size_in_dip; 483 current_frame_size_in_dip_ = frame_size_in_dip;
493 CheckResizeLock(); 484 CheckResizeLock();
494 485
495 UpdateGutters(); 486 UpdateGutters();
496 487
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 ack.resources.swap(surface_returned_resources_); 528 ack.resources.swap(surface_returned_resources_);
538 529
539 client_->DelegatedFrameHostSendReclaimCompositorResources(output_surface_id, 530 client_->DelegatedFrameHostSendReclaimCompositorResources(output_surface_id,
540 ack); 531 ack);
541 } 532 }
542 533
543 void DelegatedFrameHost::ReturnResources( 534 void DelegatedFrameHost::ReturnResources(
544 const cc::ReturnedResourceArray& resources) { 535 const cc::ReturnedResourceArray& resources) {
545 if (resources.empty()) 536 if (resources.empty())
546 return; 537 return;
547 std::copy(resources.begin(), 538 std::copy(resources.begin(), resources.end(),
548 resources.end(),
549 std::back_inserter(surface_returned_resources_)); 539 std::back_inserter(surface_returned_resources_));
550 if (!pending_delegated_ack_count_) 540 if (!pending_delegated_ack_count_)
551 SendReturnedDelegatedResources(last_output_surface_id_); 541 SendReturnedDelegatedResources(last_output_surface_id_);
552 } 542 }
553 543
554 void DelegatedFrameHost::WillDrawSurface(cc::SurfaceId id, 544 void DelegatedFrameHost::WillDrawSurface(cc::SurfaceId id,
555 const gfx::Rect& damage_rect) { 545 const gfx::Rect& damage_rect) {
556 if (id != surface_id_) 546 if (id != surface_id_)
557 return; 547 return;
558 AttemptFrameSubscriberCapture(damage_rect); 548 AttemptFrameSubscriberCapture(damage_rect);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 606
617 // static 607 // static
618 void DelegatedFrameHost::CopyFromCompositingSurfaceHasResultForVideo( 608 void DelegatedFrameHost::CopyFromCompositingSurfaceHasResultForVideo(
619 base::WeakPtr<DelegatedFrameHost> dfh, 609 base::WeakPtr<DelegatedFrameHost> dfh,
620 scoped_refptr<OwnedMailbox> subscriber_texture, 610 scoped_refptr<OwnedMailbox> subscriber_texture,
621 scoped_refptr<media::VideoFrame> video_frame, 611 scoped_refptr<media::VideoFrame> video_frame,
622 const base::Callback<void(const gfx::Rect&, bool)>& callback, 612 const base::Callback<void(const gfx::Rect&, bool)>& callback,
623 scoped_ptr<cc::CopyOutputResult> result) { 613 scoped_ptr<cc::CopyOutputResult> result) {
624 base::ScopedClosureRunner scoped_callback_runner( 614 base::ScopedClosureRunner scoped_callback_runner(
625 base::Bind(callback, gfx::Rect(), false)); 615 base::Bind(callback, gfx::Rect(), false));
626 base::ScopedClosureRunner scoped_return_subscriber_texture( 616 base::ScopedClosureRunner scoped_return_subscriber_texture(base::Bind(
627 base::Bind(&ReturnSubscriberTexture, dfh, subscriber_texture, 617 &ReturnSubscriberTexture, dfh, subscriber_texture, gpu::SyncToken()));
628 gpu::SyncToken()));
629 618
630 if (!dfh) 619 if (!dfh)
631 return; 620 return;
632 if (result->IsEmpty()) 621 if (result->IsEmpty())
633 return; 622 return;
634 if (result->size().IsEmpty()) 623 if (result->size().IsEmpty())
635 return; 624 return;
636 625
637 // Compute the dest size we want after the letterboxing resize. Make the 626 // Compute the dest size we want after the letterboxing resize. Make the
638 // coordinates and sizes even because we letterbox in YUV space 627 // coordinates and sizes even because we letterbox in YUV space
639 // (see CopyRGBToVideoFrame). They need to be even for the UV samples to 628 // (see CopyRGBToVideoFrame). They need to be even for the UV samples to
640 // line up correctly. 629 // line up correctly.
641 // The video frame's visible_rect() and the result's size() are both physical 630 // The video frame's visible_rect() and the result's size() are both physical
642 // pixels. 631 // pixels.
643 gfx::Rect region_in_frame = media::ComputeLetterboxRegion( 632 gfx::Rect region_in_frame = media::ComputeLetterboxRegion(
644 video_frame->visible_rect(), result->size()); 633 video_frame->visible_rect(), result->size());
645 region_in_frame = gfx::Rect(region_in_frame.x() & ~1, 634 region_in_frame =
646 region_in_frame.y() & ~1, 635 gfx::Rect(region_in_frame.x() & ~1, region_in_frame.y() & ~1,
647 region_in_frame.width() & ~1, 636 region_in_frame.width() & ~1, region_in_frame.height() & ~1);
648 region_in_frame.height() & ~1);
649 if (region_in_frame.IsEmpty()) 637 if (region_in_frame.IsEmpty())
650 return; 638 return;
651 639
652 if (!result->HasTexture()) { 640 if (!result->HasTexture()) {
653 DCHECK(result->HasBitmap()); 641 DCHECK(result->HasBitmap());
654 scoped_ptr<SkBitmap> bitmap = result->TakeBitmap(); 642 scoped_ptr<SkBitmap> bitmap = result->TakeBitmap();
655 // Scale the bitmap to the required size, if necessary. 643 // Scale the bitmap to the required size, if necessary.
656 SkBitmap scaled_bitmap; 644 SkBitmap scaled_bitmap;
657 if (result->size() != region_in_frame.size()) { 645 if (result->size() != region_in_frame.size()) {
658 skia::ImageOperations::ResizeMethod method = 646 skia::ImageOperations::ResizeMethod method =
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 std::string switch_value = 694 std::string switch_value =
707 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 695 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
708 quality_switch); 696 quality_switch);
709 if (switch_value == "fast") 697 if (switch_value == "fast")
710 quality = GLHelper::SCALER_QUALITY_FAST; 698 quality = GLHelper::SCALER_QUALITY_FAST;
711 else if (switch_value == "good") 699 else if (switch_value == "good")
712 quality = GLHelper::SCALER_QUALITY_GOOD; 700 quality = GLHelper::SCALER_QUALITY_GOOD;
713 else if (switch_value == "best") 701 else if (switch_value == "best")
714 quality = GLHelper::SCALER_QUALITY_BEST; 702 quality = GLHelper::SCALER_QUALITY_BEST;
715 703
716 dfh->yuv_readback_pipeline_.reset( 704 dfh->yuv_readback_pipeline_.reset(gl_helper->CreateReadbackPipelineYUV(
717 gl_helper->CreateReadbackPipelineYUV(quality, 705 quality, result_rect.size(), result_rect, region_in_frame.size(), true,
718 result_rect.size(), 706 true));
719 result_rect,
720 region_in_frame.size(),
721 true,
722 true));
723 yuv_readback_pipeline = dfh->yuv_readback_pipeline_.get(); 707 yuv_readback_pipeline = dfh->yuv_readback_pipeline_.get();
724 } 708 }
725 709
726 ignore_result(scoped_callback_runner.Release()); 710 ignore_result(scoped_callback_runner.Release());
727 ignore_result(scoped_return_subscriber_texture.Release()); 711 ignore_result(scoped_return_subscriber_texture.Release());
728 712
729 base::Callback<void(bool result)> finished_callback = base::Bind( 713 base::Callback<void(bool result)> finished_callback = base::Bind(
730 &DelegatedFrameHost::CopyFromCompositingSurfaceFinishedForVideo, 714 &DelegatedFrameHost::CopyFromCompositingSurfaceFinishedForVideo,
731 dfh->AsWeakPtr(), base::Bind(callback, region_in_frame), 715 dfh->AsWeakPtr(), base::Bind(callback, region_in_frame),
732 subscriber_texture, base::Passed(&release_callback)); 716 subscriber_texture, base::Passed(&release_callback));
733 yuv_readback_pipeline->ReadbackYUV(texture_mailbox.mailbox(), 717 yuv_readback_pipeline->ReadbackYUV(
734 texture_mailbox.sync_token(), 718 texture_mailbox.mailbox(), texture_mailbox.sync_token(),
735 video_frame.get(), 719 video_frame.get(), region_in_frame.origin(), finished_callback);
736 region_in_frame.origin(),
737 finished_callback);
738 } 720 }
739 721
740 //////////////////////////////////////////////////////////////////////////////// 722 ////////////////////////////////////////////////////////////////////////////////
741 // DelegatedFrameHost, ui::CompositorObserver implementation: 723 // DelegatedFrameHost, ui::CompositorObserver implementation:
742 724
743 void DelegatedFrameHost::OnCompositingDidCommit( 725 void DelegatedFrameHost::OnCompositingDidCommit(ui::Compositor* compositor) {
744 ui::Compositor* compositor) {
745 if (can_lock_compositor_ == NO_PENDING_COMMIT) { 726 if (can_lock_compositor_ == NO_PENDING_COMMIT) {
746 can_lock_compositor_ = YES_CAN_LOCK; 727 can_lock_compositor_ = YES_CAN_LOCK;
747 if (resize_lock_.get() && resize_lock_->GrabDeferredLock()) 728 if (resize_lock_.get() && resize_lock_->GrabDeferredLock())
748 can_lock_compositor_ = YES_DID_LOCK; 729 can_lock_compositor_ = YES_DID_LOCK;
749 } 730 }
750 if (resize_lock_ && 731 if (resize_lock_ &&
751 resize_lock_->expected_size() == current_frame_size_in_dip_) { 732 resize_lock_->expected_size() == current_frame_size_in_dip_) {
752 resize_lock_.reset(); 733 resize_lock_.reset();
753 client_->DelegatedFrameHostResizeLockWasReleased(); 734 client_->DelegatedFrameHostResizeLockWasReleased();
754 // We may have had a resize while we had the lock (e.g. if the lock expired, 735 // We may have had a resize while we had the lock (e.g. if the lock expired,
755 // or if the UI still gave us some resizes), so make sure we grab a new lock 736 // or if the UI still gave us some resizes), so make sure we grab a new lock
756 // if necessary. 737 // if necessary.
757 MaybeCreateResizeLock(); 738 MaybeCreateResizeLock();
758 } 739 }
759 } 740 }
760 741
761 void DelegatedFrameHost::OnCompositingStarted( 742 void DelegatedFrameHost::OnCompositingStarted(ui::Compositor* compositor,
762 ui::Compositor* compositor, base::TimeTicks start_time) { 743 base::TimeTicks start_time) {
763 last_draw_ended_ = start_time; 744 last_draw_ended_ = start_time;
764 } 745 }
765 746
766 void DelegatedFrameHost::OnCompositingEnded( 747 void DelegatedFrameHost::OnCompositingEnded(ui::Compositor* compositor) {}
767 ui::Compositor* compositor) {
768 }
769 748
770 void DelegatedFrameHost::OnCompositingAborted(ui::Compositor* compositor) { 749 void DelegatedFrameHost::OnCompositingAborted(ui::Compositor* compositor) {}
771 }
772 750
773 void DelegatedFrameHost::OnCompositingLockStateChanged( 751 void DelegatedFrameHost::OnCompositingLockStateChanged(
774 ui::Compositor* compositor) { 752 ui::Compositor* compositor) {
775 // A compositor lock that is part of a resize lock timed out. We 753 // A compositor lock that is part of a resize lock timed out. We
776 // should display a renderer frame. 754 // should display a renderer frame.
777 if (!compositor->IsLocked() && can_lock_compositor_ == YES_DID_LOCK) { 755 if (!compositor->IsLocked() && can_lock_compositor_ == YES_DID_LOCK) {
778 can_lock_compositor_ = NO_PENDING_RENDERER_FRAME; 756 can_lock_compositor_ = NO_PENDING_RENDERER_FRAME;
779 } 757 }
780 } 758 }
781 759
782 void DelegatedFrameHost::OnCompositingShuttingDown(ui::Compositor* compositor) { 760 void DelegatedFrameHost::OnCompositingShuttingDown(ui::Compositor* compositor) {
783 DCHECK_EQ(compositor, compositor_); 761 DCHECK_EQ(compositor, compositor_);
784 ResetCompositor(); 762 ResetCompositor();
785 DCHECK(!compositor_); 763 DCHECK(!compositor_);
786 } 764 }
787 765
788 void DelegatedFrameHost::OnUpdateVSyncParameters( 766 void DelegatedFrameHost::OnUpdateVSyncParameters(base::TimeTicks timebase,
789 base::TimeTicks timebase, 767 base::TimeDelta interval) {
790 base::TimeDelta interval) {
791 SetVSyncParameters(timebase, interval); 768 SetVSyncParameters(timebase, interval);
792 if (client_->DelegatedFrameHostIsVisible()) 769 if (client_->DelegatedFrameHostIsVisible())
793 client_->DelegatedFrameHostUpdateVSyncParameters(timebase, interval); 770 client_->DelegatedFrameHostUpdateVSyncParameters(timebase, interval);
794 } 771 }
795 772
796 //////////////////////////////////////////////////////////////////////////////// 773 ////////////////////////////////////////////////////////////////////////////////
797 // DelegatedFrameHost, ImageTransportFactoryObserver implementation: 774 // DelegatedFrameHost, ImageTransportFactoryObserver implementation:
798 775
799 void DelegatedFrameHost::OnLostResources() { 776 void DelegatedFrameHost::OnLostResources() {
800 if (!surface_id_.is_null()) 777 if (!surface_id_.is_null())
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 859
883 void DelegatedFrameHost::UnlockResources() { 860 void DelegatedFrameHost::UnlockResources() {
884 DCHECK(!surface_id_.is_null()); 861 DCHECK(!surface_id_.is_null());
885 delegated_frame_evictor_->UnlockFrame(); 862 delegated_frame_evictor_->UnlockFrame();
886 } 863 }
887 864
888 //////////////////////////////////////////////////////////////////////////////// 865 ////////////////////////////////////////////////////////////////////////////////
889 // DelegatedFrameHost, ui::LayerOwnerDelegate implementation: 866 // DelegatedFrameHost, ui::LayerOwnerDelegate implementation:
890 867
891 void DelegatedFrameHost::OnLayerRecreated(ui::Layer* old_layer, 868 void DelegatedFrameHost::OnLayerRecreated(ui::Layer* old_layer,
892 ui::Layer* new_layer) { 869 ui::Layer* new_layer) {
893 // The new_layer is the one that will be used by our Window, so that's the one 870 // The new_layer is the one that will be used by our Window, so that's the one
894 // that should keep our frame. old_layer will be returned to the 871 // that should keep our frame. old_layer will be returned to the
895 // RecreateLayer caller, and should have a copy. 872 // RecreateLayer caller, and should have a copy.
896 if (!surface_id_.is_null()) { 873 if (!surface_id_.is_null()) {
897 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); 874 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
898 cc::SurfaceManager* manager = factory->GetSurfaceManager(); 875 cc::SurfaceManager* manager = factory->GetSurfaceManager();
899 new_layer->SetShowSurface( 876 new_layer->SetShowSurface(
900 surface_id_, base::Bind(&SatisfyCallback, base::Unretained(manager)), 877 surface_id_, base::Bind(&SatisfyCallback, base::Unretained(manager)),
901 base::Bind(&RequireCallback, base::Unretained(manager)), 878 base::Bind(&RequireCallback, base::Unretained(manager)),
902 current_surface_size_, current_scale_factor_, 879 current_surface_size_, current_scale_factor_,
903 current_frame_size_in_dip_); 880 current_frame_size_in_dip_);
904 } 881 }
905 } 882 }
906 883
907 } // namespace content 884 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/delegated_frame_host.h ('k') | content/browser/renderer_host/render_widget_host_view_aura.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698