Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / content / browser / compositor / gpu_surfaceless_browser_compositor_output_surface.cc
blob9507cc31148d7f6d4369d80847bac07250ddaefd
1 // Copyright 2014 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.
5 #include "content/browser/compositor/gpu_surfaceless_browser_compositor_output_surface.h"
7 #include "cc/output/compositor_frame.h"
8 #include "content/browser/compositor/browser_compositor_overlay_candidate_validator.h"
9 #include "content/browser/compositor/buffer_queue.h"
10 #include "content/browser/compositor/reflector_impl.h"
11 #include "content/browser/gpu/gpu_surface_tracker.h"
12 #include "content/common/gpu/client/context_provider_command_buffer.h"
13 #include "content/common/gpu/client/gl_helper.h"
14 #include "gpu/GLES2/gl2extchromium.h"
15 #include "gpu/command_buffer/client/gles2_interface.h"
17 namespace content {
19 GpuSurfacelessBrowserCompositorOutputSurface::
20 GpuSurfacelessBrowserCompositorOutputSurface(
21 const scoped_refptr<ContextProviderCommandBuffer>& context,
22 int surface_id,
23 const scoped_refptr<ui::CompositorVSyncManager>& vsync_manager,
24 scoped_ptr<BrowserCompositorOverlayCandidateValidator>
25 overlay_candidate_validator,
26 unsigned int target,
27 unsigned int internalformat,
28 BrowserGpuMemoryBufferManager* gpu_memory_buffer_manager)
29 : GpuBrowserCompositorOutputSurface(context,
30 vsync_manager,
31 overlay_candidate_validator.Pass()),
32 internalformat_(internalformat),
33 gpu_memory_buffer_manager_(gpu_memory_buffer_manager) {
34 capabilities_.uses_default_gl_framebuffer = false;
35 capabilities_.flipped_output_surface = true;
36 // Set |max_frames_pending| to 2 for surfaceless, which aligns scheduling
37 // more closely with the previous surfaced behavior.
38 // With a surface, swap buffer ack used to return early, before actually
39 // presenting the back buffer, enabling the browser compositor to run ahead.
40 // Surfaceless implementation acks at the time of actual buffer swap, which
41 // shifts the start of the new frame forward relative to the old
42 // implementation.
43 capabilities_.max_frames_pending = 2;
45 gl_helper_.reset(new GLHelper(context_provider_->ContextGL(),
46 context_provider_->ContextSupport()));
47 output_surface_.reset(new BufferQueue(
48 context_provider_, target, internalformat_, gl_helper_.get(),
49 gpu_memory_buffer_manager_, surface_id));
50 output_surface_->Initialize();
53 GpuSurfacelessBrowserCompositorOutputSurface::
54 ~GpuSurfacelessBrowserCompositorOutputSurface() {
57 void GpuSurfacelessBrowserCompositorOutputSurface::SwapBuffers(
58 cc::CompositorFrame* frame) {
59 DCHECK(output_surface_);
61 GLuint texture = output_surface_->current_texture_id();
62 output_surface_->SwapBuffers(frame->gl_frame_data->sub_buffer_rect);
63 const gfx::Size& size = frame->gl_frame_data->size;
64 context_provider_->ContextGL()->ScheduleOverlayPlaneCHROMIUM(
66 GL_OVERLAY_TRANSFORM_NONE_CHROMIUM,
67 texture,
70 size.width(),
71 size.height(),
74 1.0f,
75 1.0f);
76 GpuBrowserCompositorOutputSurface::SwapBuffers(frame);
79 void GpuSurfacelessBrowserCompositorOutputSurface::OnSwapBuffersComplete() {
80 DCHECK(output_surface_);
81 output_surface_->PageFlipComplete();
82 GpuBrowserCompositorOutputSurface::OnSwapBuffersComplete();
85 void GpuSurfacelessBrowserCompositorOutputSurface::BindFramebuffer() {
86 DCHECK(output_surface_);
87 output_surface_->BindFramebuffer();
90 void GpuSurfacelessBrowserCompositorOutputSurface::Reshape(
91 const gfx::Size& size,
92 float scale_factor) {
93 GpuBrowserCompositorOutputSurface::Reshape(size, scale_factor);
94 DCHECK(output_surface_);
95 output_surface_->Reshape(SurfaceSize(), scale_factor);
98 void GpuSurfacelessBrowserCompositorOutputSurface::OnSwapBuffersCompleted(
99 const std::vector<ui::LatencyInfo>& latency_info,
100 gfx::SwapResult result) {
101 if (result == gfx::SwapResult::SWAP_NAK_RECREATE_BUFFERS) {
102 // Even through the swap failed, this is a fixable error so we can pretend
103 // it succeeded to the rest of the system.
104 result = gfx::SwapResult::SWAP_ACK;
105 output_surface_->RecreateBuffers();
107 GpuBrowserCompositorOutputSurface::OnSwapBuffersCompleted(latency_info,
108 result);
111 #if defined(OS_MACOSX)
112 void GpuSurfacelessBrowserCompositorOutputSurface::OnSurfaceDisplayed() {
113 OnSwapBuffersComplete();
115 #endif
117 } // namespace content