Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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 "cc/surfaces/in_process_context_provider.h" | |
| 6 | |
| 7 #include <stdint.h> | |
| 8 | |
| 9 #include "base/lazy_instance.h" | |
| 10 #include "base/macros.h" | |
| 11 #include "base/memory/ptr_util.h" | |
| 12 #include "base/single_thread_task_runner.h" | |
| 13 #include "base/threading/thread_task_runner_handle.h" | |
| 14 #include "cc/resources/platform_color.h" | |
| 15 #include "cc/surfaces/deferred_gpu_command_service.h" | |
| 16 #include "gpu/GLES2/gl2extchromium.h" | |
| 17 #include "gpu/command_buffer/client/gles2_implementation.h" | |
| 18 #include "gpu/command_buffer/client/gles2_lib.h" | |
| 19 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | |
| 20 #include "gpu/command_buffer/service/framebuffer_completeness_cache.h" | |
| 21 #include "gpu/command_buffer/service/gpu_preferences.h" | |
| 22 #include "gpu/command_buffer/service/mailbox_manager.h" | |
| 23 #include "gpu/command_buffer/service/shader_translator_cache.h" | |
| 24 #include "gpu/command_buffer/service/sync_point_manager.h" | |
| 25 #include "gpu/ipc/gl_in_process_context.h" | |
| 26 #include "gpu/ipc/in_process_command_buffer.h" | |
| 27 #include "gpu/skia_bindings/grcontext_for_gles2_interface.h" | |
| 28 #include "third_party/khronos/GLES2/gl2.h" | |
| 29 #include "third_party/khronos/GLES2/gl2ext.h" | |
| 30 #include "third_party/skia/include/gpu/GrContext.h" | |
| 31 #include "third_party/skia/include/gpu/gl/GrGLInterface.h" | |
| 32 #include "ui/gfx/native_widget_types.h" | |
| 33 #include "ui/gl/gl_share_group.h" | |
| 34 | |
| 35 namespace cc { | |
| 36 | |
| 37 namespace { | |
| 38 | |
| 39 gpu::gles2::ContextCreationAttribHelper CreateAttributes() { | |
| 40 gpu::gles2::ContextCreationAttribHelper attributes; | |
| 41 attributes.alpha_size = -1; | |
| 42 attributes.depth_size = 0; | |
| 43 attributes.stencil_size = 0; | |
| 44 attributes.samples = 0; | |
| 45 attributes.sample_buffers = 0; | |
| 46 attributes.fail_if_major_perf_caveat = false; | |
| 47 attributes.bind_generates_resource = false; | |
| 48 return attributes; | |
| 49 } | |
| 50 | |
| 51 std::unique_ptr<gpu::GLInProcessContext> CreateInProcessContext( | |
| 52 scoped_refptr<gpu::InProcessCommandBuffer::Service> service, | |
| 53 const gpu::gles2::ContextCreationAttribHelper& attributes, | |
| 54 gfx::AcceleratedWidget widget, | |
| 55 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | |
| 56 gpu::ImageFactory* image_factory, | |
| 57 const gpu::SharedMemoryLimits& limits, | |
| 58 gpu::GLInProcessContext* shared_context) { | |
| 59 const bool is_offscreen = widget == gfx::kNullAcceleratedWidget; | |
| 60 return base::WrapUnique(gpu::GLInProcessContext::Create( | |
| 61 service, nullptr, is_offscreen, widget, shared_context, attributes, | |
| 62 limits, gpu_memory_buffer_manager, image_factory, | |
| 63 base::ThreadTaskRunnerHandle::Get())); | |
| 64 } | |
| 65 | |
| 66 } // namespace | |
| 67 | |
| 68 InProcessContextProvider::InProcessContextProvider( | |
| 69 scoped_refptr<gpu::InProcessCommandBuffer::Service> service, | |
| 70 gfx::AcceleratedWidget widget, | |
| 71 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | |
| 72 gpu::ImageFactory* image_factory, | |
| 73 const gpu::SharedMemoryLimits& limits, | |
| 74 InProcessContextProvider* shared_context) | |
| 75 : attributes_(CreateAttributes()), | |
| 76 context_(CreateInProcessContext( | |
| 77 service, | |
| 78 attributes_, | |
| 79 widget, | |
| 80 gpu_memory_buffer_manager, | |
| 81 image_factory, | |
| 82 limits, | |
| 83 (shared_context ? shared_context->context_.get() : nullptr))) { | |
| 84 cache_controller_.reset(new ContextCacheController( | |
| 85 context_->GetImplementation(), base::ThreadTaskRunnerHandle::Get())); | |
| 86 } | |
| 87 | |
| 88 InProcessContextProvider::~InProcessContextProvider() = default; | |
| 89 | |
| 90 bool InProcessContextProvider::BindToCurrentThread() { | |
| 91 return !!context_; | |
| 92 } | |
| 93 | |
| 94 gpu::gles2::GLES2Interface* InProcessContextProvider::ContextGL() { | |
| 95 return context_->GetImplementation(); | |
| 96 } | |
| 97 | |
| 98 gpu::ContextSupport* InProcessContextProvider::ContextSupport() { | |
| 99 return context_->GetImplementation(); | |
| 100 } | |
| 101 | |
| 102 class GrContext* InProcessContextProvider::GrContext() { | |
| 103 if (gr_context_) | |
| 104 return gr_context_->get(); | |
| 105 | |
| 106 gr_context_.reset(new skia_bindings::GrContextForGLES2Interface(ContextGL())); | |
| 107 return gr_context_->get(); | |
| 108 } | |
| 109 | |
| 110 ContextCacheController* InProcessContextProvider::CacheController() { | |
| 111 return cache_controller_.get(); | |
| 112 } | |
| 113 | |
| 114 void InProcessContextProvider::InvalidateGrContext(uint32_t state) { | |
| 115 if (gr_context_) | |
| 116 gr_context_->ResetContext(state); | |
| 117 } | |
| 118 | |
| 119 base::Lock* InProcessContextProvider::GetLock() { | |
| 120 return &context_lock_; | |
| 121 } | |
| 122 | |
| 123 gpu::Capabilities InProcessContextProvider::ContextCapabilities() { | |
| 124 gpu::Capabilities capabilities; | |
| 125 capabilities.texture_rectangle = true; | |
| 126 capabilities.sync_query = true; | |
| 127 switch (PlatformColor::Format()) { | |
| 128 case PlatformColor::SOURCE_FORMAT_RGBA8: | |
| 129 capabilities.texture_format_bgra8888 = false; | |
| 130 break; | |
| 131 case PlatformColor::SOURCE_FORMAT_BGRA8: | |
| 132 capabilities.texture_format_bgra8888 = true; | |
| 133 break; | |
| 134 } | |
| 135 return capabilities; | |
| 136 } | |
| 137 | |
| 138 void InProcessContextProvider::SetLostContextCallback( | |
| 139 const LostContextCallback& lost_context_callback) { | |
| 140 // This code lives in the GPU process and so this would go away | |
| 141 // if the context is lost? | |
| 142 } | |
| 143 | |
| 144 uint32_t InProcessContextProvider::GetCopyTextureInternalFormat() { | |
| 145 if (attributes_.alpha_size > 0) | |
| 146 return GL_RGBA; | |
| 147 DCHECK_NE(attributes_.red_size, 0); | |
| 148 DCHECK_NE(attributes_.green_size, 0); | |
| 149 DCHECK_NE(attributes_.blue_size, 0); | |
| 150 return GL_RGB; | |
| 151 } | |
| 152 | |
| 153 void InProcessContextProvider::SetSwapBuffersCompletionCallback( | |
| 154 const gpu::InProcessCommandBuffer::SwapBuffersCompletionCallback& | |
| 155 callback) { | |
| 156 context_->GetInProcessCommandBuffer()->SetSwapBuffersCompletionCallback( | |
|
piman
2016/11/15 21:57:32
nit: Demeter is crying. Could we expose SetSwapBuf
Fady Samuel
2016/11/16 00:33:35
Done.
| |
| 157 callback); | |
| 158 } | |
| 159 | |
| 160 void InProcessContextProvider::SetUpdateVSyncParametersCallback( | |
| 161 const gpu::InProcessCommandBuffer::UpdateVSyncParametersCallback& | |
| 162 callback) { | |
| 163 context_->GetInProcessCommandBuffer()->SetUpdateVSyncParametersCallback( | |
| 164 callback); | |
| 165 } | |
| 166 | |
| 167 } // namespace cc | |
| OLD | NEW |