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

Side by Side Diff: webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc

Issue 22277004: Add gfx::SurfaceFactoryWebview (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add thread check Created 7 years, 4 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl. h" 5 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl. h"
6 6
7 #include <GLES2/gl2.h> 7 #include <GLES2/gl2.h>
8 #ifndef GL_GLEXT_PROTOTYPES 8 #ifndef GL_GLEXT_PROTOTYPES
9 #define GL_GLEXT_PROTOTYPES 1 9 #define GL_GLEXT_PROTOTYPES 1
10 #endif 10 #endif
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 } // namespace anonymous 66 } // namespace anonymous
67 67
68 // static 68 // static
69 scoped_ptr<WebKit::WebGraphicsContext3D> 69 scoped_ptr<WebKit::WebGraphicsContext3D>
70 WebGraphicsContext3DInProcessCommandBufferImpl::CreateViewContext( 70 WebGraphicsContext3DInProcessCommandBufferImpl::CreateViewContext(
71 const WebKit::WebGraphicsContext3D::Attributes& attributes, 71 const WebKit::WebGraphicsContext3D::Attributes& attributes,
72 gfx::AcceleratedWidget window) { 72 gfx::AcceleratedWidget window) {
73 scoped_ptr<WebKit::WebGraphicsContext3D> context; 73 scoped_ptr<WebKit::WebGraphicsContext3D> context;
74 if (gfx::GLSurface::InitializeOneOff()) { 74 if (gfx::GLSurface::InitializeOneOff()) {
75 context.reset(new WebGraphicsContext3DInProcessCommandBufferImpl( 75 context.reset(new WebGraphicsContext3DInProcessCommandBufferImpl(
76 attributes, false, window)); 76 scoped_ptr< ::gpu::GLInProcessContext>(), attributes, false, window));
77 } 77 }
78 return context.Pass(); 78 return context.Pass();
79 } 79 }
80 80
81 // static 81 // static
82 scoped_ptr<WebKit::WebGraphicsContext3D> 82 scoped_ptr<WebKit::WebGraphicsContext3D>
83 WebGraphicsContext3DInProcessCommandBufferImpl::CreateOffscreenContext( 83 WebGraphicsContext3DInProcessCommandBufferImpl::CreateOffscreenContext(
84 const WebKit::WebGraphicsContext3D::Attributes& attributes) { 84 const WebKit::WebGraphicsContext3D::Attributes& attributes) {
85 return make_scoped_ptr(new WebGraphicsContext3DInProcessCommandBufferImpl( 85 return make_scoped_ptr(new WebGraphicsContext3DInProcessCommandBufferImpl(
86 attributes, true, gfx::kNullAcceleratedWidget)) 86 scoped_ptr< ::gpu::GLInProcessContext>(),
87 attributes,
88 true,
89 gfx::kNullAcceleratedWidget))
90 .PassAs<WebKit::WebGraphicsContext3D>();
91 }
92
93 scoped_ptr<WebKit::WebGraphicsContext3D>
94 WebGraphicsContext3DInProcessCommandBufferImpl::WrapContext(
95 scoped_ptr< ::gpu::GLInProcessContext> context,
96 const WebKit::WebGraphicsContext3D::Attributes& attributes) {
97 return make_scoped_ptr(
98 new WebGraphicsContext3DInProcessCommandBufferImpl(
99 context.Pass(),
100 attributes,
101 true /* is_offscreen. Not used. */,
102 gfx::kNullAcceleratedWidget /* window. Not used. */))
87 .PassAs<WebKit::WebGraphicsContext3D>(); 103 .PassAs<WebKit::WebGraphicsContext3D>();
88 } 104 }
89 105
90 WebGraphicsContext3DInProcessCommandBufferImpl:: 106 WebGraphicsContext3DInProcessCommandBufferImpl::
91 WebGraphicsContext3DInProcessCommandBufferImpl( 107 WebGraphicsContext3DInProcessCommandBufferImpl(
108 scoped_ptr< ::gpu::GLInProcessContext> context,
92 const WebKit::WebGraphicsContext3D::Attributes& attributes, 109 const WebKit::WebGraphicsContext3D::Attributes& attributes,
93 bool is_offscreen, 110 bool is_offscreen,
94 gfx::AcceleratedWidget window) 111 gfx::AcceleratedWidget window)
95 : is_offscreen_(is_offscreen), 112 : is_offscreen_(is_offscreen),
96 window_(window), 113 window_(window),
97 initialized_(false), 114 initialized_(false),
98 initialize_failed_(false), 115 initialize_failed_(false),
116 context_(context.Pass()),
99 gl_(NULL), 117 gl_(NULL),
100 context_lost_callback_(NULL), 118 context_lost_callback_(NULL),
101 context_lost_reason_(GL_NO_ERROR), 119 context_lost_reason_(GL_NO_ERROR),
102 attributes_(attributes), 120 attributes_(attributes),
103 cached_width_(0), 121 cached_width_(0),
104 cached_height_(0) { 122 cached_height_(0) {
105 } 123 }
106 124
107 WebGraphicsContext3DInProcessCommandBufferImpl:: 125 WebGraphicsContext3DInProcessCommandBufferImpl::
108 ~WebGraphicsContext3DInProcessCommandBufferImpl() { 126 ~WebGraphicsContext3DInProcessCommandBufferImpl() {
109 } 127 }
110 128
111 bool WebGraphicsContext3DInProcessCommandBufferImpl::MaybeInitializeGL() { 129 bool WebGraphicsContext3DInProcessCommandBufferImpl::MaybeInitializeGL() {
112 if (initialized_) 130 if (initialized_)
113 return true; 131 return true;
114 132
115 if (initialize_failed_) 133 if (initialize_failed_)
116 return false; 134 return false;
117 135
118 // Ensure the gles2 library is initialized first in a thread safe way. 136 // Ensure the gles2 library is initialized first in a thread safe way.
119 g_gles2_initializer.Get(); 137 g_gles2_initializer.Get();
120 138
121 // Convert WebGL context creation attributes into GLInProcessContext / EGL 139 if (!context_) {
122 // size requests. 140 // Convert WebGL context creation attributes into GLInProcessContext / EGL
123 const int alpha_size = attributes_.alpha ? 8 : 0; 141 // size requests.
124 const int depth_size = attributes_.depth ? 24 : 0; 142 const int alpha_size = attributes_.alpha ? 8 : 0;
125 const int stencil_size = attributes_.stencil ? 8 : 0; 143 const int depth_size = attributes_.depth ? 24 : 0;
126 const int samples = attributes_.antialias ? 4 : 0; 144 const int stencil_size = attributes_.stencil ? 8 : 0;
127 const int sample_buffers = attributes_.antialias ? 1 : 0; 145 const int samples = attributes_.antialias ? 4 : 0;
128 const int32 attribs[] = { 146 const int sample_buffers = attributes_.antialias ? 1 : 0;
129 GLInProcessContext::ALPHA_SIZE, alpha_size, 147 const int32 attribs[] = {
130 GLInProcessContext::DEPTH_SIZE, depth_size, 148 GLInProcessContext::ALPHA_SIZE, alpha_size,
131 GLInProcessContext::STENCIL_SIZE, stencil_size, 149 GLInProcessContext::DEPTH_SIZE, depth_size,
132 GLInProcessContext::SAMPLES, samples, 150 GLInProcessContext::STENCIL_SIZE, stencil_size,
133 GLInProcessContext::SAMPLE_BUFFERS, sample_buffers, 151 GLInProcessContext::SAMPLES, samples,
134 GLInProcessContext::NONE, 152 GLInProcessContext::SAMPLE_BUFFERS, sample_buffers,
135 }; 153 GLInProcessContext::NONE,
154 };
136 155
137 const char* preferred_extensions = "*"; 156 const char* preferred_extensions = "*";
138 157
139 // TODO(kbr): More work will be needed in this implementation to 158 // TODO(kbr): More work will be needed in this implementation to
140 // properly support GPU switching. Like in the out-of-process 159 // properly support GPU switching. Like in the out-of-process
141 // command buffer implementation, all previously created contexts 160 // command buffer implementation, all previously created contexts
142 // will need to be lost either when the first context requesting the 161 // will need to be lost either when the first context requesting the
143 // discrete GPU is created, or the last one is destroyed. 162 // discrete GPU is created, or the last one is destroyed.
144 gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; 163 gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu;
145 164
146 base::Closure context_lost_callback = 165 context_.reset(GLInProcessContext::CreateContext(
147 base::Bind(&WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost, 166 is_offscreen_,
148 base::Unretained(this)); 167 window_,
168 gfx::Size(1, 1),
169 attributes_.shareResources,
170 preferred_extensions,
171 attribs,
172 gpu_preference));
173 }
149 174
150 context_.reset(GLInProcessContext::CreateContext( 175 if (context_) {
151 is_offscreen_, 176 base::Closure context_lost_callback = base::Bind(
152 window_, 177 &WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost,
153 gfx::Size(1, 1), 178 base::Unretained(this));
154 attributes_.shareResources, 179 context_->SetContextLostCallback(context_lost_callback);
155 preferred_extensions, 180 } else {
156 attribs,
157 gpu_preference,
158 context_lost_callback));
159
160 if (!context_) {
161 initialize_failed_ = true; 181 initialize_failed_ = true;
162 return false; 182 return false;
163 } 183 }
164 184
165 gl_ = context_->GetImplementation(); 185 gl_ = context_->GetImplementation();
166 186
167 if (gl_ && attributes_.noExtensions) 187 if (gl_ && attributes_.noExtensions)
168 gl_->EnableFeatureCHROMIUM("webgl_enable_glsl_webgl_validation"); 188 gl_->EnableFeatureCHROMIUM("webgl_enable_glsl_webgl_validation");
169 189
170 // Set attributes_ from created offscreen context. 190 // Set attributes_ from created offscreen context.
(...skipping 1014 matching lines...) Expand 10 before | Expand all | Expand 10 after
1185 1205
1186 DELEGATE_TO_GL_9(asyncTexSubImage2DCHROMIUM, AsyncTexSubImage2DCHROMIUM, 1206 DELEGATE_TO_GL_9(asyncTexSubImage2DCHROMIUM, AsyncTexSubImage2DCHROMIUM,
1187 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei, 1207 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei,
1188 WGC3Denum, WGC3Denum, const void*) 1208 WGC3Denum, WGC3Denum, const void*)
1189 1209
1190 DELEGATE_TO_GL_1(waitAsyncTexImage2DCHROMIUM, WaitAsyncTexImage2DCHROMIUM, 1210 DELEGATE_TO_GL_1(waitAsyncTexImage2DCHROMIUM, WaitAsyncTexImage2DCHROMIUM,
1191 WGC3Denum) 1211 WGC3Denum)
1192 1212
1193 } // namespace gpu 1213 } // namespace gpu
1194 } // namespace webkit 1214 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698