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

Side by Side Diff: components/exo/shared_memory.cc

Issue 2572703004: exo: Directly create GpuMemoryBufferImpl when a handle is available. (Closed)
Patch Set: fix non-ozone build Created 4 years 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
« components/exo/display.cc ('K') | « components/exo/display.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/exo/shared_memory.h" 5 #include "components/exo/shared_memory.h"
6 6
7 #include <GLES2/gl2extchromium.h> 7 #include <GLES2/gl2extchromium.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/trace_event/trace_event.h" 14 #include "base/trace_event/trace_event.h"
15 #include "components/exo/buffer.h" 15 #include "components/exo/buffer.h"
16 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" 16 #include "gpu/ipc/client/gpu_memory_buffer_impl.h"
17 #include "third_party/khronos/GLES2/gl2.h" 17 #include "third_party/khronos/GLES2/gl2.h"
18 #include "ui/aura/env.h"
19 #include "ui/compositor/compositor.h" 18 #include "ui/compositor/compositor.h"
20 #include "ui/gfx/buffer_format_util.h" 19 #include "ui/gfx/buffer_format_util.h"
21 #include "ui/gfx/geometry/size.h" 20 #include "ui/gfx/geometry/size.h"
22 #include "ui/gfx/gpu_memory_buffer.h" 21 #include "ui/gfx/gpu_memory_buffer.h"
23 22
24 namespace exo { 23 namespace exo {
25 namespace { 24 namespace {
26 25
27 bool IsSupportedFormat(gfx::BufferFormat format) { 26 bool IsSupportedFormat(gfx::BufferFormat format) {
28 return format == gfx::BufferFormat::RGBX_8888 || 27 return format == gfx::BufferFormat::RGBX_8888 ||
29 format == gfx::BufferFormat::RGBA_8888 || 28 format == gfx::BufferFormat::RGBA_8888 ||
30 format == gfx::BufferFormat::BGRX_8888 || 29 format == gfx::BufferFormat::BGRX_8888 ||
31 format == gfx::BufferFormat::BGRA_8888; 30 format == gfx::BufferFormat::BGRA_8888;
32 } 31 }
33 32
33 void DoNothing(const gpu::SyncToken& sync) {}
34
34 } // namespace 35 } // namespace
35 36
36 //////////////////////////////////////////////////////////////////////////////// 37 ////////////////////////////////////////////////////////////////////////////////
37 // SharedMemory, public: 38 // SharedMemory, public:
38 39
39 SharedMemory::SharedMemory(const base::SharedMemoryHandle& handle) 40 SharedMemory::SharedMemory(const base::SharedMemoryHandle& handle)
40 : shared_memory_(handle, true /* read-only */) {} 41 : shared_memory_(handle, true /* read-only */) {}
41 42
42 SharedMemory::~SharedMemory() {} 43 SharedMemory::~SharedMemory() {}
43 44
(...skipping 18 matching lines...) Expand all
62 << stride; 63 << stride;
63 return nullptr; 64 return nullptr;
64 } 65 }
65 66
66 gfx::GpuMemoryBufferHandle handle; 67 gfx::GpuMemoryBufferHandle handle;
67 handle.type = gfx::SHARED_MEMORY_BUFFER; 68 handle.type = gfx::SHARED_MEMORY_BUFFER;
68 handle.handle = base::SharedMemory::DuplicateHandle(shared_memory_.handle()); 69 handle.handle = base::SharedMemory::DuplicateHandle(shared_memory_.handle());
69 handle.offset = offset; 70 handle.offset = offset;
70 handle.stride = stride; 71 handle.stride = stride;
71 72
72 std::unique_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer = 73 auto gpu_memory_buffer = gpu::GpuMemoryBufferImpl::CreateFromHandle(
reveman 2016/12/13 21:30:53 ditto. avoid auto and use gpu::GpuMemoryBufferImpl
sadrul 2016/12/14 01:41:30 Done.
73 aura::Env::GetInstance() 74 handle, size, format, gfx::BufferUsage::GPU_READ, base::Bind(&DoNothing));
74 ->context_factory()
75 ->GetGpuMemoryBufferManager()
76 ->CreateGpuMemoryBufferFromHandle(handle, size, format);
77 if (!gpu_memory_buffer) { 75 if (!gpu_memory_buffer) {
78 LOG(ERROR) << "Failed to create GpuMemoryBuffer from handle"; 76 LOG(ERROR) << "Failed to create GpuMemoryBuffer from handle";
79 return nullptr; 77 return nullptr;
80 } 78 }
81 79
82 // Zero-copy doesn't provide a benefit in the case of shared memory as an 80 // Zero-copy doesn't provide a benefit in the case of shared memory as an
83 // implicit copy is required when trying to use these buffers as zero-copy 81 // implicit copy is required when trying to use these buffers as zero-copy
84 // buffers. Making the copy explicit allows the buffer to be reused earlier. 82 // buffers. Making the copy explicit allows the buffer to be reused earlier.
85 bool use_zero_copy = false; 83 bool use_zero_copy = false;
86 84
87 return base::MakeUnique<Buffer>( 85 return base::MakeUnique<Buffer>(
88 std::move(gpu_memory_buffer), GL_TEXTURE_2D, 86 std::move(gpu_memory_buffer), GL_TEXTURE_2D,
89 // COMMANDS_ISSUED queries are sufficient for shared memory 87 // COMMANDS_ISSUED queries are sufficient for shared memory
90 // buffers as binding to texture is implemented using a call to 88 // buffers as binding to texture is implemented using a call to
91 // glTexImage2D and the buffer can be reused as soon as that 89 // glTexImage2D and the buffer can be reused as soon as that
92 // command has been issued. 90 // command has been issued.
93 GL_COMMANDS_ISSUED_CHROMIUM, use_zero_copy, 91 GL_COMMANDS_ISSUED_CHROMIUM, use_zero_copy,
94 false /* is_overlay_candidate */); 92 false /* is_overlay_candidate */);
95 } 93 }
96 94
97 } // namespace exo 95 } // namespace exo
OLDNEW
« components/exo/display.cc ('K') | « components/exo/display.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698