Update broken references to image assets
[chromium-blink-merge.git] / content / browser / compositor / gpu_surfaceless_browser_compositor_output_surface.cc
blob60dc77852cb16fc7ff95be2732b6d6102431fcfd
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 const scoped_refptr<ContextProviderCommandBuffer>& worker_context,
23 int surface_id,
24 const scoped_refptr<ui::CompositorVSyncManager>& vsync_manager,
25 scoped_ptr<BrowserCompositorOverlayCandidateValidator>
26 overlay_candidate_validator,
27 unsigned int target,
28 unsigned int internalformat,
29 BrowserGpuMemoryBufferManager* gpu_memory_buffer_manager)
30 : GpuBrowserCompositorOutputSurface(context,
31 worker_context,
32 vsync_manager,
33 overlay_candidate_validator.Pass()),
34 internalformat_(internalformat),
35 gpu_memory_buffer_manager_(gpu_memory_buffer_manager) {
36 capabilities_.uses_default_gl_framebuffer = false;
37 capabilities_.flipped_output_surface = true;
38 // Set |max_frames_pending| to 2 for surfaceless, which aligns scheduling
39 // more closely with the previous surfaced behavior.
40 // With a surface, swap buffer ack used to return early, before actually
41 // presenting the back buffer, enabling the browser compositor to run ahead.
42 // Surfaceless implementation acks at the time of actual buffer swap, which
43 // shifts the start of the new frame forward relative to the old
44 // implementation.
45 capabilities_.max_frames_pending = 2;
47 gl_helper_.reset(new GLHelper(context_provider_->ContextGL(),
48 context_provider_->ContextSupport()));
49 output_surface_.reset(new BufferQueue(
50 context_provider_, target, internalformat_, gl_helper_.get(),
51 gpu_memory_buffer_manager_, surface_id));
52 output_surface_->Initialize();
55 GpuSurfacelessBrowserCompositorOutputSurface::
56 ~GpuSurfacelessBrowserCompositorOutputSurface() {
59 void GpuSurfacelessBrowserCompositorOutputSurface::SwapBuffers(
60 cc::CompositorFrame* frame) {
61 DCHECK(output_surface_);
63 GLuint texture = output_surface_->current_texture_id();
64 output_surface_->SwapBuffers(frame->gl_frame_data->sub_buffer_rect);
65 const gfx::Size& size = frame->gl_frame_data->size;
66 context_provider_->ContextGL()->ScheduleOverlayPlaneCHROMIUM(
68 GL_OVERLAY_TRANSFORM_NONE_CHROMIUM,
69 texture,
72 size.width(),
73 size.height(),
76 1.0f,
77 1.0f);
78 GpuBrowserCompositorOutputSurface::SwapBuffers(frame);
81 void GpuSurfacelessBrowserCompositorOutputSurface::OnSwapBuffersComplete() {
82 DCHECK(output_surface_);
83 output_surface_->PageFlipComplete();
84 GpuBrowserCompositorOutputSurface::OnSwapBuffersComplete();
87 void GpuSurfacelessBrowserCompositorOutputSurface::BindFramebuffer() {
88 DCHECK(output_surface_);
89 output_surface_->BindFramebuffer();
92 void GpuSurfacelessBrowserCompositorOutputSurface::Reshape(
93 const gfx::Size& size,
94 float scale_factor) {
95 GpuBrowserCompositorOutputSurface::Reshape(size, scale_factor);
96 DCHECK(output_surface_);
97 output_surface_->Reshape(SurfaceSize(), scale_factor);
100 void GpuSurfacelessBrowserCompositorOutputSurface::OnSwapBuffersCompleted(
101 const std::vector<ui::LatencyInfo>& latency_info,
102 gfx::SwapResult result) {
103 #if defined(OS_MACOSX)
104 NOTREACHED();
105 #else
106 if (result == gfx::SwapResult::SWAP_NAK_RECREATE_BUFFERS) {
107 // Even through the swap failed, this is a fixable error so we can pretend
108 // it succeeded to the rest of the system.
109 result = gfx::SwapResult::SWAP_ACK;
110 output_surface_->RecreateBuffers();
112 GpuBrowserCompositorOutputSurface::OnSwapBuffersCompleted(latency_info,
113 result);
114 #endif
117 #if defined(OS_MACOSX)
118 void GpuSurfacelessBrowserCompositorOutputSurface::OnSurfaceDisplayed() {
119 OnSwapBuffersComplete();
121 #endif
123 } // namespace content