| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 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 "blimp/client/feature/compositor/blimp_delegating_output_surface.h" |
| 6 |
| 7 #include <stdint.h> |
| 8 #include <utility> |
| 9 |
| 10 #include "cc/output/texture_mailbox_deleter.h" |
| 11 |
| 12 static constexpr uint32_t kCompositorClientId = 1; |
| 13 |
| 14 namespace blimp { |
| 15 namespace client { |
| 16 |
| 17 BlimpDelegatingOutputSurface::BlimpDelegatingOutputSurface( |
| 18 scoped_refptr<cc::ContextProvider> compositor_context_provider, |
| 19 scoped_refptr<cc::ContextProvider> worker_context_provider, |
| 20 std::unique_ptr<cc::OutputSurface> display_output_surface, |
| 21 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
| 22 const cc::RendererSettings& renderer_settings, |
| 23 base::SingleThreadTaskRunner* task_runner) |
| 24 : cc::OutputSurface(std::move(compositor_context_provider), |
| 25 std::move(worker_context_provider), |
| 26 nullptr), |
| 27 surface_manager_(new cc::SurfaceManager), |
| 28 surface_id_allocator_(new cc::SurfaceIdAllocator(kCompositorClientId)), |
| 29 surface_factory_(new cc::SurfaceFactory(surface_manager_.get(), this)) { |
| 30 std::unique_ptr<cc::SyntheticBeginFrameSource> begin_frame_source( |
| 31 new cc::DelayBasedBeginFrameSource( |
| 32 base::MakeUnique<cc::DelayBasedTimeSource>(task_runner))); |
| 33 std::unique_ptr<cc::DisplayScheduler> scheduler(new cc::DisplayScheduler( |
| 34 begin_frame_source.get(), task_runner, |
| 35 display_output_surface->capabilities().max_frames_pending)); |
| 36 display_.reset(new cc::Display( |
| 37 nullptr /*shared_bitmap_manager*/, gpu_memory_buffer_manager, |
| 38 renderer_settings, std::move(begin_frame_source), |
| 39 std::move(display_output_surface), std::move(scheduler), |
| 40 base::MakeUnique<cc::TextureMailboxDeleter>(task_runner))); |
| 41 |
| 42 capabilities_.delegated_rendering = true; |
| 43 } |
| 44 |
| 45 BlimpDelegatingOutputSurface::~BlimpDelegatingOutputSurface() = default; |
| 46 |
| 47 bool BlimpDelegatingOutputSurface::BindToClient( |
| 48 cc::OutputSurfaceClient* client) { |
| 49 bool bound = cc::OutputSurface::BindToClient(client); |
| 50 DCHECK(bound); // No support for failing to set up the context. |
| 51 |
| 52 surface_manager_->RegisterSurfaceClientId(surface_id_allocator_->client_id()); |
| 53 surface_manager_->RegisterSurfaceFactoryClient( |
| 54 surface_id_allocator_->client_id(), this); |
| 55 display_->Initialize(this, surface_manager_.get(), |
| 56 surface_id_allocator_->client_id()); |
| 57 // TODO(danakj): Do this when https://codereview.chromium.org/2238693002/ . |
| 58 // display_->SetVisible(true); |
| 59 return true; |
| 60 } |
| 61 |
| 62 void BlimpDelegatingOutputSurface::DetachFromClient() { |
| 63 if (!delegated_surface_id_.is_null()) |
| 64 surface_factory_->Destroy(delegated_surface_id_); |
| 65 surface_manager_->UnregisterSurfaceFactoryClient( |
| 66 surface_id_allocator_->client_id()); |
| 67 surface_manager_->InvalidateSurfaceClientId( |
| 68 surface_id_allocator_->client_id()); |
| 69 display_ = nullptr; |
| 70 surface_factory_ = nullptr; |
| 71 surface_id_allocator_ = nullptr; |
| 72 surface_manager_ = nullptr; |
| 73 cc::OutputSurface::DetachFromClient(); |
| 74 } |
| 75 |
| 76 void BlimpDelegatingOutputSurface::SwapBuffers(cc::CompositorFrame frame) { |
| 77 if (delegated_surface_id_.is_null()) { |
| 78 delegated_surface_id_ = surface_id_allocator_->GenerateId(); |
| 79 surface_factory_->Create(delegated_surface_id_); |
| 80 } |
| 81 display_->SetSurfaceId(delegated_surface_id_, |
| 82 frame.metadata.device_scale_factor); |
| 83 |
| 84 gfx::Size frame_size = |
| 85 frame.delegated_frame_data->render_pass_list.back()->output_rect.size(); |
| 86 display_->Resize(frame_size); |
| 87 |
| 88 surface_factory_->SubmitCompositorFrame(delegated_surface_id_, |
| 89 std::move(frame), base::Closure()); |
| 90 cc::OutputSurface::PostSwapBuffersComplete(); |
| 91 } |
| 92 |
| 93 void BlimpDelegatingOutputSurface::ForceReclaimResources() {} |
| 94 |
| 95 void BlimpDelegatingOutputSurface::BindFramebuffer() { |
| 96 // This is a delegating output surface, no framebuffer/direct drawing support. |
| 97 NOTREACHED(); |
| 98 } |
| 99 |
| 100 uint32_t BlimpDelegatingOutputSurface::GetFramebufferCopyTextureFormat() { |
| 101 // This is a delegating output surface, no framebuffer/direct drawing support. |
| 102 NOTREACHED(); |
| 103 return 0; |
| 104 } |
| 105 |
| 106 void BlimpDelegatingOutputSurface::ReturnResources( |
| 107 const cc::ReturnedResourceArray& resources) { |
| 108 client_->ReclaimResources(resources); |
| 109 } |
| 110 |
| 111 void BlimpDelegatingOutputSurface::SetBeginFrameSource( |
| 112 cc::BeginFrameSource* begin_frame_source) { |
| 113 client_->SetBeginFrameSource(begin_frame_source); |
| 114 } |
| 115 |
| 116 void BlimpDelegatingOutputSurface::DisplayOutputSurfaceLost() { |
| 117 DidLoseOutputSurface(); |
| 118 } |
| 119 |
| 120 void BlimpDelegatingOutputSurface::DisplaySetMemoryPolicy( |
| 121 const cc::ManagedMemoryPolicy& policy) { |
| 122 SetMemoryPolicy(policy); |
| 123 } |
| 124 |
| 125 void BlimpDelegatingOutputSurface::DisplayWillDrawAndSwap( |
| 126 bool will_draw_and_swap, |
| 127 const cc::RenderPassList& render_passes) {} |
| 128 |
| 129 void BlimpDelegatingOutputSurface::DisplayDidDrawAndSwap() {} |
| 130 |
| 131 } // namespace client |
| 132 } // namespace blimp |
| OLD | NEW |