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 #include "gpu/ipc/service/gpu_command_buffer_stub.h" | 5 #include "gpu/ipc/service/gpu_command_buffer_stub.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/hash.h" | 11 #include "base/hash.h" |
12 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ptr_util.h" |
14 #include "base/memory/shared_memory.h" | 15 #include "base/memory/shared_memory.h" |
15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
16 #include "base/trace_event/trace_event.h" | 17 #include "base/trace_event/trace_event.h" |
17 #include "build/build_config.h" | 18 #include "build/build_config.h" |
18 #include "gpu/command_buffer/common/constants.h" | 19 #include "gpu/command_buffer/common/constants.h" |
19 #include "gpu/command_buffer/common/gpu_memory_buffer_support.h" | 20 #include "gpu/command_buffer/common/gpu_memory_buffer_support.h" |
20 #include "gpu/command_buffer/common/mailbox.h" | 21 #include "gpu/command_buffer/common/mailbox.h" |
21 #include "gpu/command_buffer/common/sync_token.h" | 22 #include "gpu/command_buffer/common/sync_token.h" |
22 #include "gpu/command_buffer/service/gl_context_virtual.h" | 23 #include "gpu/command_buffer/service/gl_context_virtual.h" |
23 #include "gpu/command_buffer/service/gl_state_restorer_impl.h" | 24 #include "gpu/command_buffer/service/gl_state_restorer_impl.h" |
(...skipping 25 matching lines...) Expand all Loading... |
49 #include "gpu/ipc/service/stream_texture_android.h" | 50 #include "gpu/ipc/service/stream_texture_android.h" |
50 #endif | 51 #endif |
51 | 52 |
52 namespace gpu { | 53 namespace gpu { |
53 struct WaitForCommandState { | 54 struct WaitForCommandState { |
54 WaitForCommandState(int32_t start, int32_t end, IPC::Message* reply) | 55 WaitForCommandState(int32_t start, int32_t end, IPC::Message* reply) |
55 : start(start), end(end), reply(reply) {} | 56 : start(start), end(end), reply(reply) {} |
56 | 57 |
57 int32_t start; | 58 int32_t start; |
58 int32_t end; | 59 int32_t end; |
59 scoped_ptr<IPC::Message> reply; | 60 std::unique_ptr<IPC::Message> reply; |
60 }; | 61 }; |
61 | 62 |
62 namespace { | 63 namespace { |
63 | 64 |
64 // The GpuCommandBufferMemoryTracker class provides a bridge between the | 65 // The GpuCommandBufferMemoryTracker class provides a bridge between the |
65 // ContextGroup's memory type managers and the GpuMemoryManager class. | 66 // ContextGroup's memory type managers and the GpuMemoryManager class. |
66 class GpuCommandBufferMemoryTracker : public gles2::MemoryTracker { | 67 class GpuCommandBufferMemoryTracker : public gles2::MemoryTracker { |
67 public: | 68 public: |
68 explicit GpuCommandBufferMemoryTracker(GpuChannel* channel, | 69 explicit GpuCommandBufferMemoryTracker(GpuChannel* channel, |
69 uint64_t share_group_tracing_guid) | 70 uint64_t share_group_tracing_guid) |
(...skipping 16 matching lines...) Expand all Loading... |
86 }; | 87 }; |
87 | 88 |
88 uint64_t ClientTracingId() const override { return client_tracing_id_; } | 89 uint64_t ClientTracingId() const override { return client_tracing_id_; } |
89 int ClientId() const override { return client_id_; } | 90 int ClientId() const override { return client_id_; } |
90 uint64_t ShareGroupTracingGUID() const override { | 91 uint64_t ShareGroupTracingGUID() const override { |
91 return share_group_tracing_guid_; | 92 return share_group_tracing_guid_; |
92 } | 93 } |
93 | 94 |
94 private: | 95 private: |
95 ~GpuCommandBufferMemoryTracker() override {} | 96 ~GpuCommandBufferMemoryTracker() override {} |
96 scoped_ptr<GpuMemoryTrackingGroup> tracking_group_; | 97 std::unique_ptr<GpuMemoryTrackingGroup> tracking_group_; |
97 const uint64_t client_tracing_id_; | 98 const uint64_t client_tracing_id_; |
98 const int client_id_; | 99 const int client_id_; |
99 const uint64_t share_group_tracing_guid_; | 100 const uint64_t share_group_tracing_guid_; |
100 | 101 |
101 DISALLOW_COPY_AND_ASSIGN(GpuCommandBufferMemoryTracker); | 102 DISALLOW_COPY_AND_ASSIGN(GpuCommandBufferMemoryTracker); |
102 }; | 103 }; |
103 | 104 |
104 // FastSetActiveURL will shortcut the expensive call to SetActiveURL when the | 105 // FastSetActiveURL will shortcut the expensive call to SetActiveURL when the |
105 // url_hash matches. | 106 // url_hash matches. |
106 void FastSetActiveURL(const GURL& url, size_t url_hash, GpuChannel* channel) { | 107 void FastSetActiveURL(const GURL& url, size_t url_hash, GpuChannel* channel) { |
(...skipping 16 matching lines...) Expand all Loading... |
123 // stubs to process some work, or else the timing of the fences could | 124 // stubs to process some work, or else the timing of the fences could |
124 // allow a pattern of alternating fast and slow frames to occur. | 125 // allow a pattern of alternating fast and slow frames to occur. |
125 const int64_t kHandleMoreWorkPeriodMs = 2; | 126 const int64_t kHandleMoreWorkPeriodMs = 2; |
126 const int64_t kHandleMoreWorkPeriodBusyMs = 1; | 127 const int64_t kHandleMoreWorkPeriodBusyMs = 1; |
127 | 128 |
128 // Prevents idle work from being starved. | 129 // Prevents idle work from being starved. |
129 const int64_t kMaxTimeSinceIdleMs = 10; | 130 const int64_t kMaxTimeSinceIdleMs = 10; |
130 | 131 |
131 class DevToolsChannelData : public base::trace_event::ConvertableToTraceFormat { | 132 class DevToolsChannelData : public base::trace_event::ConvertableToTraceFormat { |
132 public: | 133 public: |
133 static scoped_ptr<base::trace_event::ConvertableToTraceFormat> | 134 static std::unique_ptr<base::trace_event::ConvertableToTraceFormat> |
134 CreateForChannel(GpuChannel* channel); | 135 CreateForChannel(GpuChannel* channel); |
135 ~DevToolsChannelData() override {} | 136 ~DevToolsChannelData() override {} |
136 | 137 |
137 void AppendAsTraceFormat(std::string* out) const override { | 138 void AppendAsTraceFormat(std::string* out) const override { |
138 std::string tmp; | 139 std::string tmp; |
139 base::JSONWriter::Write(*value_, &tmp); | 140 base::JSONWriter::Write(*value_, &tmp); |
140 *out += tmp; | 141 *out += tmp; |
141 } | 142 } |
142 | 143 |
143 private: | 144 private: |
144 explicit DevToolsChannelData(base::Value* value) : value_(value) {} | 145 explicit DevToolsChannelData(base::Value* value) : value_(value) {} |
145 scoped_ptr<base::Value> value_; | 146 std::unique_ptr<base::Value> value_; |
146 DISALLOW_COPY_AND_ASSIGN(DevToolsChannelData); | 147 DISALLOW_COPY_AND_ASSIGN(DevToolsChannelData); |
147 }; | 148 }; |
148 | 149 |
149 scoped_ptr<base::trace_event::ConvertableToTraceFormat> | 150 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> |
150 DevToolsChannelData::CreateForChannel(GpuChannel* channel) { | 151 DevToolsChannelData::CreateForChannel(GpuChannel* channel) { |
151 scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue); | 152 std::unique_ptr<base::DictionaryValue> res(new base::DictionaryValue); |
152 res->SetInteger("renderer_pid", channel->GetClientPID()); | 153 res->SetInteger("renderer_pid", channel->GetClientPID()); |
153 res->SetDouble("used_bytes", channel->GetMemoryUsage()); | 154 res->SetDouble("used_bytes", channel->GetMemoryUsage()); |
154 return make_scoped_ptr(new DevToolsChannelData(res.release())); | 155 return base::WrapUnique(new DevToolsChannelData(res.release())); |
155 } | 156 } |
156 | 157 |
157 CommandBufferId GetCommandBufferID(int channel_id, int32_t route_id) { | 158 CommandBufferId GetCommandBufferID(int channel_id, int32_t route_id) { |
158 return CommandBufferId::FromUnsafeValue( | 159 return CommandBufferId::FromUnsafeValue( |
159 (static_cast<uint64_t>(channel_id) << 32) | route_id); | 160 (static_cast<uint64_t>(channel_id) << 32) | route_id); |
160 } | 161 } |
161 | 162 |
162 } // namespace | 163 } // namespace |
163 | 164 |
164 GpuCommandBufferStub::GpuCommandBufferStub( | 165 GpuCommandBufferStub::GpuCommandBufferStub( |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 } | 523 } |
523 return surface; | 524 return surface; |
524 } | 525 } |
525 | 526 |
526 void GpuCommandBufferStub::OnInitialize( | 527 void GpuCommandBufferStub::OnInitialize( |
527 base::SharedMemoryHandle shared_state_handle, | 528 base::SharedMemoryHandle shared_state_handle, |
528 IPC::Message* reply_message) { | 529 IPC::Message* reply_message) { |
529 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnInitialize"); | 530 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnInitialize"); |
530 DCHECK(!command_buffer_.get()); | 531 DCHECK(!command_buffer_.get()); |
531 | 532 |
532 scoped_ptr<base::SharedMemory> shared_state_shm( | 533 std::unique_ptr<base::SharedMemory> shared_state_shm( |
533 new base::SharedMemory(shared_state_handle, false)); | 534 new base::SharedMemory(shared_state_handle, false)); |
534 | 535 |
535 command_buffer_.reset(new CommandBufferService( | 536 command_buffer_.reset(new CommandBufferService( |
536 context_group_->transfer_buffer_manager())); | 537 context_group_->transfer_buffer_manager())); |
537 | 538 |
538 bool result = command_buffer_->Initialize(); | 539 bool result = command_buffer_->Initialize(); |
539 DCHECK(result); | 540 DCHECK(result); |
540 | 541 |
541 GpuChannelManager* manager = channel_->gpu_channel_manager(); | 542 GpuChannelManager* manager = channel_->gpu_channel_manager(); |
542 DCHECK(manager); | 543 DCHECK(manager); |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
742 | 743 |
743 void GpuCommandBufferStub::OnWaitForTokenInRange(int32_t start, | 744 void GpuCommandBufferStub::OnWaitForTokenInRange(int32_t start, |
744 int32_t end, | 745 int32_t end, |
745 IPC::Message* reply_message) { | 746 IPC::Message* reply_message) { |
746 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnWaitForTokenInRange"); | 747 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnWaitForTokenInRange"); |
747 DCHECK(command_buffer_.get()); | 748 DCHECK(command_buffer_.get()); |
748 CheckContextLost(); | 749 CheckContextLost(); |
749 if (wait_for_token_) | 750 if (wait_for_token_) |
750 LOG(ERROR) << "Got WaitForToken command while currently waiting for token."; | 751 LOG(ERROR) << "Got WaitForToken command while currently waiting for token."; |
751 wait_for_token_ = | 752 wait_for_token_ = |
752 make_scoped_ptr(new WaitForCommandState(start, end, reply_message)); | 753 base::WrapUnique(new WaitForCommandState(start, end, reply_message)); |
753 CheckCompleteWaits(); | 754 CheckCompleteWaits(); |
754 } | 755 } |
755 | 756 |
756 void GpuCommandBufferStub::OnWaitForGetOffsetInRange( | 757 void GpuCommandBufferStub::OnWaitForGetOffsetInRange( |
757 int32_t start, | 758 int32_t start, |
758 int32_t end, | 759 int32_t end, |
759 IPC::Message* reply_message) { | 760 IPC::Message* reply_message) { |
760 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnWaitForGetOffsetInRange"); | 761 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnWaitForGetOffsetInRange"); |
761 DCHECK(command_buffer_.get()); | 762 DCHECK(command_buffer_.get()); |
762 CheckContextLost(); | 763 CheckContextLost(); |
763 if (wait_for_get_offset_) { | 764 if (wait_for_get_offset_) { |
764 LOG(ERROR) | 765 LOG(ERROR) |
765 << "Got WaitForGetOffset command while currently waiting for offset."; | 766 << "Got WaitForGetOffset command while currently waiting for offset."; |
766 } | 767 } |
767 wait_for_get_offset_ = | 768 wait_for_get_offset_ = |
768 make_scoped_ptr(new WaitForCommandState(start, end, reply_message)); | 769 base::WrapUnique(new WaitForCommandState(start, end, reply_message)); |
769 CheckCompleteWaits(); | 770 CheckCompleteWaits(); |
770 } | 771 } |
771 | 772 |
772 void GpuCommandBufferStub::CheckCompleteWaits() { | 773 void GpuCommandBufferStub::CheckCompleteWaits() { |
773 if (wait_for_token_ || wait_for_get_offset_) { | 774 if (wait_for_token_ || wait_for_get_offset_) { |
774 CommandBuffer::State state = command_buffer_->GetLastState(); | 775 CommandBuffer::State state = command_buffer_->GetLastState(); |
775 if (wait_for_token_ && | 776 if (wait_for_token_ && |
776 (CommandBuffer::InRange( | 777 (CommandBuffer::InRange( |
777 wait_for_token_->start, wait_for_token_->end, state.token) || | 778 wait_for_token_->start, wait_for_token_->end, state.token) || |
778 state.error != error::kNoError)) { | 779 state.error != error::kNoError)) { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
831 } | 832 } |
832 | 833 |
833 void GpuCommandBufferStub::OnRegisterTransferBuffer( | 834 void GpuCommandBufferStub::OnRegisterTransferBuffer( |
834 int32_t id, | 835 int32_t id, |
835 base::SharedMemoryHandle transfer_buffer, | 836 base::SharedMemoryHandle transfer_buffer, |
836 uint32_t size) { | 837 uint32_t size) { |
837 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnRegisterTransferBuffer"); | 838 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnRegisterTransferBuffer"); |
838 | 839 |
839 // Take ownership of the memory and map it into this process. | 840 // Take ownership of the memory and map it into this process. |
840 // This validates the size. | 841 // This validates the size. |
841 scoped_ptr<base::SharedMemory> shared_memory( | 842 std::unique_ptr<base::SharedMemory> shared_memory( |
842 new base::SharedMemory(transfer_buffer, false)); | 843 new base::SharedMemory(transfer_buffer, false)); |
843 if (!shared_memory->Map(size)) { | 844 if (!shared_memory->Map(size)) { |
844 DVLOG(0) << "Failed to map shared memory."; | 845 DVLOG(0) << "Failed to map shared memory."; |
845 return; | 846 return; |
846 } | 847 } |
847 | 848 |
848 if (command_buffer_) { | 849 if (command_buffer_) { |
849 command_buffer_->RegisterTransferBuffer( | 850 command_buffer_->RegisterTransferBuffer( |
850 id, MakeBackingFromSharedMemory(std::move(shared_memory), size)); | 851 id, MakeBackingFromSharedMemory(std::move(shared_memory), size)); |
851 } | 852 } |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1129 result)); | 1130 result)); |
1130 } | 1131 } |
1131 | 1132 |
1132 void GpuCommandBufferStub::SendUpdateVSyncParameters(base::TimeTicks timebase, | 1133 void GpuCommandBufferStub::SendUpdateVSyncParameters(base::TimeTicks timebase, |
1133 base::TimeDelta interval) { | 1134 base::TimeDelta interval) { |
1134 Send(new GpuCommandBufferMsg_UpdateVSyncParameters(route_id_, timebase, | 1135 Send(new GpuCommandBufferMsg_UpdateVSyncParameters(route_id_, timebase, |
1135 interval)); | 1136 interval)); |
1136 } | 1137 } |
1137 | 1138 |
1138 } // namespace gpu | 1139 } // namespace gpu |
OLD | NEW |