OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/output_surface.h" | 5 #include "cc/output_surface.h" |
6 | 6 |
| 7 #include <set> |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
7 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/string_split.h" |
| 13 #include "base/string_util.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; |
8 | 23 |
9 namespace cc { | 24 namespace cc { |
10 | 25 |
11 OutputSurface::OutputSurface( | 26 OutputSurface::OutputSurface( |
12 scoped_ptr<WebKit::WebGraphicsContext3D> context3d) | 27 scoped_ptr<WebKit::WebGraphicsContext3D> context3d) |
13 : client_(NULL), | 28 : client_(NULL), |
14 context3d_(context3d.Pass()) { | 29 context3d_(context3d.Pass()), |
| 30 has_gl_discard_backbuffer_(false) { |
15 } | 31 } |
16 | 32 |
17 OutputSurface::OutputSurface( | 33 OutputSurface::OutputSurface( |
18 scoped_ptr<cc::SoftwareOutputDevice> software_device) | 34 scoped_ptr<cc::SoftwareOutputDevice> software_device) |
19 : client_(NULL), | 35 : client_(NULL), |
20 software_device_(software_device.Pass()) { | 36 software_device_(software_device.Pass()), |
| 37 has_gl_discard_backbuffer_(false) { |
21 } | 38 } |
22 | 39 |
23 OutputSurface::OutputSurface( | 40 OutputSurface::OutputSurface( |
24 scoped_ptr<WebKit::WebGraphicsContext3D> context3d, | 41 scoped_ptr<WebKit::WebGraphicsContext3D> context3d, |
25 scoped_ptr<cc::SoftwareOutputDevice> software_device) | 42 scoped_ptr<cc::SoftwareOutputDevice> software_device) |
26 : client_(NULL), | 43 : client_(NULL), |
27 context3d_(context3d.Pass()), | 44 context3d_(context3d.Pass()), |
28 software_device_(software_device.Pass()) { | 45 software_device_(software_device.Pass()), |
| 46 has_gl_discard_backbuffer_(false) { |
29 } | 47 } |
30 | 48 |
31 OutputSurface::~OutputSurface() { | 49 OutputSurface::~OutputSurface() { |
32 } | 50 } |
33 | 51 |
34 bool OutputSurface::BindToClient( | 52 bool OutputSurface::BindToClient( |
35 cc::OutputSurfaceClient* client) { | 53 cc::OutputSurfaceClient* client) { |
36 DCHECK(client); | 54 DCHECK(client); |
37 client_ = client; | 55 client_ = client; |
38 if (!context3d_) | 56 if (!context3d_) |
39 return true; | 57 return true; |
40 return context3d_->makeContextCurrent(); | 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; |
41 } | 70 } |
42 | 71 |
43 void OutputSurface::SendFrameToParentCompositor(CompositorFrame*) { | 72 void OutputSurface::SendFrameToParentCompositor(CompositorFrame*) { |
44 NOTIMPLEMENTED(); | 73 NOTIMPLEMENTED(); |
45 } | 74 } |
46 | 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 |
47 } // namespace cc | 111 } // namespace cc |
OLD | NEW |