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/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 // Code only from DirectOutputSurface | |
| 78 // Do we need this? What does it do? | |
| 79 // TODO(rjk): figure out if I need it (or maybe it comes along from Swap() | |
| 80 // above | |
| 81 // in the GpuBrowserCompositorOutputSurface context. | |
|
Fady Samuel
2016/04/12 02:54:41
nit: Better wrapping please?
rjkroege
2016/04/12 19:27:54
Done.
| |
| 82 gpu::gles2::GLES2Interface* gl = context_provider_->ContextGL(); | |
| 83 const GLuint64 fence_sync = gl->InsertFenceSyncCHROMIUM(); | |
| 84 gl->ShallowFlushCHROMIUM(); | |
| 85 | |
| 86 gpu::SyncToken sync_token; | |
| 87 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, sync_token.GetData()); | |
| 88 | |
| 89 client_->DidSwapBuffers(); | |
| 90 } | |
| 91 | |
| 92 bool DirectOutputSurfaceOzone::BindToClient(cc::OutputSurfaceClient* client) { | |
| 93 if (!cc::OutputSurface::BindToClient(client)) | |
| 94 return false; | |
| 95 | |
| 96 if (capabilities_.uses_default_gl_framebuffer) { | |
| 97 capabilities_.flipped_output_surface = | |
| 98 context_provider()->ContextCapabilities().gpu.flips_vertically; | |
| 99 } | |
| 100 return true; | |
| 101 } | |
| 102 | |
| 103 // TODO(rjkroege): Plumb vsync properties. | |
| 104 void DirectOutputSurfaceOzone::OnUpdateVSyncParametersFromGpu( | |
| 105 base::TimeTicks timebase, | |
| 106 base::TimeDelta interval) { | |
| 107 DCHECK(HasClient()); | |
| 108 CommitVSyncParameters(timebase, interval); | |
| 109 // vsync_manager_->UpdateVSyncParameters(timebase, interval); | |
| 110 } | |
| 111 | |
| 112 void DirectOutputSurfaceOzone::OnGpuSwapBuffersCompleted( | |
| 113 gfx::SwapResult result) { | |
| 114 DCHECK(output_surface_); | |
| 115 bool force_swap = false; | |
| 116 if (result == gfx::SwapResult::SWAP_NAK_RECREATE_BUFFERS) { | |
| 117 // Even through the swap failed, this is a fixable error so we can pretend | |
| 118 // it succeeded to the rest of the system. | |
| 119 result = gfx::SwapResult::SWAP_ACK; | |
| 120 output_surface_->RecreateBuffers(); | |
| 121 force_swap = true; | |
| 122 } | |
| 123 | |
| 124 output_surface_->PageFlipComplete(); | |
| 125 OnSwapBuffersComplete(); | |
| 126 | |
| 127 if (force_swap) | |
| 128 client_->SetNeedsRedrawRect(gfx::Rect(SurfaceSize())); | |
| 129 } | |
| 130 | |
| 131 void DirectOutputSurfaceOzone::BindFramebuffer() { | |
| 132 DCHECK(output_surface_); | |
| 133 output_surface_->BindFramebuffer(); | |
| 134 } | |
| 135 | |
| 136 // We call this on every frame but changing the size once we've allocated | |
| 137 // backing NativePixmapOzone instances will cause a DCHECK because | |
| 138 // Chrome never Reshape(s) after the first one from (0,0). NB: this implies | |
| 139 // that screen size changes need to be plumbed differently. In particular, we | |
| 140 // must create the native window in the size that the hardware reports. | |
| 141 void DirectOutputSurfaceOzone::Reshape(const gfx::Size& size, | |
| 142 float scale_factor, | |
| 143 bool alpha) { | |
| 144 OutputSurface::Reshape(size, scale_factor, alpha); | |
| 145 DCHECK(output_surface_); | |
| 146 output_surface_->Reshape(SurfaceSize(), scale_factor); | |
| 147 } | |
| 148 | |
| 149 } // namespace mus | |
| OLD | NEW |