Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "content/common/gpu/image_transport_surface.h" | 5 #include "content/common/gpu/image_transport_surface.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
| 11 #include "content/common/gpu/gpu_channel.h" | 11 #include "content/common/gpu/gpu_channel.h" |
| 12 #include "content/common/gpu/gpu_channel_manager.h" | 12 #include "content/common/gpu/gpu_channel_manager.h" |
| 13 #include "content/common/gpu/gpu_command_buffer_stub.h" | 13 #include "content/common/gpu/gpu_command_buffer_stub.h" |
| 14 #include "content/common/gpu/gpu_messages.h" | 14 #include "content/common/gpu/gpu_messages.h" |
| 15 #include "content/common/gpu/null_transport_surface.h" | 15 #include "content/public/common/content_switches.h" |
| 16 #include "gpu/command_buffer/service/sync_point_manager.h" | 16 #include "gpu/command_buffer/service/sync_point_manager.h" |
| 17 #include "ui/gfx/vsync_provider.h" | 17 #include "ui/gfx/vsync_provider.h" |
| 18 #include "ui/gl/gl_context.h" | 18 #include "ui/gl/gl_context.h" |
| 19 #include "ui/gl/gl_implementation.h" | 19 #include "ui/gl/gl_implementation.h" |
| 20 #include "ui/gl/gl_switches.h" | 20 #include "ui/gl/gl_switches.h" |
| 21 | 21 |
| 22 namespace content { | 22 namespace content { |
| 23 | 23 |
| 24 ImageTransportSurface::ImageTransportSurface() {} | 24 ImageTransportSurface::ImageTransportSurface() {} |
| 25 | 25 |
| 26 ImageTransportSurface::~ImageTransportSurface() {} | 26 ImageTransportSurface::~ImageTransportSurface() {} |
| 27 | 27 |
| 28 scoped_refptr<gfx::GLSurface> ImageTransportSurface::CreateSurface( | 28 scoped_refptr<gfx::GLSurface> ImageTransportSurface::CreateSurface( |
| 29 GpuChannelManager* manager, | 29 GpuChannelManager* manager, |
| 30 GpuCommandBufferStub* stub, | 30 GpuCommandBufferStub* stub, |
| 31 const gfx::GLSurfaceHandle& handle) { | 31 const gfx::GLSurfaceHandle& handle) { |
| 32 scoped_refptr<gfx::GLSurface> surface; | 32 scoped_refptr<gfx::GLSurface> surface; |
| 33 if (handle.transport_type == gfx::NULL_TRANSPORT) { | 33 if (handle.transport_type == gfx::NULL_TRANSPORT) { |
| 34 #if defined(OS_ANDROID) | 34 GpuChannel* parent_channel = manager->LookupChannel( |
| 35 surface = CreateTransportSurface(manager, stub, handle); | 35 handle.parent_client_id); |
| 36 #else | 36 if (parent_channel) { |
| 37 surface = new NullTransportSurface(manager, stub, handle); | 37 const base::CommandLine* command_line = |
| 38 #endif | 38 base::CommandLine::ForCurrentProcess(); |
| 39 if (command_line->HasSwitch(switches::kUIPrioritizeInGpuProcess)) | |
| 40 stub->channel()->SetPreemptByFlag(parent_channel->GetPreemptionFlag()); | |
| 41 } | |
| 42 | |
| 43 surface = manager->GetDefaultOffscreenSurface(); | |
| 39 } else { | 44 } else { |
| 40 surface = CreateNativeSurface(manager, stub, handle); | 45 surface = CreateNativeSurface(manager, stub, handle); |
| 46 if (!surface.get() || !surface->Initialize()) | |
| 47 return NULL; | |
| 41 } | 48 } |
| 42 | 49 |
| 43 if (!surface.get() || !surface->Initialize()) | |
| 44 return NULL; | |
| 45 return surface; | 50 return surface; |
| 46 } | 51 } |
| 47 | 52 |
| 48 ImageTransportHelper::ImageTransportHelper(ImageTransportSurface* surface, | 53 ImageTransportHelper::ImageTransportHelper(ImageTransportSurface* surface, |
| 49 GpuChannelManager* manager, | 54 GpuChannelManager* manager, |
| 50 GpuCommandBufferStub* stub, | 55 GpuCommandBufferStub* stub, |
| 51 gfx::PluginWindowHandle handle) | 56 gfx::PluginWindowHandle handle) |
| 52 : surface_(surface), | 57 : surface_(surface), |
| 53 manager_(manager), | 58 manager_(manager), |
| 54 stub_(stub->AsWeakPtr()), | 59 stub_(stub->AsWeakPtr()), |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 71 if (!decoder) | 76 if (!decoder) |
| 72 return false; | 77 return false; |
| 73 | 78 |
| 74 decoder->SetResizeCallback( | 79 decoder->SetResizeCallback( |
| 75 base::Bind(&ImageTransportHelper::Resize, base::Unretained(this))); | 80 base::Bind(&ImageTransportHelper::Resize, base::Unretained(this))); |
| 76 | 81 |
| 77 stub_->SetLatencyInfoCallback( | 82 stub_->SetLatencyInfoCallback( |
| 78 base::Bind(&ImageTransportHelper::SetLatencyInfo, | 83 base::Bind(&ImageTransportHelper::SetLatencyInfo, |
| 79 base::Unretained(this))); | 84 base::Unretained(this))); |
| 80 | 85 |
| 81 manager_->Send(new GpuHostMsg_AcceleratedSurfaceInitialized( | |
| 82 stub_->surface_id(), route_id_)); | |
| 83 | |
| 84 return true; | 86 return true; |
| 85 } | 87 } |
| 86 | 88 |
| 87 bool ImageTransportHelper::OnMessageReceived(const IPC::Message& message) { | 89 bool ImageTransportHelper::OnMessageReceived(const IPC::Message& message) { |
| 90 #if defined(OS_MACOSX) | |
| 88 bool handled = true; | 91 bool handled = true; |
| 89 IPC_BEGIN_MESSAGE_MAP(ImageTransportHelper, message) | 92 IPC_BEGIN_MESSAGE_MAP(ImageTransportHelper, message) |
| 90 #if defined(OS_MACOSX) | |
| 91 IPC_MESSAGE_HANDLER(AcceleratedSurfaceMsg_BufferPresented, | 93 IPC_MESSAGE_HANDLER(AcceleratedSurfaceMsg_BufferPresented, |
| 92 OnBufferPresented) | 94 OnBufferPresented) |
| 93 #endif | |
| 94 IPC_MESSAGE_HANDLER(AcceleratedSurfaceMsg_WakeUpGpu, OnWakeUpGpu); | |
| 95 IPC_MESSAGE_UNHANDLED(handled = false) | 95 IPC_MESSAGE_UNHANDLED(handled = false) |
| 96 IPC_END_MESSAGE_MAP() | 96 IPC_END_MESSAGE_MAP() |
| 97 return handled; | 97 return handled; |
| 98 #else | |
| 99 return false; | |
|
no sievers
2015/09/23 19:32:33
NOTREACHED() even?
piman
2015/09/23 22:32:32
Good idea, done.
| |
| 100 #endif | |
| 98 } | 101 } |
| 99 | 102 |
| 100 #if defined(OS_MACOSX) | 103 #if defined(OS_MACOSX) |
| 101 void ImageTransportHelper::SendAcceleratedSurfaceBuffersSwapped( | 104 void ImageTransportHelper::SendAcceleratedSurfaceBuffersSwapped( |
| 102 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params) { | 105 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params) { |
| 103 // TRACE_EVENT for gpu tests: | 106 // TRACE_EVENT for gpu tests: |
| 104 TRACE_EVENT_INSTANT2("test_gpu", "SwapBuffers", | 107 TRACE_EVENT_INSTANT2("test_gpu", "SwapBuffers", |
| 105 TRACE_EVENT_SCOPE_THREAD, | 108 TRACE_EVENT_SCOPE_THREAD, |
| 106 "GLImpl", static_cast<int>(gfx::GetGLImplementation()), | 109 "GLImpl", static_cast<int>(gfx::GetGLImplementation()), |
| 107 "width", params.size.width()); | 110 "width", params.size.width()); |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 137 return stub_->decoder(); | 140 return stub_->decoder(); |
| 138 } | 141 } |
| 139 | 142 |
| 140 #if defined(OS_MACOSX) | 143 #if defined(OS_MACOSX) |
| 141 void ImageTransportHelper::OnBufferPresented( | 144 void ImageTransportHelper::OnBufferPresented( |
| 142 const AcceleratedSurfaceMsg_BufferPresented_Params& params) { | 145 const AcceleratedSurfaceMsg_BufferPresented_Params& params) { |
| 143 surface_->OnBufferPresented(params); | 146 surface_->OnBufferPresented(params); |
| 144 } | 147 } |
| 145 #endif | 148 #endif |
| 146 | 149 |
| 147 void ImageTransportHelper::OnWakeUpGpu() { | |
| 148 surface_->WakeUpGpu(); | |
| 149 } | |
| 150 | |
| 151 void ImageTransportHelper::Resize(gfx::Size size, float scale_factor) { | 150 void ImageTransportHelper::Resize(gfx::Size size, float scale_factor) { |
| 152 surface_->OnResize(size, scale_factor); | 151 surface_->OnResize(size, scale_factor); |
| 153 | 152 |
| 154 #if defined(OS_ANDROID) | 153 #if defined(OS_ANDROID) |
| 155 manager_->gpu_memory_manager()->ScheduleManage( | 154 manager_->gpu_memory_manager()->ScheduleManage( |
| 156 GpuMemoryManager::kScheduleManageNow); | 155 GpuMemoryManager::kScheduleManageNow); |
| 157 #endif | 156 #endif |
| 158 } | 157 } |
| 159 | 158 |
| 160 void ImageTransportHelper::SetLatencyInfo( | 159 void ImageTransportHelper::SetLatencyInfo( |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 273 | 272 |
| 274 void PassThroughImageTransportSurface::OnResize(gfx::Size size, | 273 void PassThroughImageTransportSurface::OnResize(gfx::Size size, |
| 275 float scale_factor) { | 274 float scale_factor) { |
| 276 Resize(size); | 275 Resize(size); |
| 277 } | 276 } |
| 278 | 277 |
| 279 gfx::Size PassThroughImageTransportSurface::GetSize() { | 278 gfx::Size PassThroughImageTransportSurface::GetSize() { |
| 280 return GLSurfaceAdapter::GetSize(); | 279 return GLSurfaceAdapter::GetSize(); |
| 281 } | 280 } |
| 282 | 281 |
| 283 void PassThroughImageTransportSurface::WakeUpGpu() { | |
| 284 NOTREACHED(); | |
| 285 } | |
| 286 | |
| 287 PassThroughImageTransportSurface::~PassThroughImageTransportSurface() {} | 282 PassThroughImageTransportSurface::~PassThroughImageTransportSurface() {} |
| 288 | 283 |
| 289 void PassThroughImageTransportSurface::SendVSyncUpdateIfAvailable() { | 284 void PassThroughImageTransportSurface::SendVSyncUpdateIfAvailable() { |
| 290 gfx::VSyncProvider* vsync_provider = GetVSyncProvider(); | 285 gfx::VSyncProvider* vsync_provider = GetVSyncProvider(); |
| 291 if (vsync_provider) { | 286 if (vsync_provider) { |
| 292 vsync_provider->GetVSyncParameters( | 287 vsync_provider->GetVSyncParameters( |
| 293 base::Bind(&GpuCommandBufferStub::SendUpdateVSyncParameters, | 288 base::Bind(&GpuCommandBufferStub::SendUpdateVSyncParameters, |
| 294 helper_->stub()->AsWeakPtr())); | 289 helper_->stub()->AsWeakPtr())); |
| 295 } | 290 } |
| 296 } | 291 } |
| 297 | 292 |
| 298 } // namespace content | 293 } // namespace content |
| OLD | NEW |