OLD | NEW |
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "gpu/skia_runner/in_process_graphics_system.h" | 5 #include "gpu/skia_runner/in_process_graphics_system.h" |
6 | 6 |
7 #include <iostream> | 7 #include <iostream> |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/memory/discardable_memory.h" | 10 #include "base/memory/discardable_memory.h" |
11 #include "base/memory/discardable_memory_allocator.h" | 11 #include "base/memory/discardable_memory_allocator.h" |
12 #include "base/thread_task_runner_handle.h" | 12 #include "base/thread_task_runner_handle.h" |
| 13 #include "base/trace_event/memory_allocator_dump.h" |
| 14 #include "base/trace_event/memory_dump_manager.h" |
| 15 #include "base/trace_event/process_memory_dump.h" |
13 #include "gpu/command_buffer/client/gles2_implementation.h" | 16 #include "gpu/command_buffer/client/gles2_implementation.h" |
14 #include "gpu/command_buffer/client/gles2_lib.h" | 17 #include "gpu/command_buffer/client/gles2_lib.h" |
15 #include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h" | 18 #include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h" |
16 #include "third_party/khronos/GLES2/gl2.h" | 19 #include "third_party/khronos/GLES2/gl2.h" |
17 #include "third_party/skia/include/gpu/gl/GrGLInterface.h" | 20 #include "third_party/skia/include/gpu/gl/GrGLInterface.h" |
18 | 21 |
19 namespace { | 22 namespace { |
20 | 23 |
21 // TODO(hendrikw): Replace TestDiscardableMemoryAllocator and move to base? | 24 // TODO(hendrikw): Replace TestDiscardableMemoryAllocator and move to base? |
22 class NonDiscardableMemory : public base::DiscardableMemory { | 25 class NonDiscardableMemory : public base::DiscardableMemory { |
23 public: | 26 public: |
24 explicit NonDiscardableMemory(size_t size) : data_(new uint8_t[size]) {} | 27 explicit NonDiscardableMemory(size_t size) |
| 28 : data_(new uint8_t[size]), size_(size) {} |
25 bool Lock() override { return false; } | 29 bool Lock() override { return false; } |
26 void Unlock() override {} | 30 void Unlock() override {} |
27 void* data() const override { return data_.get(); } | 31 void* data() const override { return data_.get(); } |
28 | 32 |
| 33 base::trace_event::MemoryAllocatorDump* CreateMemoryAllocatorDump( |
| 34 const char* name, |
| 35 base::trace_event::ProcessMemoryDump* pmd) const override { |
| 36 base::trace_event::MemoryAllocatorDump* dump = |
| 37 pmd->CreateAllocatorDump(name); |
| 38 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, |
| 39 base::trace_event::MemoryAllocatorDump::kUnitsBytes, size_); |
| 40 |
| 41 // Memory is allocated from system allocator (malloc). |
| 42 pmd->AddSuballocation(dump->guid(), |
| 43 base::trace_event::MemoryDumpManager::GetInstance() |
| 44 ->system_allocator_pool_name()); |
| 45 return dump; |
| 46 } |
| 47 |
29 private: | 48 private: |
30 scoped_ptr<uint8_t[]> data_; | 49 scoped_ptr<uint8_t[]> data_; |
| 50 size_t size_; |
31 }; | 51 }; |
32 | 52 |
33 class NonDiscardableMemoryAllocator : public base::DiscardableMemoryAllocator { | 53 class NonDiscardableMemoryAllocator : public base::DiscardableMemoryAllocator { |
34 public: | 54 public: |
35 // Overridden from DiscardableMemoryAllocator: | 55 // Overridden from DiscardableMemoryAllocator: |
36 scoped_ptr<base::DiscardableMemory> AllocateLockedDiscardableMemory( | 56 scoped_ptr<base::DiscardableMemory> AllocateLockedDiscardableMemory( |
37 size_t size) override { | 57 size_t size) override { |
38 return make_scoped_ptr(new NonDiscardableMemory(size)); | 58 return make_scoped_ptr(new NonDiscardableMemory(size)); |
39 } | 59 } |
40 }; | 60 }; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 make_scoped_ptr(gpu::GLInProcessContext::Create( | 161 make_scoped_ptr(gpu::GLInProcessContext::Create( |
142 nullptr, nullptr, is_offscreen, gfx::kNullAcceleratedWidget, | 162 nullptr, nullptr, is_offscreen, gfx::kNullAcceleratedWidget, |
143 gfx::Size(1, 1), nullptr, share_resources, attribs, gpu_preference, | 163 gfx::Size(1, 1), nullptr, share_resources, attribs, gpu_preference, |
144 gpu::GLInProcessContextSharedMemoryLimits(), nullptr, nullptr)); | 164 gpu::GLInProcessContextSharedMemoryLimits(), nullptr, nullptr)); |
145 | 165 |
146 DCHECK(context); | 166 DCHECK(context); |
147 return context.Pass(); | 167 return context.Pass(); |
148 } | 168 } |
149 | 169 |
150 } // namespace skia_runner | 170 } // namespace skia_runner |
OLD | NEW |