Chromium Code Reviews| 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(); | |
|
danakj
2013/06/07 17:22:23
reset callbacks_ too? (before the context3d)
| |
| 114 | |
| 115 return success; | |
| 116 } | |
| 117 | |
| 118 void OutputSurface::SetContext3D( | |
| 119 scoped_ptr<WebKit::WebGraphicsContext3D> context3d) { | |
| 120 DCHECK(context3d); | |
|
danakj
2013/06/07 17:22:23
DCHECK(!context3d_) here too?
| |
| 121 DCHECK(client_); | |
| 122 | |
| 123 string extensions_string = UTF16ToASCII(context3d->getString(GL_EXTENSIONS)); | |
| 87 vector<string> extensions_list; | 124 vector<string> extensions_list; |
| 88 base::SplitString(extensions_string, ' ', &extensions_list); | 125 base::SplitString(extensions_string, ' ', &extensions_list); |
| 89 set<string> extensions(extensions_list.begin(), extensions_list.end()); | 126 set<string> extensions(extensions_list.begin(), extensions_list.end()); |
| 90 | |
| 91 has_gl_discard_backbuffer_ = | 127 has_gl_discard_backbuffer_ = |
| 92 extensions.count("GL_CHROMIUM_discard_backbuffer") > 0; | 128 extensions.count("GL_CHROMIUM_discard_backbuffer") > 0; |
| 93 | 129 |
| 130 context3d_ = context3d.Pass(); | |
| 94 callbacks_.reset(new OutputSurfaceCallbacks(client_)); | 131 callbacks_.reset(new OutputSurfaceCallbacks(client_)); |
| 95 context3d_->setSwapBuffersCompleteCallbackCHROMIUM(callbacks_.get()); | 132 context3d_->setSwapBuffersCompleteCallbackCHROMIUM(callbacks_.get()); |
| 96 context3d_->setContextLostCallback(callbacks_.get()); | 133 context3d_->setContextLostCallback(callbacks_.get()); |
| 97 | |
| 98 return true; | |
| 99 } | 134 } |
| 100 | 135 |
| 101 void OutputSurface::SendFrameToParentCompositor(CompositorFrame* frame) { | 136 void OutputSurface::SendFrameToParentCompositor(CompositorFrame* frame) { |
| 102 NOTIMPLEMENTED(); | 137 NOTIMPLEMENTED(); |
| 103 } | 138 } |
| 104 | 139 |
| 105 void OutputSurface::EnsureBackbuffer() { | 140 void OutputSurface::EnsureBackbuffer() { |
| 106 DCHECK(context3d_); | 141 DCHECK(context3d_); |
| 107 if (has_gl_discard_backbuffer_) | 142 if (has_gl_discard_backbuffer_) |
| 108 context3d_->ensureBackbufferCHROMIUM(); | 143 context3d_->ensureBackbufferCHROMIUM(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 143 } | 178 } |
| 144 | 179 |
| 145 void OutputSurface::PostSubBuffer(gfx::Rect rect, | 180 void OutputSurface::PostSubBuffer(gfx::Rect rect, |
| 146 const ui::LatencyInfo& latency_info) { | 181 const ui::LatencyInfo& latency_info) { |
| 147 DCHECK(context3d_); | 182 DCHECK(context3d_); |
| 148 context3d_->postSubBufferCHROMIUM( | 183 context3d_->postSubBufferCHROMIUM( |
| 149 rect.x(), rect.y(), rect.width(), rect.height()); | 184 rect.x(), rect.y(), rect.width(), rect.height()); |
| 150 } | 185 } |
| 151 | 186 |
| 152 } // namespace cc | 187 } // namespace cc |
| OLD | NEW |