Fix build break
[chromium-blink-merge.git] / cc / output / output_surface.cc
blob416440283d4bdfca847494ea0ca9e5c3b6f6d44d
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"
7 #include <set>
8 #include <string>
9 #include <vector>
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"
20 using std::set;
21 using std::string;
22 using std::vector;
24 namespace cc {
26 OutputSurface::OutputSurface(
27 scoped_ptr<WebKit::WebGraphicsContext3D> context3d)
28 : client_(NULL),
29 context3d_(context3d.Pass()),
30 has_gl_discard_backbuffer_(false) {
33 OutputSurface::OutputSurface(
34 scoped_ptr<cc::SoftwareOutputDevice> software_device)
35 : client_(NULL),
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)
43 : client_(NULL),
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) {
54 DCHECK(client);
55 client_ = client;
56 if (!context3d_)
57 return true;
58 if (!context3d_->makeContextCurrent())
59 return false;
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;
69 return true;
72 void OutputSurface::SendFrameToParentCompositor(CompositorFrame* frame) {
73 NOTIMPLEMENTED();
76 void OutputSurface::EnsureBackbuffer() {
77 DCHECK(context3d_);
78 if (has_gl_discard_backbuffer_)
79 context3d_->ensureBackbufferCHROMIUM();
82 void OutputSurface::DiscardBackbuffer() {
83 DCHECK(context3d_);
84 if (has_gl_discard_backbuffer_)
85 context3d_->discardBackbufferCHROMIUM();
88 void OutputSurface::Reshape(gfx::Size size) {
89 DCHECK(context3d_);
90 context3d_->reshape(size.width(), size.height());
93 void OutputSurface::BindFramebuffer() {
94 DCHECK(context3d_);
95 context3d_->bindFramebuffer(GL_FRAMEBUFFER, 0);
98 void OutputSurface::SwapBuffers(const LatencyInfo& latency_info) {
99 DCHECK(context3d_);
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) {
107 DCHECK(context3d_);
108 context3d_->postSubBufferCHROMIUM(
109 rect.x(), rect.y(), rect.width(), rect.height());
112 } // namespace cc