Chromium Code Reviews| 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 "components/mus/surfaces/display_compositor.h" | |
| 6 | |
| 7 #include "cc/output/copy_output_request.h" | |
| 8 #include "cc/output/output_surface.h" | |
| 9 #include "cc/output/renderer_settings.h" | |
| 10 #include "cc/surfaces/display.h" | |
| 11 #include "components/mus/surfaces/direct_output_surface.h" | |
| 12 #include "components/mus/surfaces/surfaces_context_provider.h" | |
| 13 #include "components/mus/surfaces/top_level_display_client.h" | |
| 14 | |
| 15 #if defined(USE_OZONE) | |
| 16 #include "components/mus/surfaces/direct_output_surface_ozone.h" | |
| 17 #include "gpu/command_buffer/client/gles2_interface.h" | |
| 18 #endif | |
| 19 | |
| 20 namespace mus { | |
| 21 | |
| 22 namespace { | |
| 23 | |
| 24 void CallCallback(const base::Closure& callback, cc::SurfaceDrawStatus status) { | |
| 25 callback.Run(); | |
| 26 } | |
| 27 | |
| 28 } // namespace | |
| 29 | |
| 30 DisplayCompositor::DisplayCompositor( | |
| 31 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | |
| 32 gfx::AcceleratedWidget widget, | |
| 33 const scoped_refptr<GpuState>& gpu_state, | |
| 34 const scoped_refptr<SurfacesState>& surfaces_state) | |
| 35 : task_runner_(task_runner), | |
| 36 surfaces_state_(surfaces_state), | |
| 37 factory_(surfaces_state->manager(), this), | |
| 38 allocator_(surfaces_state->next_id_namespace()) { | |
| 39 surfaces_state_->manager()->RegisterSurfaceFactoryClient( | |
| 40 allocator_.id_namespace(), this); | |
| 41 | |
| 42 scoped_refptr<SurfacesContextProvider> surfaces_context_provider( | |
| 43 new SurfacesContextProvider(widget, gpu_state)); | |
| 44 // TODO(rjkroege): If there is something better to do than CHECK, add it. | |
| 45 CHECK(surfaces_context_provider->BindToCurrentThread()); | |
| 46 | |
| 47 std::unique_ptr<cc::OutputSurface> output_surface; | |
| 48 if (surfaces_context_provider->ContextCapabilities().surfaceless) { | |
| 49 #if defined(USE_OZONE) | |
| 50 output_surface = base::WrapUnique(new DirectOutputSurfaceOzone( | |
| 51 surfaces_context_provider, widget, task_runner_.get(), GL_TEXTURE_2D, | |
| 52 GL_RGB)); | |
| 53 #else | |
| 54 NOTREACHED(); | |
| 55 #endif | |
| 56 } else { | |
| 57 output_surface = base::WrapUnique( | |
| 58 new DirectOutputSurface(surfaces_context_provider, task_runner_.get())); | |
| 59 } | |
| 60 | |
| 61 int max_frames_pending = output_surface->capabilities().max_frames_pending; | |
| 62 DCHECK_GT(max_frames_pending, 0); | |
| 63 | |
| 64 display_client_.reset(new TopLevelDisplayClient( | |
| 65 std::move(output_surface), surfaces_state_->manager(), | |
| 66 nullptr /* bitmap_manager */, nullptr /* gpu_memory_buffer_manager */, | |
| 67 cc::RendererSettings(), task_runner_, allocator_.id_namespace())); | |
| 68 | |
| 69 display_client_->Initialize(); | |
| 70 } | |
| 71 | |
| 72 DisplayCompositor::~DisplayCompositor() { | |
| 73 surfaces_state_->manager()->UnregisterSurfaceFactoryClient( | |
| 74 allocator_.id_namespace()); | |
| 75 } | |
| 76 | |
| 77 void DisplayCompositor::SubmitCompositorFrame( | |
| 78 std::unique_ptr<cc::CompositorFrame> frame, | |
| 79 const base::Closure& callback) { | |
| 80 gfx::Size frame_size = | |
| 81 frame->delegated_frame_data->render_pass_list.back()->output_rect.size(); | |
| 82 if (frame_size.IsEmpty() || frame_size != display_size_) { | |
| 83 if (!surface_id_.is_null()) | |
| 84 factory_.Destroy(surface_id_); | |
| 85 surface_id_ = allocator_.GenerateId(); | |
| 86 factory_.Create(surface_id_); | |
| 87 display_size_ = frame_size; | |
| 88 display_client_->display()->Resize(display_size_); | |
| 89 } | |
| 90 display_client_->display()->SetSurfaceId(surface_id_, | |
| 91 frame->metadata.device_scale_factor); | |
| 92 factory_.SubmitCompositorFrame(surface_id_, std::move(frame), | |
|
rjkroege
2016/05/12 23:26:36
why do you need to wrap the Callback?
Fady Samuel
2016/05/13 18:43:41
Removed.
| |
| 93 base::Bind(&CallCallback, callback)); | |
| 94 } | |
| 95 | |
| 96 void DisplayCompositor::RequestCopyOfOutput( | |
| 97 std::unique_ptr<cc::CopyOutputRequest> output_request) { | |
| 98 factory_.RequestCopyOfSurface(surface_id_, std::move(output_request)); | |
| 99 } | |
| 100 | |
| 101 void DisplayCompositor::ReturnResources( | |
| 102 const cc::ReturnedResourceArray& resources) { | |
| 103 // TODO(fsamuel): Implement this. | |
| 104 } | |
| 105 | |
| 106 void DisplayCompositor::SetBeginFrameSource( | |
| 107 cc::BeginFrameSource* begin_frame_source) { | |
| 108 // TODO(fsamuel): Implement this. | |
| 109 } | |
| 110 | |
| 111 } // namespace mus | |
| OLD | NEW |