| 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 display_->SetVisible(true); | |
| 58 return true; | |
| 59 } | |
| 60 | |
| 61 void BlimpDelegatingOutputSurface::DetachFromClient() { | |
| 62 if (!delegated_surface_id_.is_null()) | |
| 63 surface_factory_->Destroy(delegated_surface_id_); | |
| 64 surface_manager_->UnregisterSurfaceFactoryClient( | |
| 65 surface_id_allocator_->client_id()); | |
| 66 surface_manager_->InvalidateSurfaceClientId( | |
| 67 surface_id_allocator_->client_id()); | |
| 68 display_ = nullptr; | |
| 69 surface_factory_ = nullptr; | |
| 70 surface_id_allocator_ = nullptr; | |
| 71 surface_manager_ = nullptr; | |
| 72 cc::OutputSurface::DetachFromClient(); | |
| 73 } | |
| 74 | |
| 75 void BlimpDelegatingOutputSurface::SwapBuffers(cc::CompositorFrame frame) { | |
| 76 if (delegated_surface_id_.is_null()) { | |
| 77 delegated_surface_id_ = surface_id_allocator_->GenerateId(); | |
| 78 surface_factory_->Create(delegated_surface_id_); | |
| 79 } | |
| 80 display_->SetSurfaceId(delegated_surface_id_, | |
| 81 frame.metadata.device_scale_factor); | |
| 82 | |
| 83 gfx::Size frame_size = | |
| 84 frame.delegated_frame_data->render_pass_list.back()->output_rect.size(); | |
| 85 display_->Resize(frame_size); | |
| 86 | |
| 87 surface_factory_->SubmitCompositorFrame(delegated_surface_id_, | |
| 88 std::move(frame), base::Closure()); | |
| 89 cc::OutputSurface::PostSwapBuffersComplete(); | |
| 90 } | |
| 91 | |
| 92 void BlimpDelegatingOutputSurface::ForceReclaimResources() {} | |
| 93 | |
| 94 void BlimpDelegatingOutputSurface::BindFramebuffer() { | |
| 95 // This is a delegating output surface, no framebuffer/direct drawing support. | |
| 96 NOTREACHED(); | |
| 97 } | |
| 98 | |
| 99 uint32_t BlimpDelegatingOutputSurface::GetFramebufferCopyTextureFormat() { | |
| 100 // This is a delegating output surface, no framebuffer/direct drawing support. | |
| 101 NOTREACHED(); | |
| 102 return 0; | |
| 103 } | |
| 104 | |
| 105 void BlimpDelegatingOutputSurface::ReturnResources( | |
| 106 const cc::ReturnedResourceArray& resources) { | |
| 107 client_->ReclaimResources(resources); | |
| 108 } | |
| 109 | |
| 110 void BlimpDelegatingOutputSurface::SetBeginFrameSource( | |
| 111 cc::BeginFrameSource* begin_frame_source) { | |
| 112 client_->SetBeginFrameSource(begin_frame_source); | |
| 113 } | |
| 114 | |
| 115 void BlimpDelegatingOutputSurface::DisplayOutputSurfaceLost() { | |
| 116 DidLoseOutputSurface(); | |
| 117 } | |
| 118 | |
| 119 void BlimpDelegatingOutputSurface::DisplaySetMemoryPolicy( | |
| 120 const cc::ManagedMemoryPolicy& policy) { | |
| 121 SetMemoryPolicy(policy); | |
| 122 } | |
| 123 | |
| 124 void BlimpDelegatingOutputSurface::DisplayWillDrawAndSwap( | |
| 125 bool will_draw_and_swap, | |
| 126 const cc::RenderPassList& render_passes) {} | |
| 127 | |
| 128 void BlimpDelegatingOutputSurface::DisplayDidDrawAndSwap() {} | |
| 129 | |
| 130 } // namespace client | |
| 131 } // namespace blimp | |
| OLD | NEW |