| OLD | NEW | 
|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 "components/html_viewer/web_graphics_context_3d_command_buffer_impl.h" | 5 #include "components/html_viewer/web_graphics_context_3d_command_buffer_impl.h" | 
| 6 | 6 | 
| 7 #include "components/mus/public/interfaces/gpu.mojom.h" | 7 #include "components/mus/public/interfaces/gpu.mojom.h" | 
|  | 8 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 
| 8 #include "mojo/application/public/cpp/application_impl.h" | 9 #include "mojo/application/public/cpp/application_impl.h" | 
| 9 #include "mojo/cc/context_provider_mojo.h" | 10 #include "mojo/cc/context_provider_mojo.h" | 
| 10 #include "mojo/gles2/gles2_context.h" | 11 #include "mojo/gles2/gles2_context.h" | 
| 11 #include "mojo/gpu/mojo_gles2_impl_autogen.h" | 12 #include "mojo/gpu/mojo_gles2_impl_autogen.h" | 
| 12 #include "third_party/mojo/src/mojo/public/cpp/environment/environment.h" | 13 #include "third_party/mojo/src/mojo/public/cpp/environment/environment.h" | 
| 13 | 14 | 
| 14 namespace html_viewer { | 15 namespace html_viewer { | 
| 15 | 16 | 
| 16 WebGraphicsContext3DCommandBufferImpl::WebGraphicsContext3DCommandBufferImpl( | 17 WebGraphicsContext3DCommandBufferImpl::WebGraphicsContext3DCommandBufferImpl( | 
| 17     mojo::ApplicationImpl* app, | 18     mojo::ApplicationImpl* app, | 
| 18     const GURL& active_url, | 19     const GURL& active_url, | 
| 19     const blink::WebGraphicsContext3D::Attributes& attributes, | 20     const blink::WebGraphicsContext3D::Attributes& attributes, | 
| 20     blink::WebGraphicsContext3D* share_context, | 21     blink::WebGraphicsContext3D* share_context, | 
| 21     blink::WebGLInfo* gl_info) { | 22     blink::WebGLInfo* gl_info) { | 
| 22   mojo::URLRequestPtr request(mojo::URLRequest::New()); | 23   mojo::URLRequestPtr request(mojo::URLRequest::New()); | 
| 23   request->url = mojo::String::From("mojo:mus"); | 24   request->url = mojo::String::From("mojo:mus"); | 
| 24   mojo::GpuPtr gpu_service; | 25   mojo::GpuPtr gpu_service; | 
| 25   app->ConnectToService(request.Pass(), &gpu_service); | 26   app->ConnectToService(request.Pass(), &gpu_service); | 
| 26 | 27 | 
| 27   mojo::CommandBufferPtr cb; | 28   mojo::CommandBufferPtr cb; | 
| 28   gpu_service->CreateOffscreenGLES2Context(GetProxy(&cb)); | 29   gpu_service->CreateOffscreenGLES2Context(GetProxy(&cb)); | 
| 29   command_buffer_handle_ = cb.PassInterface().PassHandle(); | 30   command_buffer_handle_ = cb.PassInterface().PassHandle(); | 
| 30   CHECK(command_buffer_handle_.is_valid()); | 31   CHECK(command_buffer_handle_.is_valid()); | 
| 31   // TODO(penghuang): Support share context. | 32   // TODO(penghuang): Support share context. | 
| 32   // TODO(penghuang): Fill gl_info and pass attribuites to GPU. | 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); | 
| 33   gles2_context_ = MojoGLES2CreateContext( | 46   gles2_context_ = MojoGLES2CreateContext( | 
| 34       command_buffer_handle_.release().value(), | 47       command_buffer_handle_.release().value(), | 
|  | 48       attrib_vector.data(), | 
| 35       &ContextLostThunk, | 49       &ContextLostThunk, | 
| 36       this, | 50       this, | 
| 37       mojo::Environment::GetDefaultAsyncWaiter()); | 51       mojo::Environment::GetDefaultAsyncWaiter()); | 
| 38   context_gl_.reset(new mojo::MojoGLES2Impl(gles2_context_)); | 52   context_gl_.reset(new mojo::MojoGLES2Impl(gles2_context_)); | 
| 39   setGLInterface(context_gl_.get()); | 53   setGLInterface(context_gl_.get()); | 
| 40 } | 54 } | 
| 41 | 55 | 
| 42 WebGraphicsContext3DCommandBufferImpl:: | 56 WebGraphicsContext3DCommandBufferImpl:: | 
| 43     ~WebGraphicsContext3DCommandBufferImpl() { | 57     ~WebGraphicsContext3DCommandBufferImpl() { | 
| 44 } | 58 } | 
| 45 | 59 | 
| 46 // static | 60 // static | 
| 47 WebGraphicsContext3DCommandBufferImpl* | 61 WebGraphicsContext3DCommandBufferImpl* | 
| 48 WebGraphicsContext3DCommandBufferImpl::CreateOffscreenContext( | 62 WebGraphicsContext3DCommandBufferImpl::CreateOffscreenContext( | 
| 49     mojo::ApplicationImpl* app, | 63     mojo::ApplicationImpl* app, | 
| 50     const GURL& active_url, | 64     const GURL& active_url, | 
| 51     const blink::WebGraphicsContext3D::Attributes& attributes, | 65     const blink::WebGraphicsContext3D::Attributes& attributes, | 
| 52     blink::WebGraphicsContext3D* share_context, | 66     blink::WebGraphicsContext3D* share_context, | 
| 53     blink::WebGLInfo* gl_info) { | 67     blink::WebGLInfo* gl_info) { | 
| 54   return new WebGraphicsContext3DCommandBufferImpl( | 68   return new WebGraphicsContext3DCommandBufferImpl( | 
| 55       app, active_url, attributes, share_context, gl_info); | 69       app, active_url, attributes, share_context, gl_info); | 
| 56 } | 70 } | 
| 57 | 71 | 
| 58 void WebGraphicsContext3DCommandBufferImpl::ContextLost() { | 72 void WebGraphicsContext3DCommandBufferImpl::ContextLost() { | 
| 59   if (context_lost_callback_) | 73   if (context_lost_callback_) | 
| 60     context_lost_callback_->onContextLost(); | 74     context_lost_callback_->onContextLost(); | 
| 61 } | 75 } | 
| 62 | 76 | 
| 63 }  // namespace html_viewer | 77 }  // namespace html_viewer | 
| OLD | NEW | 
|---|