| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/compositor/delegated_frame_host.h" | 5 #include "content/browser/compositor/delegated_frame_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.h" |
| 14 #include "cc/surfaces/surface_factory.h" | 15 #include "cc/surfaces/surface_factory.h" |
| 16 #include "cc/surfaces/surface_manager.h" |
| 15 #include "content/browser/compositor/resize_lock.h" | 17 #include "content/browser/compositor/resize_lock.h" |
| 16 #include "content/browser/gpu/compositor_util.h" | 18 #include "content/browser/gpu/compositor_util.h" |
| 17 #include "content/common/gpu/client/gl_helper.h" | 19 #include "content/common/gpu/client/gl_helper.h" |
| 18 #include "content/public/browser/render_widget_host_view_frame_subscriber.h" | 20 #include "content/public/browser/render_widget_host_view_frame_subscriber.h" |
| 19 #include "content/public/common/content_switches.h" | 21 #include "content/public/common/content_switches.h" |
| 20 #include "media/base/video_frame.h" | 22 #include "media/base/video_frame.h" |
| 21 #include "media/base/video_util.h" | 23 #include "media/base/video_util.h" |
| 22 #include "skia/ext/image_operations.h" | 24 #include "skia/ext/image_operations.h" |
| 23 #include "third_party/skia/include/core/SkCanvas.h" | 25 #include "third_party/skia/include/core/SkCanvas.h" |
| 24 #include "third_party/skia/include/core/SkPaint.h" | 26 #include "third_party/skia/include/core/SkPaint.h" |
| 25 #include "third_party/skia/include/effects/SkLumaColorFilter.h" | 27 #include "third_party/skia/include/effects/SkLumaColorFilter.h" |
| 26 #include "ui/gfx/frame_time.h" | 28 #include "ui/gfx/frame_time.h" |
| 27 | 29 |
| 28 namespace content { | 30 namespace content { |
| 29 | 31 |
| 32 namespace { |
| 33 |
| 34 void SatisfyCallback(cc::SurfaceManager* manager, |
| 35 cc::SurfaceSequence sequence) { |
| 36 std::vector<uint32_t> sequences; |
| 37 sequences.push_back(sequence.sequence); |
| 38 manager->DidSatisfySequences(sequence.id_namespace, &sequences); |
| 39 } |
| 40 |
| 41 void RequireCallback(cc::SurfaceManager* manager, |
| 42 cc::SurfaceId id, |
| 43 cc::SurfaceSequence sequence) { |
| 44 cc::Surface* surface = manager->GetSurfaceForId(id); |
| 45 if (!surface) { |
| 46 LOG(ERROR) << "Attempting to require callback on nonexistent surface"; |
| 47 return; |
| 48 } |
| 49 surface->AddDestructionDependency(sequence); |
| 50 } |
| 51 |
| 52 } // namespace |
| 53 |
| 30 //////////////////////////////////////////////////////////////////////////////// | 54 //////////////////////////////////////////////////////////////////////////////// |
| 31 // DelegatedFrameHostClient | 55 // DelegatedFrameHostClient |
| 32 | 56 |
| 33 bool DelegatedFrameHostClient::ShouldCreateResizeLock() { | 57 bool DelegatedFrameHostClient::ShouldCreateResizeLock() { |
| 34 // On Windows and Linux, holding pointer moves will not help throttling | 58 // On Windows and Linux, holding pointer moves will not help throttling |
| 35 // resizes. | 59 // resizes. |
| 36 // TODO(piman): on Windows we need to block (nested message loop?) the | 60 // TODO(piman): on Windows we need to block (nested message loop?) the |
| 37 // WM_SIZE event. On Linux we need to throttle at the WM level using | 61 // WM_SIZE event. On Linux we need to throttle at the WM level using |
| 38 // _NET_WM_SYNC_REQUEST. | 62 // _NET_WM_SYNC_REQUEST. |
| 39 // TODO(ccameron): Mac browser window resizing is incompletely implemented. | 63 // TODO(ccameron): Mac browser window resizing is incompletely implemented. |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 resource_collection_ = NULL; | 388 resource_collection_ = NULL; |
| 365 } | 389 } |
| 366 last_output_surface_id_ = output_surface_id; | 390 last_output_surface_id_ = output_surface_id; |
| 367 } | 391 } |
| 368 ui::Compositor* compositor = client_->GetCompositor(); | 392 ui::Compositor* compositor = client_->GetCompositor(); |
| 369 if (frame_size.IsEmpty()) { | 393 if (frame_size.IsEmpty()) { |
| 370 DCHECK(frame_data->resource_list.empty()); | 394 DCHECK(frame_data->resource_list.empty()); |
| 371 EvictDelegatedFrame(); | 395 EvictDelegatedFrame(); |
| 372 } else { | 396 } else { |
| 373 if (use_surfaces_) { | 397 if (use_surfaces_) { |
| 398 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
| 399 cc::SurfaceManager* manager = factory->GetSurfaceManager(); |
| 374 if (!surface_factory_) { | 400 if (!surface_factory_) { |
| 375 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | |
| 376 cc::SurfaceManager* manager = factory->GetSurfaceManager(); | |
| 377 id_allocator_ = | 401 id_allocator_ = |
| 378 factory->GetContextFactory()->CreateSurfaceIdAllocator(); | 402 factory->GetContextFactory()->CreateSurfaceIdAllocator(); |
| 379 surface_factory_ = | 403 surface_factory_ = |
| 380 make_scoped_ptr(new cc::SurfaceFactory(manager, this)); | 404 make_scoped_ptr(new cc::SurfaceFactory(manager, this)); |
| 381 } | 405 } |
| 382 if (surface_id_.is_null() || frame_size != current_surface_size_ || | 406 if (surface_id_.is_null() || frame_size != current_surface_size_ || |
| 383 frame_size_in_dip != current_frame_size_in_dip_) { | 407 frame_size_in_dip != current_frame_size_in_dip_) { |
| 384 if (!surface_id_.is_null()) { | 408 if (!surface_id_.is_null()) |
| 385 if (compositor) { | 409 surface_factory_->Destroy(surface_id_); |
| 386 std::set<cc::SurfaceSequence> seq; | |
| 387 seq.insert(compositor->InsertSurfaceSequenceForNextFrame()); | |
| 388 // Destruction of this surface needs to wait for compositors that | |
| 389 // have drawn using it to swap frames that don't reference it. | |
| 390 // TODO(jbauman): Handle cases where the compositor has been | |
| 391 // changed since the last draw. | |
| 392 surface_factory_->DestroyOnSequence(surface_id_, seq); | |
| 393 } else { | |
| 394 surface_factory_->Destroy(surface_id_); | |
| 395 } | |
| 396 } | |
| 397 surface_id_ = id_allocator_->GenerateId(); | 410 surface_id_ = id_allocator_->GenerateId(); |
| 398 surface_factory_->Create(surface_id_, frame_size); | 411 surface_factory_->Create(surface_id_, frame_size); |
| 399 client_->GetLayer()->SetShowSurface(surface_id_, frame_size_in_dip); | 412 // manager must outlive compositors using it. |
| 413 client_->GetLayer()->SetShowSurface( |
| 414 surface_id_, |
| 415 base::Bind(&SatisfyCallback, base::Unretained(manager)), |
| 416 base::Bind(&RequireCallback, base::Unretained(manager)), |
| 417 frame_size_in_dip); |
| 400 current_surface_size_ = frame_size; | 418 current_surface_size_ = frame_size; |
| 401 } | 419 } |
| 402 scoped_ptr<cc::CompositorFrame> compositor_frame = | 420 scoped_ptr<cc::CompositorFrame> compositor_frame = |
| 403 make_scoped_ptr(new cc::CompositorFrame()); | 421 make_scoped_ptr(new cc::CompositorFrame()); |
| 404 compositor_frame->delegated_frame_data = frame_data.Pass(); | 422 compositor_frame->delegated_frame_data = frame_data.Pass(); |
| 405 | 423 |
| 406 compositor_frame->metadata.latency_info.swap(skipped_latency_info_list_); | 424 compositor_frame->metadata.latency_info.swap(skipped_latency_info_list_); |
| 407 compositor_frame->metadata.latency_info.insert( | 425 compositor_frame->metadata.latency_info.insert( |
| 408 compositor_frame->metadata.latency_info.end(), | 426 compositor_frame->metadata.latency_info.end(), |
| 409 latency_info.begin(), | 427 latency_info.begin(), |
| (...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 991 void DelegatedFrameHost::OnLayerRecreated(ui::Layer* old_layer, | 1009 void DelegatedFrameHost::OnLayerRecreated(ui::Layer* old_layer, |
| 992 ui::Layer* new_layer) { | 1010 ui::Layer* new_layer) { |
| 993 // The new_layer is the one that will be used by our Window, so that's the one | 1011 // The new_layer is the one that will be used by our Window, so that's the one |
| 994 // that should keep our frame. old_layer will be returned to the | 1012 // that should keep our frame. old_layer will be returned to the |
| 995 // RecreateLayer caller, and should have a copy. | 1013 // RecreateLayer caller, and should have a copy. |
| 996 if (frame_provider_.get()) { | 1014 if (frame_provider_.get()) { |
| 997 new_layer->SetShowDelegatedContent(frame_provider_.get(), | 1015 new_layer->SetShowDelegatedContent(frame_provider_.get(), |
| 998 current_frame_size_in_dip_); | 1016 current_frame_size_in_dip_); |
| 999 } | 1017 } |
| 1000 if (!surface_id_.is_null()) { | 1018 if (!surface_id_.is_null()) { |
| 1001 new_layer->SetShowSurface(surface_id_, current_frame_size_in_dip_); | 1019 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
| 1020 cc::SurfaceManager* manager = factory->GetSurfaceManager(); |
| 1021 new_layer->SetShowSurface( |
| 1022 surface_id_, base::Bind(&SatisfyCallback, base::Unretained(manager)), |
| 1023 base::Bind(&RequireCallback, base::Unretained(manager)), |
| 1024 current_frame_size_in_dip_); |
| 1002 } | 1025 } |
| 1003 } | 1026 } |
| 1004 | 1027 |
| 1005 } // namespace content | 1028 } // namespace content |
| OLD | NEW |