| 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/direct_output_surface_ozone.h" |
| 6 |
| 7 #include <utility> |
| 8 |
| 9 #include "base/bind.h" |
| 10 #include "cc/output/compositor_frame.h" |
| 11 #include "cc/output/context_provider.h" |
| 12 #include "cc/output/output_surface_client.h" |
| 13 #include "components/mus/gles2/mojo_gpu_memory_buffer_manager.h" |
| 14 #include "components/mus/surfaces/buffer_queue.h" |
| 15 #include "components/mus/surfaces/surfaces_context_provider.h" |
| 16 #include "gpu/command_buffer/client/context_support.h" |
| 17 #include "gpu/command_buffer/client/gles2_interface.h" |
| 18 |
| 19 namespace mus { |
| 20 |
| 21 DirectOutputSurfaceOzone::DirectOutputSurfaceOzone( |
| 22 const scoped_refptr<SurfacesContextProvider>& context_provider, |
| 23 gfx::AcceleratedWidget widget, |
| 24 uint32_t target, |
| 25 uint32_t internalformat) |
| 26 : cc::OutputSurface(context_provider), |
| 27 output_surface_( |
| 28 new BufferQueue(context_provider, target, internalformat, widget)), |
| 29 weak_ptr_factory_(this) { |
| 30 capabilities_.uses_default_gl_framebuffer = false; |
| 31 capabilities_.flipped_output_surface = true; |
| 32 // Set |max_frames_pending| to 2 for surfaceless, which aligns scheduling |
| 33 // more closely with the previous surfaced behavior. |
| 34 // With a surface, swap buffer ack used to return early, before actually |
| 35 // presenting the back buffer, enabling the browser compositor to run ahead. |
| 36 // Surfaceless implementation acks at the time of actual buffer swap, which |
| 37 // shifts the start of the new frame forward relative to the old |
| 38 // implementation. |
| 39 capabilities_.max_frames_pending = 2; |
| 40 |
| 41 output_surface_->Initialize(); |
| 42 |
| 43 context_provider->SetSwapBuffersCompletionCallback( |
| 44 base::Bind(&DirectOutputSurfaceOzone::OnGpuSwapBuffersCompleted, |
| 45 base::Unretained(this))); |
| 46 } |
| 47 |
| 48 DirectOutputSurfaceOzone::~DirectOutputSurfaceOzone() { |
| 49 // TODO(rjkroege): Support cleanup. |
| 50 } |
| 51 |
| 52 bool DirectOutputSurfaceOzone::IsDisplayedAsOverlayPlane() const { |
| 53 // TODO(rjkroege): implement remaining overlay functionality. |
| 54 return true; |
| 55 } |
| 56 |
| 57 unsigned DirectOutputSurfaceOzone::GetOverlayTextureId() const { |
| 58 DCHECK(output_surface_); |
| 59 return output_surface_->current_texture_id(); |
| 60 } |
| 61 |
| 62 void DirectOutputSurfaceOzone::SwapBuffers(cc::CompositorFrame* frame) { |
| 63 DCHECK(output_surface_); |
| 64 DCHECK(frame->gl_frame_data); |
| 65 |
| 66 output_surface_->SwapBuffers(frame->gl_frame_data->sub_buffer_rect); |
| 67 |
| 68 // Code combining GpuBrowserCompositorOutputSurface + DirectOutputSurface |
| 69 if (frame->gl_frame_data->sub_buffer_rect == |
| 70 gfx::Rect(frame->gl_frame_data->size)) { |
| 71 context_provider_->ContextSupport()->Swap(); |
| 72 } else { |
| 73 context_provider_->ContextSupport()->PartialSwapBuffers( |
| 74 frame->gl_frame_data->sub_buffer_rect); |
| 75 } |
| 76 |
| 77 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); |
| 78 const GLuint64 fence_sync = gl->InsertFenceSyncCHROMIUM(); |
| 79 gl->ShallowFlushCHROMIUM(); |
| 80 |
| 81 gpu::SyncToken sync_token; |
| 82 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, sync_token.GetData()); |
| 83 |
| 84 client_->DidSwapBuffers(); |
| 85 } |
| 86 |
| 87 bool DirectOutputSurfaceOzone::BindToClient(cc::OutputSurfaceClient* client) { |
| 88 if (!cc::OutputSurface::BindToClient(client)) |
| 89 return false; |
| 90 |
| 91 if (capabilities_.uses_default_gl_framebuffer) { |
| 92 capabilities_.flipped_output_surface = |
| 93 context_provider()->ContextCapabilities().gpu.flips_vertically; |
| 94 } |
| 95 return true; |
| 96 } |
| 97 |
| 98 // TODO(rjkroege): Plumb vsync properties. |
| 99 void DirectOutputSurfaceOzone::OnUpdateVSyncParametersFromGpu( |
| 100 base::TimeTicks timebase, |
| 101 base::TimeDelta interval) { |
| 102 DCHECK(HasClient()); |
| 103 CommitVSyncParameters(timebase, interval); |
| 104 // vsync_manager_->UpdateVSyncParameters(timebase, interval); |
| 105 } |
| 106 |
| 107 void DirectOutputSurfaceOzone::OnGpuSwapBuffersCompleted( |
| 108 gfx::SwapResult result) { |
| 109 DCHECK(output_surface_); |
| 110 bool force_swap = false; |
| 111 if (result == gfx::SwapResult::SWAP_NAK_RECREATE_BUFFERS) { |
| 112 // Even through the swap failed, this is a fixable error so we can pretend |
| 113 // it succeeded to the rest of the system. |
| 114 result = gfx::SwapResult::SWAP_ACK; |
| 115 output_surface_->RecreateBuffers(); |
| 116 force_swap = true; |
| 117 } |
| 118 |
| 119 output_surface_->PageFlipComplete(); |
| 120 OnSwapBuffersComplete(); |
| 121 |
| 122 if (force_swap) |
| 123 client_->SetNeedsRedrawRect(gfx::Rect(SurfaceSize())); |
| 124 } |
| 125 |
| 126 void DirectOutputSurfaceOzone::BindFramebuffer() { |
| 127 DCHECK(output_surface_); |
| 128 output_surface_->BindFramebuffer(); |
| 129 } |
| 130 |
| 131 // We call this on every frame but changing the size once we've allocated |
| 132 // backing NativePixmapOzone instances will cause a DCHECK because |
| 133 // Chrome never Reshape(s) after the first one from (0,0). NB: this implies |
| 134 // that screen size changes need to be plumbed differently. In particular, we |
| 135 // must create the native window in the size that the hardware reports. |
| 136 void DirectOutputSurfaceOzone::Reshape(const gfx::Size& size, |
| 137 float scale_factor, |
| 138 bool alpha) { |
| 139 OutputSurface::Reshape(size, scale_factor, alpha); |
| 140 DCHECK(output_surface_); |
| 141 output_surface_->Reshape(SurfaceSize(), scale_factor); |
| 142 } |
| 143 |
| 144 } // namespace mus |
| OLD | NEW |