1 // Copyright (c) 2013 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 "cc/output/output_surface.h"
11 #include "base/logging.h"
12 #include "base/string_util.h"
13 #include "base/strings/string_split.h"
14 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3D.h"
15 #include "third_party/khronos/GLES2/gl2.h"
16 #include "third_party/khronos/GLES2/gl2ext.h"
17 #include "ui/gfx/rect.h"
18 #include "ui/gfx/size.h"
26 OutputSurface::OutputSurface(
27 scoped_ptr
<WebKit::WebGraphicsContext3D
> context3d
)
29 context3d_(context3d
.Pass()),
30 has_gl_discard_backbuffer_(false) {
33 OutputSurface::OutputSurface(
34 scoped_ptr
<cc::SoftwareOutputDevice
> software_device
)
36 software_device_(software_device
.Pass()),
37 has_gl_discard_backbuffer_(false) {
40 OutputSurface::OutputSurface(
41 scoped_ptr
<WebKit::WebGraphicsContext3D
> context3d
,
42 scoped_ptr
<cc::SoftwareOutputDevice
> software_device
)
44 context3d_(context3d
.Pass()),
45 software_device_(software_device
.Pass()),
46 has_gl_discard_backbuffer_(false) {
49 OutputSurface::~OutputSurface() {
52 bool OutputSurface::BindToClient(
53 cc::OutputSurfaceClient
* client
) {
58 if (!context3d_
->makeContextCurrent())
61 string extensions_string
= UTF16ToASCII(context3d_
->getString(GL_EXTENSIONS
));
62 vector
<string
> extensions_list
;
63 base::SplitString(extensions_string
, ' ', &extensions_list
);
64 set
<string
> extensions(extensions_list
.begin(), extensions_list
.end());
66 has_gl_discard_backbuffer_
=
67 extensions
.count("GL_CHROMIUM_discard_backbuffer") > 0;
72 void OutputSurface::SendFrameToParentCompositor(CompositorFrame
* frame
) {
76 void OutputSurface::EnsureBackbuffer() {
78 if (has_gl_discard_backbuffer_
)
79 context3d_
->ensureBackbufferCHROMIUM();
82 void OutputSurface::DiscardBackbuffer() {
84 if (has_gl_discard_backbuffer_
)
85 context3d_
->discardBackbufferCHROMIUM();
88 void OutputSurface::Reshape(gfx::Size size
) {
90 context3d_
->reshape(size
.width(), size
.height());
93 void OutputSurface::BindFramebuffer() {
95 context3d_
->bindFramebuffer(GL_FRAMEBUFFER
, 0);
98 void OutputSurface::SwapBuffers(const LatencyInfo
& latency_info
) {
100 // Note that currently this has the same effect as SwapBuffers; we should
101 // consider exposing a different entry point on WebGraphicsContext3D.
102 context3d_
->prepareTexture();
105 void OutputSurface::PostSubBuffer(gfx::Rect rect
,
106 const LatencyInfo
& latency_info
) {
108 context3d_
->postSubBufferCHROMIUM(
109 rect
.x(), rect
.y(), rect
.width(), rect
.height());