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

Side by Side Diff: services/ui/gpu/mus_gpu_memory_buffer_manager.cc

Issue 2281583003: services/ui: Split GpuServiceInternal into gpu vs. ws pieces. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@DONE_2016.08.24_mus-ws-gpu-refactor
Patch Set: tot merge Created 4 years, 3 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
« no previous file with comments | « services/ui/gpu/mus_gpu_memory_buffer_manager.h ('k') | services/ui/public/cpp/gpu_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 "services/ui/gpu/mus_gpu_memory_buffer_manager.h"
6
7 #include "base/logging.h"
8 #include "gpu/ipc/client/gpu_memory_buffer_impl.h"
9 #include "gpu/ipc/client/gpu_memory_buffer_impl_shared_memory.h"
10 #include "gpu/ipc/common/gpu_memory_buffer_support.h"
11 #include "gpu/ipc/service/gpu_memory_buffer_factory.h"
12 #include "services/ui/common/generic_shared_memory_id_generator.h"
13 #include "services/ui/gpu/gpu_service_internal.h"
14
15 namespace ui {
16
17 namespace {
18
19 MusGpuMemoryBufferManager* g_gpu_memory_buffer_manager = nullptr;
20
21 bool IsNativeGpuMemoryBufferFactoryConfigurationSupported(
22 gfx::BufferFormat format,
23 gfx::BufferUsage usage) {
24 switch (gpu::GetNativeGpuMemoryBufferType()) {
25 case gfx::SHARED_MEMORY_BUFFER:
26 return false;
27 case gfx::IO_SURFACE_BUFFER:
28 case gfx::SURFACE_TEXTURE_BUFFER:
29 case gfx::OZONE_NATIVE_PIXMAP:
30 return gpu::IsNativeGpuMemoryBufferConfigurationSupported(format, usage);
31 default:
32 NOTREACHED();
33 return false;
34 }
35 }
36 }
37
38 MusGpuMemoryBufferManager* MusGpuMemoryBufferManager::current() {
39 return g_gpu_memory_buffer_manager;
40 }
41
42 MusGpuMemoryBufferManager::MusGpuMemoryBufferManager(
43 GpuServiceInternal* gpu_service,
44 int client_id)
45 : gpu_service_(gpu_service), client_id_(client_id), weak_factory_(this) {
46 DCHECK(!g_gpu_memory_buffer_manager);
47 g_gpu_memory_buffer_manager = this;
48 }
49
50 MusGpuMemoryBufferManager::~MusGpuMemoryBufferManager() {
51 g_gpu_memory_buffer_manager = nullptr;
52 }
53
54 std::unique_ptr<gfx::GpuMemoryBuffer>
55 MusGpuMemoryBufferManager::AllocateGpuMemoryBuffer(
56 const gfx::Size& size,
57 gfx::BufferFormat format,
58 gfx::BufferUsage usage,
59 gpu::SurfaceHandle surface_handle) {
60 gfx::GpuMemoryBufferId id = GetNextGenericSharedMemoryId();
61 const bool is_native =
62 IsNativeGpuMemoryBufferFactoryConfigurationSupported(format, usage);
63 if (is_native) {
64 gfx::GpuMemoryBufferHandle handle =
65 gpu_service_->gpu_memory_buffer_factory()->CreateGpuMemoryBuffer(
66 id, size, format, usage, client_id_, surface_handle);
67 if (handle.is_null())
68 return nullptr;
69 return gpu::GpuMemoryBufferImpl::CreateFromHandle(
70 handle, size, format, usage,
71 base::Bind(&MusGpuMemoryBufferManager::DestroyGpuMemoryBuffer,
72 weak_factory_.GetWeakPtr(), id, client_id_, is_native));
73 }
74
75 DCHECK(gpu::GpuMemoryBufferImplSharedMemory::IsUsageSupported(usage))
76 << static_cast<int>(usage);
77 return gpu::GpuMemoryBufferImplSharedMemory::Create(
78 id, size, format,
79 base::Bind(&MusGpuMemoryBufferManager::DestroyGpuMemoryBuffer,
80 weak_factory_.GetWeakPtr(), id, client_id_, is_native));
81 }
82
83 std::unique_ptr<gfx::GpuMemoryBuffer>
84 MusGpuMemoryBufferManager::CreateGpuMemoryBufferFromHandle(
85 const gfx::GpuMemoryBufferHandle& handle,
86 const gfx::Size& size,
87 gfx::BufferFormat format) {
88 NOTIMPLEMENTED();
89 return nullptr;
90 }
91
92 gfx::GpuMemoryBuffer*
93 MusGpuMemoryBufferManager::GpuMemoryBufferFromClientBuffer(
94 ClientBuffer buffer) {
95 return gpu::GpuMemoryBufferImpl::FromClientBuffer(buffer);
96 }
97
98 void MusGpuMemoryBufferManager::SetDestructionSyncToken(
99 gfx::GpuMemoryBuffer* buffer,
100 const gpu::SyncToken& sync_token) {
101 static_cast<gpu::GpuMemoryBufferImpl*>(buffer)->set_destruction_sync_token(
102 sync_token);
103 }
104
105 void MusGpuMemoryBufferManager::DestroyGpuMemoryBuffer(
106 gfx::GpuMemoryBufferId id,
107 int client_id,
108 bool is_native,
109 const gpu::SyncToken& sync_token) {
110 if (is_native) {
111 gpu_service_->gpu_channel_manager()->DestroyGpuMemoryBuffer(id, client_id,
112 sync_token);
113 }
114 }
115
116 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/gpu/mus_gpu_memory_buffer_manager.h ('k') | services/ui/public/cpp/gpu_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698