OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #if defined(ENABLE_GPU) | 5 #if defined(ENABLE_GPU) |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
11 #include "base/shared_memory.h" | 11 #include "base/shared_memory.h" |
12 #include "base/time.h" | 12 #include "base/time.h" |
13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
14 #include "content/common/gpu/gpu_channel.h" | 14 #include "content/common/gpu/gpu_channel.h" |
15 #include "content/common/gpu/gpu_channel_manager.h" | 15 #include "content/common/gpu/gpu_channel_manager.h" |
16 #include "content/common/gpu/gpu_command_buffer_stub.h" | 16 #include "content/common/gpu/gpu_command_buffer_stub.h" |
17 #include "content/common/gpu/gpu_memory_manager.h" | 17 #include "content/common/gpu/gpu_memory_manager.h" |
18 #include "content/common/gpu/gpu_messages.h" | 18 #include "content/common/gpu/gpu_messages.h" |
19 #include "content/common/gpu/gpu_watchdog.h" | 19 #include "content/common/gpu/gpu_watchdog.h" |
20 #include "content/common/gpu/image_transport_surface.h" | 20 #include "content/common/gpu/image_transport_surface.h" |
21 #include "content/common/gpu/media/gpu_video_decode_accelerator.h" | 21 #include "content/common/gpu/media/gpu_video_decode_accelerator.h" |
22 #include "content/common/gpu/sync_point_manager.h" | 22 #include "content/common/gpu/sync_point_manager.h" |
23 #include "content/public/common/content_client.h" | 23 #include "content/public/common/content_client.h" |
24 #include "gpu/command_buffer/common/constants.h" | 24 #include "gpu/command_buffer/common/constants.h" |
25 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 25 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
| 26 #include "gpu/command_buffer/service/memory_tracking.h" |
26 #include "net/disk_cache/hash.h" | 27 #include "net/disk_cache/hash.h" |
27 #include "ui/gl/gl_bindings.h" | 28 #include "ui/gl/gl_bindings.h" |
28 #include "ui/gl/gl_switches.h" | 29 #include "ui/gl/gl_switches.h" |
29 | 30 |
30 #if defined(OS_WIN) | 31 #if defined(OS_WIN) |
31 #include "content/public/common/sandbox_init.h" | 32 #include "content/public/common/sandbox_init.h" |
32 #endif | 33 #endif |
33 | 34 |
34 namespace { | 35 namespace { |
35 | 36 |
| 37 // The GpuCommandBufferMemoryTracker class provides a bridge between the |
| 38 // ContextGroup's memory type managers and the GpuMemoryManager class. |
| 39 class GpuCommandBufferMemoryTracker : public gpu::gles2::MemoryTracker { |
| 40 public: |
| 41 GpuCommandBufferMemoryTracker(GpuMemoryManager* gpu_memory_manager) |
| 42 : gpu_memory_manager_(gpu_memory_manager) {} |
| 43 void TrackMemoryAllocatedChange(size_t old_size, size_t new_size) { |
| 44 gpu_memory_manager_->TrackMemoryAllocatedChange(old_size, new_size); |
| 45 } |
| 46 |
| 47 private: |
| 48 GpuMemoryManager* gpu_memory_manager_; |
| 49 }; |
| 50 |
36 // FastSetActiveURL will shortcut the expensive call to SetActiveURL when the | 51 // FastSetActiveURL will shortcut the expensive call to SetActiveURL when the |
37 // url_hash matches. | 52 // url_hash matches. |
38 void FastSetActiveURL(const GURL& url, size_t url_hash) { | 53 void FastSetActiveURL(const GURL& url, size_t url_hash) { |
39 // Leave the previously set URL in the empty case -- empty URLs are given by | 54 // Leave the previously set URL in the empty case -- empty URLs are given by |
40 // WebKitPlatformSupportImpl::createOffscreenGraphicsContext3D. Hopefully the | 55 // WebKitPlatformSupportImpl::createOffscreenGraphicsContext3D. Hopefully the |
41 // onscreen context URL was set previously and will show up even when a crash | 56 // onscreen context URL was set previously and will show up even when a crash |
42 // occurs during offscreen command processing. | 57 // occurs during offscreen command processing. |
43 if (url.is_empty()) | 58 if (url.is_empty()) |
44 return; | 59 return; |
45 static size_t g_last_url_hash = 0; | 60 static size_t g_last_url_hash = 0; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 watchdog_(watchdog), | 111 watchdog_(watchdog), |
97 sync_point_wait_count_(0), | 112 sync_point_wait_count_(0), |
98 delayed_work_scheduled_(false), | 113 delayed_work_scheduled_(false), |
99 active_url_(active_url) { | 114 active_url_(active_url) { |
100 active_url_hash_ = | 115 active_url_hash_ = |
101 disk_cache::Hash(active_url.possibly_invalid_spec()); | 116 disk_cache::Hash(active_url.possibly_invalid_spec()); |
102 FastSetActiveURL(active_url_, active_url_hash_); | 117 FastSetActiveURL(active_url_, active_url_hash_); |
103 if (share_group) { | 118 if (share_group) { |
104 context_group_ = share_group->context_group_; | 119 context_group_ = share_group->context_group_; |
105 } else { | 120 } else { |
106 context_group_ = new gpu::gles2::ContextGroup(mailbox_manager, true); | 121 context_group_ = new gpu::gles2::ContextGroup( |
| 122 mailbox_manager, |
| 123 new GpuCommandBufferMemoryTracker( |
| 124 channel->gpu_channel_manager()->gpu_memory_manager()), |
| 125 true); |
107 } | 126 } |
108 if (surface_id != 0) | 127 if (surface_id != 0) |
109 surface_state_.reset(new GpuCommandBufferStubBase::SurfaceState( | 128 surface_state_.reset(new GpuCommandBufferStubBase::SurfaceState( |
110 surface_id, true, base::TimeTicks::Now())); | 129 surface_id, true, base::TimeTicks::Now())); |
111 if (handle_.sync_point) | 130 if (handle_.sync_point) |
112 OnWaitSyncPoint(handle_.sync_point); | 131 OnWaitSyncPoint(handle_.sync_point); |
113 } | 132 } |
114 | 133 |
115 GpuCommandBufferStub::~GpuCommandBufferStub() { | 134 GpuCommandBufferStub::~GpuCommandBufferStub() { |
116 Destroy(); | 135 Destroy(); |
(...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
797 const GpuMemoryAllocation& allocation) { | 816 const GpuMemoryAllocation& allocation) { |
798 Send(new GpuCommandBufferMsg_SetMemoryAllocation(route_id_, allocation)); | 817 Send(new GpuCommandBufferMsg_SetMemoryAllocation(route_id_, allocation)); |
799 // This can be called outside of OnMessageReceived, so the context needs to be | 818 // This can be called outside of OnMessageReceived, so the context needs to be |
800 // made current before calling methods on the surface. | 819 // made current before calling methods on the surface. |
801 if (!surface_ || !MakeCurrent()) | 820 if (!surface_ || !MakeCurrent()) |
802 return; | 821 return; |
803 surface_->SetFrontbufferAllocation(allocation.suggest_have_frontbuffer); | 822 surface_->SetFrontbufferAllocation(allocation.suggest_have_frontbuffer); |
804 } | 823 } |
805 | 824 |
806 #endif // defined(ENABLE_GPU) | 825 #endif // defined(ENABLE_GPU) |
OLD | NEW |