| 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 ~GpuCommandBufferMemoryTracker() {} |
| 49 GpuMemoryManager* gpu_memory_manager_; |
| 50 |
| 51 DISALLOW_COPY_AND_ASSIGN(GpuCommandBufferMemoryTracker); |
| 52 }; |
| 53 |
| 36 // FastSetActiveURL will shortcut the expensive call to SetActiveURL when the | 54 // FastSetActiveURL will shortcut the expensive call to SetActiveURL when the |
| 37 // url_hash matches. | 55 // url_hash matches. |
| 38 void FastSetActiveURL(const GURL& url, size_t url_hash) { | 56 void FastSetActiveURL(const GURL& url, size_t url_hash) { |
| 39 // Leave the previously set URL in the empty case -- empty URLs are given by | 57 // Leave the previously set URL in the empty case -- empty URLs are given by |
| 40 // WebKitPlatformSupportImpl::createOffscreenGraphicsContext3D. Hopefully the | 58 // WebKitPlatformSupportImpl::createOffscreenGraphicsContext3D. Hopefully the |
| 41 // onscreen context URL was set previously and will show up even when a crash | 59 // onscreen context URL was set previously and will show up even when a crash |
| 42 // occurs during offscreen command processing. | 60 // occurs during offscreen command processing. |
| 43 if (url.is_empty()) | 61 if (url.is_empty()) |
| 44 return; | 62 return; |
| 45 static size_t g_last_url_hash = 0; | 63 static size_t g_last_url_hash = 0; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 watchdog_(watchdog), | 114 watchdog_(watchdog), |
| 97 sync_point_wait_count_(0), | 115 sync_point_wait_count_(0), |
| 98 delayed_work_scheduled_(false), | 116 delayed_work_scheduled_(false), |
| 99 active_url_(active_url) { | 117 active_url_(active_url) { |
| 100 active_url_hash_ = | 118 active_url_hash_ = |
| 101 disk_cache::Hash(active_url.possibly_invalid_spec()); | 119 disk_cache::Hash(active_url.possibly_invalid_spec()); |
| 102 FastSetActiveURL(active_url_, active_url_hash_); | 120 FastSetActiveURL(active_url_, active_url_hash_); |
| 103 if (share_group) { | 121 if (share_group) { |
| 104 context_group_ = share_group->context_group_; | 122 context_group_ = share_group->context_group_; |
| 105 } else { | 123 } else { |
| 106 context_group_ = new gpu::gles2::ContextGroup(mailbox_manager, true); | 124 context_group_ = new gpu::gles2::ContextGroup( |
| 125 mailbox_manager, |
| 126 new GpuCommandBufferMemoryTracker( |
| 127 channel->gpu_channel_manager()->gpu_memory_manager()), |
| 128 true); |
| 107 } | 129 } |
| 108 if (surface_id != 0) | 130 if (surface_id != 0) |
| 109 surface_state_.reset(new GpuCommandBufferStubBase::SurfaceState( | 131 surface_state_.reset(new GpuCommandBufferStubBase::SurfaceState( |
| 110 surface_id, true, base::TimeTicks::Now())); | 132 surface_id, true, base::TimeTicks::Now())); |
| 111 if (handle_.sync_point) | 133 if (handle_.sync_point) |
| 112 OnWaitSyncPoint(handle_.sync_point); | 134 OnWaitSyncPoint(handle_.sync_point); |
| 113 } | 135 } |
| 114 | 136 |
| 115 GpuCommandBufferStub::~GpuCommandBufferStub() { | 137 GpuCommandBufferStub::~GpuCommandBufferStub() { |
| 116 Destroy(); | 138 Destroy(); |
| (...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 803 const GpuMemoryAllocation& allocation) { | 825 const GpuMemoryAllocation& allocation) { |
| 804 Send(new GpuCommandBufferMsg_SetMemoryAllocation(route_id_, allocation)); | 826 Send(new GpuCommandBufferMsg_SetMemoryAllocation(route_id_, allocation)); |
| 805 // This can be called outside of OnMessageReceived, so the context needs to be | 827 // This can be called outside of OnMessageReceived, so the context needs to be |
| 806 // made current before calling methods on the surface. | 828 // made current before calling methods on the surface. |
| 807 if (!surface_ || !MakeCurrent()) | 829 if (!surface_ || !MakeCurrent()) |
| 808 return; | 830 return; |
| 809 surface_->SetFrontbufferAllocation(allocation.suggest_have_frontbuffer); | 831 surface_->SetFrontbufferAllocation(allocation.suggest_have_frontbuffer); |
| 810 } | 832 } |
| 811 | 833 |
| 812 #endif // defined(ENABLE_GPU) | 834 #endif // defined(ENABLE_GPU) |
| OLD | NEW |