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/output_surface.h" | 5 #include "cc/output/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 |
(...skipping 12 matching lines...) Expand all Loading... | |
23 using std::vector; | 23 using std::vector; |
24 | 24 |
25 namespace cc { | 25 namespace cc { |
26 | 26 |
27 class OutputSurfaceCallbacks | 27 class OutputSurfaceCallbacks |
28 : public WebKit::WebGraphicsContext3D:: | 28 : public WebKit::WebGraphicsContext3D:: |
29 WebGraphicsSwapBuffersCompleteCallbackCHROMIUM, | 29 WebGraphicsSwapBuffersCompleteCallbackCHROMIUM, |
30 public WebKit::WebGraphicsContext3D::WebGraphicsContextLostCallback { | 30 public WebKit::WebGraphicsContext3D::WebGraphicsContextLostCallback { |
31 public: | 31 public: |
32 explicit OutputSurfaceCallbacks(OutputSurfaceClient* client) | 32 explicit OutputSurfaceCallbacks(OutputSurfaceClient* client) |
33 : client_(client) {} | 33 : client_(client) { |
34 DCHECK(client_); | |
35 } | |
34 | 36 |
35 // WK:WGC3D::WGSwapBuffersCompleteCallbackCHROMIUM implementation. | 37 // WK:WGC3D::WGSwapBuffersCompleteCallbackCHROMIUM implementation. |
36 virtual void onSwapBuffersComplete() { client_->OnSwapBuffersComplete(); } | 38 virtual void onSwapBuffersComplete() { client_->OnSwapBuffersComplete(); } |
37 | 39 |
38 // WK:WGC3D::WGContextLostCallback implementation. | 40 // WK:WGC3D::WGContextLostCallback implementation. |
39 virtual void onContextLost() { client_->DidLoseOutputSurface(); } | 41 virtual void onContextLost() { client_->DidLoseOutputSurface(); } |
40 | 42 |
41 private: | 43 private: |
42 OutputSurfaceClient* client_; | 44 OutputSurfaceClient* client_; |
43 }; | 45 }; |
(...skipping 27 matching lines...) Expand all Loading... | |
71 OutputSurface::~OutputSurface() { | 73 OutputSurface::~OutputSurface() { |
72 } | 74 } |
73 | 75 |
74 bool OutputSurface::ForcedDrawToSoftwareDevice() const { | 76 bool OutputSurface::ForcedDrawToSoftwareDevice() const { |
75 return false; | 77 return false; |
76 } | 78 } |
77 | 79 |
78 bool OutputSurface::BindToClient( | 80 bool OutputSurface::BindToClient( |
79 cc::OutputSurfaceClient* client) { | 81 cc::OutputSurfaceClient* client) { |
80 DCHECK(client); | 82 DCHECK(client); |
81 if (context3d_ && !context3d_->makeContextCurrent()) | |
82 return false; | |
83 client_ = client; | 83 client_ = client; |
84 if (!context3d_) | 84 bool success = true; |
85 return true; | 85 |
86 string extensions_string = UTF16ToASCII(context3d_->getString(GL_EXTENSIONS)); | 86 if (context3d_) { |
87 success = context3d_->makeContextCurrent(); | |
88 if (success) | |
89 SetContext3D(context3d_.Pass()); | |
90 } | |
91 | |
92 if (!success) | |
93 client_ = NULL; | |
94 | |
95 return success; | |
96 } | |
97 | |
98 bool OutputSurface::InitializeAndSetContext3D( | |
99 scoped_ptr<WebKit::WebGraphicsContext3D> context3d, | |
100 scoped_refptr<ContextProvider> offscreen_context_provider) { | |
101 DCHECK(!context3d_); | |
102 DCHECK(context3d); | |
103 DCHECK(client_); | |
104 | |
105 bool success = false; | |
106 if (context3d->makeContextCurrent()) { | |
107 SetContext3D(context3d.Pass()); | |
108 if (client_->DeferredInitialize(offscreen_context_provider)) | |
109 success = true; | |
110 } | |
111 | |
112 if (!success) { | |
113 context3d_.reset(); | |
114 callbacks_.reset(); | |
danakj
2013/06/07 17:32:00
nit: since the callbacks use the context3d, i thin
boliu
2013/06/07 17:34:31
Actually context3d uses callbacks, so the order is
danakj
2013/06/07 17:48:07
Oh, I'm thinking that when callbacks go away they
| |
115 } | |
116 | |
117 return success; | |
118 } | |
119 | |
120 void OutputSurface::SetContext3D( | |
121 scoped_ptr<WebKit::WebGraphicsContext3D> context3d) { | |
122 DCHECK(!context3d_); | |
123 DCHECK(context3d); | |
124 DCHECK(client_); | |
125 | |
126 string extensions_string = UTF16ToASCII(context3d->getString(GL_EXTENSIONS)); | |
87 vector<string> extensions_list; | 127 vector<string> extensions_list; |
88 base::SplitString(extensions_string, ' ', &extensions_list); | 128 base::SplitString(extensions_string, ' ', &extensions_list); |
89 set<string> extensions(extensions_list.begin(), extensions_list.end()); | 129 set<string> extensions(extensions_list.begin(), extensions_list.end()); |
90 | |
91 has_gl_discard_backbuffer_ = | 130 has_gl_discard_backbuffer_ = |
92 extensions.count("GL_CHROMIUM_discard_backbuffer") > 0; | 131 extensions.count("GL_CHROMIUM_discard_backbuffer") > 0; |
93 | 132 |
133 context3d_ = context3d.Pass(); | |
94 callbacks_.reset(new OutputSurfaceCallbacks(client_)); | 134 callbacks_.reset(new OutputSurfaceCallbacks(client_)); |
95 context3d_->setSwapBuffersCompleteCallbackCHROMIUM(callbacks_.get()); | 135 context3d_->setSwapBuffersCompleteCallbackCHROMIUM(callbacks_.get()); |
96 context3d_->setContextLostCallback(callbacks_.get()); | 136 context3d_->setContextLostCallback(callbacks_.get()); |
97 | |
98 return true; | |
99 } | 137 } |
100 | 138 |
101 void OutputSurface::SendFrameToParentCompositor(CompositorFrame* frame) { | 139 void OutputSurface::SendFrameToParentCompositor(CompositorFrame* frame) { |
102 NOTIMPLEMENTED(); | 140 NOTIMPLEMENTED(); |
103 } | 141 } |
104 | 142 |
105 void OutputSurface::EnsureBackbuffer() { | 143 void OutputSurface::EnsureBackbuffer() { |
106 DCHECK(context3d_); | 144 DCHECK(context3d_); |
107 if (has_gl_discard_backbuffer_) | 145 if (has_gl_discard_backbuffer_) |
108 context3d_->ensureBackbufferCHROMIUM(); | 146 context3d_->ensureBackbufferCHROMIUM(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
143 } | 181 } |
144 | 182 |
145 void OutputSurface::PostSubBuffer(gfx::Rect rect, | 183 void OutputSurface::PostSubBuffer(gfx::Rect rect, |
146 const ui::LatencyInfo& latency_info) { | 184 const ui::LatencyInfo& latency_info) { |
147 DCHECK(context3d_); | 185 DCHECK(context3d_); |
148 context3d_->postSubBufferCHROMIUM( | 186 context3d_->postSubBufferCHROMIUM( |
149 rect.x(), rect.y(), rect.width(), rect.height()); | 187 rect.x(), rect.y(), rect.width(), rect.height()); |
150 } | 188 } |
151 | 189 |
152 } // namespace cc | 190 } // namespace cc |
OLD | NEW |