OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "components/view_manager/surfaces/top_level_display_client.h" |
| 6 |
| 7 #include "cc/output/compositor_frame.h" |
| 8 #include "cc/surfaces/display.h" |
| 9 #include "components/view_manager/gles2/gpu_state.h" |
| 10 #include "components/view_manager/surfaces/surfaces_context_provider.h" |
| 11 #include "components/view_manager/surfaces/surfaces_output_surface.h" |
| 12 #include "components/view_manager/surfaces/surfaces_scheduler.h" |
| 13 #include "components/view_manager/surfaces/surfaces_state.h" |
| 14 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 15 #include "mojo/converters/surfaces/surfaces_type_converters.h" |
| 16 |
| 17 namespace surfaces { |
| 18 namespace { |
| 19 void CallCallback(const mojo::Closure& callback, cc::SurfaceDrawStatus status) { |
| 20 callback.Run(); |
| 21 } |
| 22 } |
| 23 |
| 24 TopLevelDisplayClient::TopLevelDisplayClient( |
| 25 gfx::AcceleratedWidget widget, |
| 26 const scoped_refptr<gles2::GpuState>& gpu_state, |
| 27 const scoped_refptr<SurfacesState>& surfaces_state) |
| 28 : gpu_state_(gpu_state), |
| 29 surfaces_state_(surfaces_state), |
| 30 factory_(surfaces_state->manager(), this), |
| 31 cc_id_(static_cast<uint64_t>(surfaces_state->next_id_namespace()) << 32) { |
| 32 factory_.Create(cc_id_); |
| 33 |
| 34 display_.reset(new cc::Display(this, surfaces_state_->manager(), nullptr, |
| 35 nullptr, cc::RendererSettings())); |
| 36 surfaces_state_->scheduler()->AddDisplay(display_.get()); |
| 37 |
| 38 // TODO(brianderson): Reconcile with SurfacesScheduler crbug.com/476676 |
| 39 cc::DisplayScheduler* null_display_scheduler = nullptr; |
| 40 display_->Initialize( |
| 41 make_scoped_ptr(new surfaces::DirectOutputSurface( |
| 42 new SurfacesContextProvider(this, widget, gpu_state))), |
| 43 null_display_scheduler); |
| 44 |
| 45 display_->Resize(last_submitted_frame_size_); |
| 46 |
| 47 // TODO(fsamuel): Plumb the proper device scale factor. |
| 48 display_->SetSurfaceId(cc_id_, 1.f /* device_scale_factor */); |
| 49 } |
| 50 |
| 51 void TopLevelDisplayClient::OnContextCreated() { |
| 52 } |
| 53 |
| 54 TopLevelDisplayClient::~TopLevelDisplayClient() { |
| 55 if (display_) { |
| 56 factory_.Destroy(cc_id_); |
| 57 surfaces_state_->scheduler()->RemoveDisplay(display_.get()); |
| 58 // By deleting the object after display_ is reset, OutputSurfaceLost can |
| 59 // know not to do anything (which would result in double delete). |
| 60 delete display_.release(); |
| 61 } |
| 62 } |
| 63 |
| 64 void TopLevelDisplayClient::SubmitFrame(mojo::FramePtr frame, |
| 65 const base::Closure& callback) { |
| 66 DCHECK(pending_callback_.is_null()); |
| 67 pending_frame_ = frame.Pass(); |
| 68 pending_callback_ = callback; |
| 69 if (display_) |
| 70 Draw(); |
| 71 } |
| 72 |
| 73 void TopLevelDisplayClient::Draw() { |
| 74 gfx::Size frame_size = |
| 75 pending_frame_->passes[0]->output_rect.To<gfx::Rect>().size(); |
| 76 last_submitted_frame_size_ = frame_size; |
| 77 display_->Resize(frame_size); |
| 78 factory_.SubmitFrame(cc_id_, |
| 79 pending_frame_.To<scoped_ptr<cc::CompositorFrame>>(), |
| 80 base::Bind(&CallCallback, pending_callback_)); |
| 81 pending_frame_.reset(); |
| 82 surfaces_state_->scheduler()->SetNeedsDraw(); |
| 83 pending_callback_.Reset(); |
| 84 } |
| 85 |
| 86 void TopLevelDisplayClient::CommitVSyncParameters(base::TimeTicks timebase, |
| 87 base::TimeDelta interval) { |
| 88 } |
| 89 |
| 90 void TopLevelDisplayClient::OutputSurfaceLost() { |
| 91 if (!display_) // Shutdown case |
| 92 return; |
| 93 |
| 94 // If our OutputSurface is lost we can't draw until we get a new one. For now, |
| 95 // destroy the display and create a new one when our ContextProvider provides |
| 96 // a new one. |
| 97 // TODO: This is more violent than necessary - we could simply remove this |
| 98 // display from the scheduler's set and pass a new context in to the |
| 99 // OutputSurface. It should be able to reinitialize properly. |
| 100 surfaces_state_->scheduler()->RemoveDisplay(display_.get()); |
| 101 display_.reset(); |
| 102 } |
| 103 |
| 104 void TopLevelDisplayClient::SetMemoryPolicy( |
| 105 const cc::ManagedMemoryPolicy& policy) { |
| 106 } |
| 107 |
| 108 void TopLevelDisplayClient::OnVSyncParametersUpdated(int64_t timebase, |
| 109 int64_t interval) { |
| 110 surfaces_state_->scheduler()->OnVSyncParametersUpdated( |
| 111 base::TimeTicks::FromInternalValue(timebase), |
| 112 base::TimeDelta::FromInternalValue(interval)); |
| 113 } |
| 114 |
| 115 void TopLevelDisplayClient::ReturnResources( |
| 116 const cc::ReturnedResourceArray& resources) { |
| 117 // TODO(fsamuel): Implement this. |
| 118 } |
| 119 |
| 120 } // namespace surfaces |
OLD | NEW |