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

Side by Side Diff: gpu/blink/webgraphicscontext3d_in_process_command_buffer_impl.cc

Issue 851503003: Update from https://crrev.com/311076 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "gpu/blink/webgraphicscontext3d_in_process_command_buffer_impl.h"
6
7 #include <GLES2/gl2.h>
8 #ifndef GL_GLEXT_PROTOTYPES
9 #define GL_GLEXT_PROTOTYPES 1
10 #endif
11 #include <GLES2/gl2ext.h>
12 #include <GLES2/gl2extchromium.h>
13
14 #include <string>
15
16 #include "base/atomicops.h"
17 #include "base/bind.h"
18 #include "base/bind_helpers.h"
19 #include "base/callback.h"
20 #include "base/logging.h"
21 #include "gpu/command_buffer/client/gles2_implementation.h"
22 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
23 #include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h"
24 #include "ui/gfx/geometry/size.h"
25 #include "ui/gl/gl_implementation.h"
26
27 using gpu::gles2::GLES2Implementation;
28 using gpu::GLInProcessContext;
29
30 namespace gpu_blink {
31
32 // static
33 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>
34 WebGraphicsContext3DInProcessCommandBufferImpl::CreateViewContext(
35 const blink::WebGraphicsContext3D::Attributes& attributes,
36 bool lose_context_when_out_of_memory,
37 gfx::AcceleratedWidget window) {
38 DCHECK_NE(gfx::GetGLImplementation(), gfx::kGLImplementationNone);
39 bool is_offscreen = false;
40 return make_scoped_ptr(new WebGraphicsContext3DInProcessCommandBufferImpl(
41 scoped_ptr< ::gpu::GLInProcessContext>(),
42 attributes,
43 lose_context_when_out_of_memory,
44 is_offscreen,
45 window));
46 }
47
48 // static
49 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>
50 WebGraphicsContext3DInProcessCommandBufferImpl::CreateOffscreenContext(
51 const blink::WebGraphicsContext3D::Attributes& attributes,
52 bool lose_context_when_out_of_memory) {
53 bool is_offscreen = true;
54 return make_scoped_ptr(new WebGraphicsContext3DInProcessCommandBufferImpl(
55 scoped_ptr< ::gpu::GLInProcessContext>(),
56 attributes,
57 lose_context_when_out_of_memory,
58 is_offscreen,
59 gfx::kNullAcceleratedWidget));
60 }
61
62 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>
63 WebGraphicsContext3DInProcessCommandBufferImpl::WrapContext(
64 scoped_ptr< ::gpu::GLInProcessContext> context,
65 const blink::WebGraphicsContext3D::Attributes& attributes) {
66 bool lose_context_when_out_of_memory = false; // Not used.
67 bool is_offscreen = true; // Not used.
68 return make_scoped_ptr(new WebGraphicsContext3DInProcessCommandBufferImpl(
69 context.Pass(),
70 attributes,
71 lose_context_when_out_of_memory,
72 is_offscreen,
73 gfx::kNullAcceleratedWidget /* window. Not used. */));
74 }
75
76 WebGraphicsContext3DInProcessCommandBufferImpl::
77 WebGraphicsContext3DInProcessCommandBufferImpl(
78 scoped_ptr< ::gpu::GLInProcessContext> context,
79 const blink::WebGraphicsContext3D::Attributes& attributes,
80 bool lose_context_when_out_of_memory,
81 bool is_offscreen,
82 gfx::AcceleratedWidget window)
83 : share_resources_(attributes.shareResources),
84 webgl_context_(attributes.webGL),
85 is_offscreen_(is_offscreen),
86 window_(window),
87 context_(context.Pass()) {
88 ConvertAttributes(attributes, &attribs_);
89 attribs_.lose_context_when_out_of_memory = lose_context_when_out_of_memory;
90 }
91
92 WebGraphicsContext3DInProcessCommandBufferImpl::
93 ~WebGraphicsContext3DInProcessCommandBufferImpl() {
94 }
95
96 size_t WebGraphicsContext3DInProcessCommandBufferImpl::GetMappedMemoryLimit() {
97 return context_->GetMappedMemoryLimit();
98 }
99
100 bool WebGraphicsContext3DInProcessCommandBufferImpl::MaybeInitializeGL() {
101 if (initialized_)
102 return true;
103
104 if (initialize_failed_)
105 return false;
106
107 if (!context_) {
108 // TODO(kbr): More work will be needed in this implementation to
109 // properly support GPU switching. Like in the out-of-process
110 // command buffer implementation, all previously created contexts
111 // will need to be lost either when the first context requesting the
112 // discrete GPU is created, or the last one is destroyed.
113 gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu;
114 context_.reset(GLInProcessContext::Create(
115 NULL, /* service */
116 NULL, /* surface */
117 is_offscreen_,
118 window_,
119 gfx::Size(1, 1),
120 NULL, /* share_context */
121 share_resources_,
122 attribs_,
123 gpu_preference,
124 ::gpu::GLInProcessContextSharedMemoryLimits(),
125 nullptr,
126 nullptr));
127 }
128
129 if (context_) {
130 base::Closure context_lost_callback = base::Bind(
131 &WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost,
132 base::Unretained(this));
133 context_->SetContextLostCallback(context_lost_callback);
134 } else {
135 initialize_failed_ = true;
136 return false;
137 }
138
139 real_gl_ = context_->GetImplementation();
140 setGLInterface(real_gl_);
141
142 if (real_gl_ && webgl_context_)
143 real_gl_->EnableFeatureCHROMIUM("webgl_enable_glsl_webgl_validation");
144
145 initialized_ = true;
146 return true;
147 }
148
149 bool
150 WebGraphicsContext3DInProcessCommandBufferImpl::InitializeOnCurrentThread() {
151 if (!MaybeInitializeGL())
152 return false;
153 return context_ && !isContextLost();
154 }
155
156 bool WebGraphicsContext3DInProcessCommandBufferImpl::isContextLost() {
157 return context_lost_reason_ != GL_NO_ERROR;
158 }
159
160 WGC3Denum WebGraphicsContext3DInProcessCommandBufferImpl::
161 getGraphicsResetStatusARB() {
162 return context_lost_reason_;
163 }
164
165 ::gpu::ContextSupport*
166 WebGraphicsContext3DInProcessCommandBufferImpl::GetContextSupport() {
167 return real_gl_;
168 }
169
170 void WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost() {
171 // TODO(kbr): improve the precision here.
172 context_lost_reason_ = GL_UNKNOWN_CONTEXT_RESET_ARB;
173 if (context_lost_callback_) {
174 context_lost_callback_->onContextLost();
175 }
176 }
177
178 } // namespace gpu_blink
OLDNEW
« no previous file with comments | « gpu/blink/webgraphicscontext3d_in_process_command_buffer_impl.h ('k') | gpu/command_buffer/build_gles2_cmd_buffer.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698