diff options
author | ericrk <ericrk@chromium.org> | 2015-08-17 07:22:37 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-08-17 14:23:13 +0000 |
commit | c9984ebe42daab4cd51fb928c32d7d1f4f14a9c7 (patch) | |
tree | 04dc6d445304b474a83e3137d3523447ab0bed9c /ui | |
parent | a814ea088d8c8f85485b3588996605767081cd79 (diff) | |
download | chromium_src-c9984ebe42daab4cd51fb928c32d7d1f4f14a9c7.zip chromium_src-c9984ebe42daab4cd51fb928c32d7d1f4f14a9c7.tar.gz chromium_src-c9984ebe42daab4cd51fb928c32d7d1f4f14a9c7.tar.bz2 |
Add GenericSharedMemoryId and use w/ GpuMemoryBuffer
Adds a GenericSharedMemoryId type which will be used to track various types of shared memory (SharedBitmap, IOSurface, base::SharedMemory).
Wire up GpuMemoryBufferManager so that GpuMemoryBufferId is just a typedef of this type, setting up for further integration in the future.
Note regarding message changes - We needed a way for all GenericSharedMemoryIds used by a process to be unique. Currently a renderer process sometimes internally allocates shared memory and sometimes asks the browser process to do so. In order to allow for consistent naming, we cause the Renderer process to provide an ID to the browser when asking the browser to allocate on its behalf.
+tsepez for message changes.
+piman for content/gpu changes
+danakj/reveman for other changes.
TBR=sky@chromium.org
BUG=512534
CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel
Review URL: https://codereview.chromium.org/1280513002
Cr-Commit-Position: refs/heads/master@{#343677}
Diffstat (limited to 'ui')
-rw-r--r-- | ui/gfx/BUILD.gn | 2 | ||||
-rw-r--r-- | ui/gfx/generic_shared_memory_id.cc | 20 | ||||
-rw-r--r-- | ui/gfx/generic_shared_memory_id.h | 54 | ||||
-rw-r--r-- | ui/gfx/gfx.gyp | 2 | ||||
-rw-r--r-- | ui/gfx/gpu_memory_buffer.cc | 11 | ||||
-rw-r--r-- | ui/gfx/gpu_memory_buffer.h | 3 |
6 files changed, 85 insertions, 7 deletions
diff --git a/ui/gfx/BUILD.gn b/ui/gfx/BUILD.gn index 4cd3576..32fc674 100644 --- a/ui/gfx/BUILD.gn +++ b/ui/gfx/BUILD.gn @@ -103,6 +103,8 @@ component("gfx") { "font_render_params_win.cc", "gdi_util.cc", "gdi_util.h", + "generic_shared_memory_id.cc", + "generic_shared_memory_id.h", "gfx_paths.cc", "gfx_paths.h", "gpu_memory_buffer.cc", diff --git a/ui/gfx/generic_shared_memory_id.cc b/ui/gfx/generic_shared_memory_id.cc new file mode 100644 index 0000000..33a5ef0 --- /dev/null +++ b/ui/gfx/generic_shared_memory_id.cc @@ -0,0 +1,20 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/gfx/generic_shared_memory_id.h" + +#include "base/format_macros.h" +#include "base/strings/stringprintf.h" + +namespace gfx { + +base::trace_event::MemoryAllocatorDumpGuid GetGenericSharedMemoryGUIDForTracing( + uint64_t tracing_process_id, + GenericSharedMemoryId generic_shared_memory_id) { + return base::trace_event::MemoryAllocatorDumpGuid( + base::StringPrintf("genericsharedmemory-x-process/%" PRIx64 "/%d", + tracing_process_id, generic_shared_memory_id.id)); +} + +} // namespace gfx diff --git a/ui/gfx/generic_shared_memory_id.h b/ui/gfx/generic_shared_memory_id.h new file mode 100644 index 0000000..9aa226f --- /dev/null +++ b/ui/gfx/generic_shared_memory_id.h @@ -0,0 +1,54 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_GFX_GENERIC_SHARED_MEMORY_ID_H_ +#define UI_GFX_GENERIC_SHARED_MEMORY_ID_H_ + +#include "base/trace_event/memory_allocator_dump.h" +#include "ui/gfx/gfx_export.h" + +namespace gfx { + +// Defines an ID type which is used across all types of shared memory +// allocations in content/. This ID type is in ui/gfx, as components outside +// content/ may need to hold an ID (but should not generate one). +class GFX_EXPORT GenericSharedMemoryId { + public: + int id; + + // Invalid ID is -1 to match semantics of base::StaticAtomicSequenceNumber. + GenericSharedMemoryId() : id(-1) {} + explicit GenericSharedMemoryId(int id) : id(id) {} + GenericSharedMemoryId(const GenericSharedMemoryId& other) = default; + GenericSharedMemoryId& operator=(const GenericSharedMemoryId& other) = + default; + + bool operator==(const GenericSharedMemoryId& other) const { + return id == other.id; + } + + bool operator<(const GenericSharedMemoryId& other) const { + return id < other.id; + } +}; + +// Generates GUID which can be used to trace shared memory using its +// GenericSharedMemoryId. +GFX_EXPORT base::trace_event::MemoryAllocatorDumpGuid +GetGenericSharedMemoryGUIDForTracing( + uint64_t tracing_process_id, + GenericSharedMemoryId generic_shared_memory_id); + +} // namespace gfx + +namespace BASE_HASH_NAMESPACE { +template <> +struct hash<gfx::GenericSharedMemoryId> { + size_t operator()(gfx::GenericSharedMemoryId key) const { + return BASE_HASH_NAMESPACE::hash<int>()(key.id); + } +}; +} // namespace BASE_HASH_NAMESPACE + +#endif // UI_GFX_GENERIC_SHARED_MEMORY_ID_H_ diff --git a/ui/gfx/gfx.gyp b/ui/gfx/gfx.gyp index d741b0e..98575ae 100644 --- a/ui/gfx/gfx.gyp +++ b/ui/gfx/gfx.gyp @@ -173,6 +173,8 @@ 'font_render_params_linux.cc', 'font_render_params_mac.cc', 'font_render_params_win.cc', + 'generic_shared_memory_id.cc', + 'generic_shared_memory_id.h', 'gfx_export.h', 'gfx_paths.cc', 'gfx_paths.h', diff --git a/ui/gfx/gpu_memory_buffer.cc b/ui/gfx/gpu_memory_buffer.cc index 44fcd31..9ccd410 100644 --- a/ui/gfx/gpu_memory_buffer.cc +++ b/ui/gfx/gpu_memory_buffer.cc @@ -4,17 +4,16 @@ #include "ui/gfx/gpu_memory_buffer.h" -#include "base/format_macros.h" -#include "base/strings/stringprintf.h" - namespace gfx { base::trace_event::MemoryAllocatorDumpGuid GetGpuMemoryBufferGUIDForTracing( uint64 tracing_process_id, GpuMemoryBufferId buffer_id) { - return base::trace_event::MemoryAllocatorDumpGuid( - base::StringPrintf("gpumemorybuffer-x-process/%" PRIx64 "/%d", - tracing_process_id, buffer_id)); + // TODO(ericrk): Currently this function just wraps + // GetGenericSharedMemoryGUIDForTracing, we may want to special case this if + // the GPU memory buffer is not backed by shared memory. + return gfx::GetGenericSharedMemoryGUIDForTracing(tracing_process_id, + buffer_id); } GpuMemoryBufferHandle::GpuMemoryBufferHandle() diff --git a/ui/gfx/gpu_memory_buffer.h b/ui/gfx/gpu_memory_buffer.h index 263a0ef..1234dc2 100644 --- a/ui/gfx/gpu_memory_buffer.h +++ b/ui/gfx/gpu_memory_buffer.h @@ -9,6 +9,7 @@ #include "base/trace_event/memory_dump_manager.h" #include "build/build_config.h" #include "ui/gfx/buffer_types.h" +#include "ui/gfx/generic_shared_memory_id.h" #include "ui/gfx/gfx_export.h" extern "C" typedef struct _ClientBuffer* ClientBuffer; @@ -24,7 +25,7 @@ enum GpuMemoryBufferType { GPU_MEMORY_BUFFER_TYPE_LAST = OZONE_NATIVE_PIXMAP }; -using GpuMemoryBufferId = int32; +using GpuMemoryBufferId = gfx::GenericSharedMemoryId; struct GFX_EXPORT GpuMemoryBufferHandle { GpuMemoryBufferHandle(); |