OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "cc/output_surface.h" | |
6 | |
7 #include <set> | |
8 #include <string> | |
9 #include <vector> | |
10 | |
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/WebGraphicsContext3
D.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" | |
19 | |
20 using std::set; | |
21 using std::string; | |
22 using std::vector; | |
23 | |
24 namespace cc { | |
25 | |
26 OutputSurface::OutputSurface( | |
27 scoped_ptr<WebKit::WebGraphicsContext3D> context3d) | |
28 : client_(NULL), | |
29 context3d_(context3d.Pass()), | |
30 has_gl_discard_backbuffer_(false) { | |
31 } | |
32 | |
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) { | |
38 } | |
39 | |
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) { | |
47 } | |
48 | |
49 OutputSurface::~OutputSurface() { | |
50 } | |
51 | |
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; | |
60 | |
61 string extensionsString = UTF16ToASCII(context3d_->getString(GL_EXTENSIONS)); | |
62 vector<string> extensionsList; | |
63 base::SplitString(extensionsString, ' ', &extensionsList); | |
64 set<string> extensions(extensionsList.begin(), extensionsList.end()); | |
65 | |
66 has_gl_discard_backbuffer_ = | |
67 extensions.count("GL_CHROMIUM_discard_backbuffer"); | |
68 | |
69 return true; | |
70 } | |
71 | |
72 void OutputSurface::SendFrameToParentCompositor(CompositorFrame*) { | |
73 NOTIMPLEMENTED(); | |
74 } | |
75 | |
76 void OutputSurface::EnsureBackbuffer() { | |
77 DCHECK(context3d_); | |
78 if (has_gl_discard_backbuffer_) | |
79 context3d_->ensureBackbufferCHROMIUM(); | |
80 } | |
81 | |
82 void OutputSurface::DiscardBackbuffer() { | |
83 DCHECK(context3d_); | |
84 if (has_gl_discard_backbuffer_) | |
85 context3d_->discardBackbufferCHROMIUM(); | |
86 } | |
87 | |
88 void OutputSurface::Reshape(gfx::Size size) { | |
89 DCHECK(context3d_); | |
90 context3d_->reshape(size.width(), size.height()); | |
91 } | |
92 | |
93 void OutputSurface::BindFramebuffer() { | |
94 DCHECK(context3d_); | |
95 context3d_->bindFramebuffer(GL_FRAMEBUFFER, 0); | |
96 } | |
97 | |
98 void OutputSurface::SwapBuffers() { | |
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(); | |
103 } | |
104 | |
105 void OutputSurface::PostSubBuffer(gfx::Rect rect) { | |
106 DCHECK(context3d_); | |
107 context3d_->postSubBufferCHROMIUM( | |
108 rect.x(), rect.y(), rect.width(), rect.height()); | |
109 } | |
110 | |
111 } // namespace cc | |
OLD | NEW |