Cleanup: Pass std::string as const reference from pdf/
[chromium-blink-merge.git] / components / html_viewer / web_graphics_context_3d_command_buffer_impl.cc
blob52881c0157c0f906308221ed0b7c95a58aede588
1 // Copyright 2015 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.
5 #include "components/html_viewer/web_graphics_context_3d_command_buffer_impl.h"
7 #include "components/mus/public/interfaces/gpu.mojom.h"
8 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
9 #include "mojo/application/public/cpp/application_impl.h"
10 #include "mojo/cc/context_provider_mojo.h"
11 #include "mojo/gles2/gles2_context.h"
12 #include "mojo/gpu/mojo_gles2_impl_autogen.h"
13 #include "third_party/mojo/src/mojo/public/cpp/environment/environment.h"
15 namespace html_viewer {
17 WebGraphicsContext3DCommandBufferImpl::WebGraphicsContext3DCommandBufferImpl(
18 mojo::ApplicationImpl* app,
19 const GURL& active_url,
20 const blink::WebGraphicsContext3D::Attributes& attributes,
21 blink::WebGraphicsContext3D* share_context,
22 blink::WebGLInfo* gl_info) {
23 mojo::URLRequestPtr request(mojo::URLRequest::New());
24 request->url = mojo::String::From("mojo:mus");
25 mojo::GpuPtr gpu_service;
26 app->ConnectToService(request.Pass(), &gpu_service);
28 mojo::CommandBufferPtr cb;
29 gpu_service->CreateOffscreenGLES2Context(GetProxy(&cb));
30 command_buffer_handle_ = cb.PassInterface().PassHandle();
31 CHECK(command_buffer_handle_.is_valid());
32 // TODO(penghuang): Support share context.
33 // TODO(penghuang): Fill gl_info.
34 gpu::gles2::ContextCreationAttribHelper attrib_helper;
35 attrib_helper.alpha_size = attributes.alpha ? 8 : 0;
36 attrib_helper.depth_size = attributes.depth ? 24 : 0;
37 attrib_helper.stencil_size = attributes.stencil ? 8 : 0;
38 attrib_helper.samples = attributes.antialias ? 4 : 0;
39 attrib_helper.sample_buffers = attributes.antialias ? 1 : 0;
40 attrib_helper.fail_if_major_perf_caveat =
41 attributes.failIfMajorPerformanceCaveat;
42 attrib_helper.bind_generates_resource = false;
43 attrib_helper.webgl_version = attributes.webGLVersion;
44 std::vector<int32_t> attrib_vector;
45 attrib_helper.Serialize(&attrib_vector);
46 gles2_context_ = MojoGLES2CreateContext(
47 command_buffer_handle_.release().value(),
48 attrib_vector.data(),
49 &ContextLostThunk,
50 this,
51 mojo::Environment::GetDefaultAsyncWaiter());
52 context_gl_.reset(new mojo::MojoGLES2Impl(gles2_context_));
53 setGLInterface(context_gl_.get());
56 WebGraphicsContext3DCommandBufferImpl::
57 ~WebGraphicsContext3DCommandBufferImpl() {
58 if (gles2_context_)
59 MojoGLES2DestroyContext(gles2_context_);
62 // static
63 WebGraphicsContext3DCommandBufferImpl*
64 WebGraphicsContext3DCommandBufferImpl::CreateOffscreenContext(
65 mojo::ApplicationImpl* app,
66 const GURL& active_url,
67 const blink::WebGraphicsContext3D::Attributes& attributes,
68 blink::WebGraphicsContext3D* share_context,
69 blink::WebGLInfo* gl_info) {
70 return new WebGraphicsContext3DCommandBufferImpl(
71 app, active_url, attributes, share_context, gl_info);
74 void WebGraphicsContext3DCommandBufferImpl::ContextLost() {
75 if (context_lost_callback_)
76 context_lost_callback_->onContextLost();
79 } // namespace html_viewer