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

Side by Side Diff: ui/gl/gl_image_shared_memory.cc

Issue 1415723006: ui: Add RGBX_8888 buffer format. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix gles but no conversion needed case Created 5 years, 1 month 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 | « ui/gl/gl_image_ref_counted_memory_unittest.cc ('k') | ui/gl/gl_image_shared_memory_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "ui/gl/gl_image_shared_memory.h" 5 #include "ui/gl/gl_image_shared_memory.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/shared_memory.h" 8 #include "base/memory/shared_memory.h"
9 #include "base/numerics/safe_math.h" 9 #include "base/numerics/safe_math.h"
10 #include "base/process/process_handle.h" 10 #include "base/process/process_handle.h"
11 #include "base/trace_event/memory_allocator_dump.h" 11 #include "base/trace_event/memory_allocator_dump.h"
12 #include "base/trace_event/memory_dump_manager.h" 12 #include "base/trace_event/memory_dump_manager.h"
13 #include "base/trace_event/process_memory_dump.h" 13 #include "base/trace_event/process_memory_dump.h"
14 #include "ui/gfx/buffer_format_util.h"
14 15
15 namespace gfx { 16 namespace gfx {
16 namespace {
17
18 // Returns true if the size is valid and false otherwise.
19 bool SizeInBytes(const Size& size, BufferFormat format, size_t* size_in_bytes) {
20 if (size.IsEmpty())
21 return false;
22
23 size_t stride_in_bytes = 0;
24 if (!GLImageMemory::StrideInBytes(size.width(), format, &stride_in_bytes))
25 return false;
26 base::CheckedNumeric<size_t> s = stride_in_bytes;
27 s *= size.height();
28 if (!s.IsValid())
29 return false;
30 *size_in_bytes = s.ValueOrDie();
31 return true;
32 }
33
34 } // namespace
35 17
36 GLImageSharedMemory::GLImageSharedMemory(const Size& size, 18 GLImageSharedMemory::GLImageSharedMemory(const Size& size,
37 unsigned internalformat) 19 unsigned internalformat)
38 : GLImageMemory(size, internalformat) {} 20 : GLImageMemory(size, internalformat) {}
39 21
40 GLImageSharedMemory::~GLImageSharedMemory() { 22 GLImageSharedMemory::~GLImageSharedMemory() {
41 DCHECK(!shared_memory_); 23 DCHECK(!shared_memory_);
42 } 24 }
43 25
44 bool GLImageSharedMemory::Initialize(const base::SharedMemoryHandle& handle, 26 bool GLImageSharedMemory::Initialize(const base::SharedMemoryHandle& handle,
45 GenericSharedMemoryId shared_memory_id, 27 GenericSharedMemoryId shared_memory_id,
46 BufferFormat format) { 28 BufferFormat format) {
47 size_t size_in_bytes; 29 size_t size_in_bytes;
48 if (!SizeInBytes(GetSize(), format, &size_in_bytes)) 30 if (!BufferSizeForBufferFormatChecked(GetSize(), format, &size_in_bytes))
49 return false; 31 return false;
50 32
51 if (!base::SharedMemory::IsHandleValid(handle)) 33 if (!base::SharedMemory::IsHandleValid(handle))
52 return false; 34 return false;
53 35
54 base::SharedMemory shared_memory(handle, true); 36 base::SharedMemory shared_memory(handle, true);
55 37
56 // Duplicate the handle. 38 // Duplicate the handle.
57 base::SharedMemoryHandle duped_shared_memory_handle; 39 base::SharedMemoryHandle duped_shared_memory_handle;
58 if (!shared_memory.ShareToProcess(base::GetCurrentProcessHandle(), 40 if (!shared_memory.ShareToProcess(base::GetCurrentProcessHandle(),
(...skipping 24 matching lines...) Expand all
83 GLImageMemory::Destroy(have_context); 65 GLImageMemory::Destroy(have_context);
84 shared_memory_.reset(); 66 shared_memory_.reset();
85 } 67 }
86 68
87 void GLImageSharedMemory::OnMemoryDump( 69 void GLImageSharedMemory::OnMemoryDump(
88 base::trace_event::ProcessMemoryDump* pmd, 70 base::trace_event::ProcessMemoryDump* pmd,
89 uint64_t process_tracing_id, 71 uint64_t process_tracing_id,
90 const std::string& dump_name) { 72 const std::string& dump_name) {
91 size_t size_in_bytes = 0; 73 size_t size_in_bytes = 0;
92 74
93 if (shared_memory_) { 75 if (shared_memory_)
94 bool result = SizeInBytes(GetSize(), format(), &size_in_bytes); 76 size_in_bytes = BufferSizeForBufferFormat(GetSize(), format());
95 DCHECK(result);
96 }
97 77
98 // Dump under "/shared_memory", as the base class may also dump to 78 // Dump under "/shared_memory", as the base class may also dump to
99 // "/texture_memory". 79 // "/texture_memory".
100 base::trace_event::MemoryAllocatorDump* dump = 80 base::trace_event::MemoryAllocatorDump* dump =
101 pmd->CreateAllocatorDump(dump_name + "/shared_memory"); 81 pmd->CreateAllocatorDump(dump_name + "/shared_memory");
102 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, 82 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
103 base::trace_event::MemoryAllocatorDump::kUnitsBytes, 83 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
104 static_cast<uint64_t>(size_in_bytes)); 84 static_cast<uint64_t>(size_in_bytes));
105 85
106 auto guid = GetGenericSharedMemoryGUIDForTracing(process_tracing_id, 86 auto guid = GetGenericSharedMemoryGUIDForTracing(process_tracing_id,
107 shared_memory_id_); 87 shared_memory_id_);
108 pmd->CreateSharedGlobalAllocatorDump(guid); 88 pmd->CreateSharedGlobalAllocatorDump(guid);
109 pmd->AddOwnershipEdge(dump->guid(), guid); 89 pmd->AddOwnershipEdge(dump->guid(), guid);
110 } 90 }
111 91
112 } // namespace gfx 92 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gl/gl_image_ref_counted_memory_unittest.cc ('k') | ui/gl/gl_image_shared_memory_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698