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> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
13 #include "base/strings/string_split.h" | 13 #include "base/strings/string_split.h" |
| 14 #include "cc/output_surface_client.h" |
14 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3
D.h" | 15 #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/gl2.h" |
16 #include "third_party/khronos/GLES2/gl2ext.h" | 17 #include "third_party/khronos/GLES2/gl2ext.h" |
17 #include "ui/gfx/rect.h" | 18 #include "ui/gfx/rect.h" |
18 #include "ui/gfx/size.h" | 19 #include "ui/gfx/size.h" |
19 | 20 |
20 using std::set; | 21 using std::set; |
21 using std::string; | 22 using std::string; |
22 using std::vector; | 23 using std::vector; |
23 | 24 |
24 namespace cc { | 25 namespace cc { |
25 | 26 |
| 27 class OutputSurfaceCallbacks : |
| 28 public WebKit::WebGraphicsContext3D::WebGraphicsSwapBuffersCompleteCallbackCHR
OMIUM, |
| 29 public WebKit::WebGraphicsContext3D::WebGraphicsContextLostCallback { |
| 30 public: |
| 31 explicit OutputSurfaceCallbacks(OutputSurfaceClient* client) |
| 32 : client_(client) {} |
| 33 |
| 34 // WK:WGC3D::WGSwapBuffersCompleteCallbackCHROMIUM implementation. |
| 35 virtual void onSwapBuffersComplete() { |
| 36 client_->OnSwapBuffersComplete(); |
| 37 } |
| 38 |
| 39 // WK:WGC3D::WGContextLostCallback implementation. |
| 40 virtual void onContextLost() { |
| 41 client_->DidLoseOutputSurface(); |
| 42 } |
| 43 |
| 44 private: |
| 45 OutputSurfaceClient* client_; |
| 46 }; |
| 47 |
26 OutputSurface::OutputSurface( | 48 OutputSurface::OutputSurface( |
27 scoped_ptr<WebKit::WebGraphicsContext3D> context3d) | 49 scoped_ptr<WebKit::WebGraphicsContext3D> context3d) |
28 : client_(NULL), | 50 : client_(NULL), |
29 context3d_(context3d.Pass()), | 51 context3d_(context3d.Pass()), |
30 has_gl_discard_backbuffer_(false) { | 52 has_gl_discard_backbuffer_(false) { |
31 } | 53 } |
32 | 54 |
33 OutputSurface::OutputSurface( | 55 OutputSurface::OutputSurface( |
34 scoped_ptr<cc::SoftwareOutputDevice> software_device) | 56 scoped_ptr<cc::SoftwareOutputDevice> software_device) |
35 : client_(NULL), | 57 : client_(NULL), |
(...skipping 23 matching lines...) Expand all Loading... |
59 return false; | 81 return false; |
60 | 82 |
61 string extensionsString = UTF16ToASCII(context3d_->getString(GL_EXTENSIONS)); | 83 string extensionsString = UTF16ToASCII(context3d_->getString(GL_EXTENSIONS)); |
62 vector<string> extensionsList; | 84 vector<string> extensionsList; |
63 base::SplitString(extensionsString, ' ', &extensionsList); | 85 base::SplitString(extensionsString, ' ', &extensionsList); |
64 set<string> extensions(extensionsList.begin(), extensionsList.end()); | 86 set<string> extensions(extensionsList.begin(), extensionsList.end()); |
65 | 87 |
66 has_gl_discard_backbuffer_ = | 88 has_gl_discard_backbuffer_ = |
67 extensions.count("GL_CHROMIUM_discard_backbuffer"); | 89 extensions.count("GL_CHROMIUM_discard_backbuffer"); |
68 | 90 |
| 91 callbacks_.reset(new OutputSurfaceCallbacks(client_)); |
| 92 context3d_->setSwapBuffersCompleteCallbackCHROMIUM(callbacks_.get()); |
| 93 context3d_->setContextLostCallback(callbacks_.get()); |
| 94 |
69 return true; | 95 return true; |
70 } | 96 } |
71 | 97 |
72 void OutputSurface::SendFrameToParentCompositor(CompositorFrame*) { | 98 void OutputSurface::SendFrameToParentCompositor(CompositorFrame*) { |
73 NOTIMPLEMENTED(); | 99 NOTIMPLEMENTED(); |
74 } | 100 } |
75 | 101 |
76 void OutputSurface::EnsureBackbuffer() { | 102 void OutputSurface::EnsureBackbuffer() { |
77 DCHECK(context3d_); | 103 DCHECK(context3d_); |
78 if (has_gl_discard_backbuffer_) | 104 if (has_gl_discard_backbuffer_) |
(...skipping 23 matching lines...) Expand all Loading... |
102 context3d_->prepareTexture(); | 128 context3d_->prepareTexture(); |
103 } | 129 } |
104 | 130 |
105 void OutputSurface::PostSubBuffer(gfx::Rect rect) { | 131 void OutputSurface::PostSubBuffer(gfx::Rect rect) { |
106 DCHECK(context3d_); | 132 DCHECK(context3d_); |
107 context3d_->postSubBufferCHROMIUM( | 133 context3d_->postSubBufferCHROMIUM( |
108 rect.x(), rect.y(), rect.width(), rect.height()); | 134 rect.x(), rect.y(), rect.width(), rect.height()); |
109 } | 135 } |
110 | 136 |
111 } // namespace cc | 137 } // namespace cc |
OLD | NEW |