Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(149)

Side by Side Diff: cc/output_surface.cc

Issue 12545018: Move context-related callbacks into OutputSurface (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: works Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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),
36 software_device_(software_device.Pass()), 58 software_device_(software_device.Pass()),
37 has_gl_discard_backbuffer_(false) { 59 has_gl_discard_backbuffer_(false) {
38 } 60 }
39 61
40 OutputSurface::OutputSurface( 62 OutputSurface::OutputSurface(
41 scoped_ptr<WebKit::WebGraphicsContext3D> context3d, 63 scoped_ptr<WebKit::WebGraphicsContext3D> context3d,
42 scoped_ptr<cc::SoftwareOutputDevice> software_device) 64 scoped_ptr<cc::SoftwareOutputDevice> software_device)
43 : client_(NULL), 65 : client_(NULL),
44 context3d_(context3d.Pass()), 66 context3d_(context3d.Pass()),
45 software_device_(software_device.Pass()), 67 software_device_(software_device.Pass()),
46 has_gl_discard_backbuffer_(false) { 68 has_gl_discard_backbuffer_(false) {
47 } 69 }
48 70
49 OutputSurface::~OutputSurface() { 71 OutputSurface::~OutputSurface() {
50 } 72 }
51 73
74 void OutputSurface::RegisterCallbacks() {
75 if (!context3d_)
76 return;
77
78 callbacks_.reset(new OutputSurfaceCallbacks(client_));
79 context3d_->setSwapBuffersCompleteCallbackCHROMIUM(callbacks_.get());
80 context3d_->setContextLostCallback(callbacks_.get());
81
82 }
83
84 void OutputSurface::ClearCallbacks() {
85 if (!context3d_)
86 return;
87
88 context3d_->setSwapBuffersCompleteCallbackCHROMIUM(NULL);
89 context3d_->setContextLostCallback(NULL);
90 }
91
52 bool OutputSurface::BindToClient( 92 bool OutputSurface::BindToClient(
53 cc::OutputSurfaceClient* client) { 93 cc::OutputSurfaceClient* client) {
54 DCHECK(client); 94 DCHECK(client);
55 client_ = client; 95 client_ = client;
56 if (!context3d_) 96 if (!context3d_)
57 return true; 97 return true;
58 if (!context3d_->makeContextCurrent()) 98 if (!context3d_->makeContextCurrent())
59 return false; 99 return false;
60 100
61 string extensionsString = UTF16ToASCII(context3d_->getString(GL_EXTENSIONS)); 101 string extensionsString = UTF16ToASCII(context3d_->getString(GL_EXTENSIONS));
62 vector<string> extensionsList; 102 vector<string> extensionsList;
63 base::SplitString(extensionsString, ' ', &extensionsList); 103 base::SplitString(extensionsString, ' ', &extensionsList);
64 set<string> extensions(extensionsList.begin(), extensionsList.end()); 104 set<string> extensions(extensionsList.begin(), extensionsList.end());
65 105
66 has_gl_discard_backbuffer_ = 106 has_gl_discard_backbuffer_ =
67 extensions.count("GL_CHROMIUM_discard_backbuffer"); 107 extensions.count("GL_CHROMIUM_discard_backbuffer");
68
69 return true; 108 return true;
70 } 109 }
71 110
72 void OutputSurface::SendFrameToParentCompositor(CompositorFrame*) { 111 void OutputSurface::SendFrameToParentCompositor(CompositorFrame*) {
73 NOTIMPLEMENTED(); 112 NOTIMPLEMENTED();
74 } 113 }
75 114
76 void OutputSurface::EnsureBackbuffer() { 115 void OutputSurface::EnsureBackbuffer() {
77 DCHECK(context3d_); 116 DCHECK(context3d_);
78 if (has_gl_discard_backbuffer_) 117 if (has_gl_discard_backbuffer_)
(...skipping 23 matching lines...) Expand all
102 context3d_->prepareTexture(); 141 context3d_->prepareTexture();
103 } 142 }
104 143
105 void OutputSurface::PostSubBuffer(gfx::Rect rect) { 144 void OutputSurface::PostSubBuffer(gfx::Rect rect) {
106 DCHECK(context3d_); 145 DCHECK(context3d_);
107 context3d_->postSubBufferCHROMIUM( 146 context3d_->postSubBufferCHROMIUM(
108 rect.x(), rect.y(), rect.width(), rect.height()); 147 rect.x(), rect.y(), rect.width(), rect.height());
109 } 148 }
110 149
111 } // namespace cc 150 } // namespace cc
OLDNEW
« cc/output_surface.h ('K') | « cc/output_surface.h ('k') | cc/output_surface_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698