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" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 } | 80 } |
81 | 81 |
82 // The first time polling a fence, delay some extra time to allow other | 82 // The first time polling a fence, delay some extra time to allow other |
83 // stubs to process some work, or else the timing of the fences could | 83 // stubs to process some work, or else the timing of the fences could |
84 // allow a pattern of alternating fast and slow frames to occur. | 84 // allow a pattern of alternating fast and slow frames to occur. |
85 const int64 kHandleMoreWorkPeriodMs = 2; | 85 const int64 kHandleMoreWorkPeriodMs = 2; |
86 const int64 kHandleMoreWorkPeriodBusyMs = 1; | 86 const int64 kHandleMoreWorkPeriodBusyMs = 1; |
87 | 87 |
88 } // namespace | 88 } // namespace |
89 | 89 |
90 GpuCommandBufferStub::SurfaceState::SurfaceState(int32 surface_id, | 90 GpuCommandBufferStub::MemoryManagerState::MemoryManagerState( |
91 bool visible, | 91 bool has_surface, |
92 base::TimeTicks last_used_time) | 92 bool visible, |
93 : surface_id(surface_id), | 93 base::TimeTicks last_used_time) |
| 94 : has_surface(has_surface), |
94 visible(visible), | 95 visible(visible), |
| 96 client_has_memory_allocation_changed_callback(false), |
95 last_used_time(last_used_time) { | 97 last_used_time(last_used_time) { |
96 } | 98 } |
97 | 99 |
98 GpuCommandBufferStub::GpuCommandBufferStub( | 100 GpuCommandBufferStub::GpuCommandBufferStub( |
99 GpuChannel* channel, | 101 GpuChannel* channel, |
100 GpuCommandBufferStub* share_group, | 102 GpuCommandBufferStub* share_group, |
101 const gfx::GLSurfaceHandle& handle, | 103 const gfx::GLSurfaceHandle& handle, |
102 gpu::gles2::MailboxManager* mailbox_manager, | 104 gpu::gles2::MailboxManager* mailbox_manager, |
103 const gfx::Size& size, | 105 const gfx::Size& size, |
104 const gpu::gles2::DisallowedFeatures& disallowed_features, | 106 const gpu::gles2::DisallowedFeatures& disallowed_features, |
105 const std::string& allowed_extensions, | 107 const std::string& allowed_extensions, |
106 const std::vector<int32>& attribs, | 108 const std::vector<int32>& attribs, |
107 gfx::GpuPreference gpu_preference, | 109 gfx::GpuPreference gpu_preference, |
108 int32 route_id, | 110 int32 route_id, |
109 int32 surface_id, | 111 int32 surface_id, |
110 GpuWatchdog* watchdog, | 112 GpuWatchdog* watchdog, |
111 bool software, | 113 bool software, |
112 const GURL& active_url) | 114 const GURL& active_url) |
113 : channel_(channel), | 115 : channel_(channel), |
114 handle_(handle), | 116 handle_(handle), |
115 initial_size_(size), | 117 initial_size_(size), |
116 disallowed_features_(disallowed_features), | 118 disallowed_features_(disallowed_features), |
117 allowed_extensions_(allowed_extensions), | 119 allowed_extensions_(allowed_extensions), |
118 requested_attribs_(attribs), | 120 requested_attribs_(attribs), |
119 gpu_preference_(gpu_preference), | 121 gpu_preference_(gpu_preference), |
120 route_id_(route_id), | 122 route_id_(route_id), |
| 123 surface_id_(surface_id), |
121 software_(software), | 124 software_(software), |
122 client_has_memory_allocation_changed_callback_(false), | |
123 last_flush_count_(0), | 125 last_flush_count_(0), |
124 parent_stub_for_initialization_(), | 126 parent_stub_for_initialization_(), |
125 parent_texture_for_initialization_(0), | 127 parent_texture_for_initialization_(0), |
126 watchdog_(watchdog), | 128 watchdog_(watchdog), |
127 sync_point_wait_count_(0), | 129 sync_point_wait_count_(0), |
128 delayed_work_scheduled_(false), | 130 delayed_work_scheduled_(false), |
129 active_url_(active_url) { | 131 active_url_(active_url) { |
130 active_url_hash_ = base::Hash(active_url.possibly_invalid_spec()); | 132 active_url_hash_ = base::Hash(active_url.possibly_invalid_spec()); |
131 FastSetActiveURL(active_url_, active_url_hash_); | 133 FastSetActiveURL(active_url_, active_url_hash_); |
132 if (share_group) { | 134 if (share_group) { |
133 context_group_ = share_group->context_group_; | 135 context_group_ = share_group->context_group_; |
134 } else { | 136 } else { |
135 context_group_ = new gpu::gles2::ContextGroup( | 137 context_group_ = new gpu::gles2::ContextGroup( |
136 mailbox_manager, | 138 mailbox_manager, |
137 new GpuCommandBufferMemoryTracker(channel), | 139 new GpuCommandBufferMemoryTracker(channel), |
138 true); | 140 true); |
139 } | 141 } |
140 if (surface_id != 0) | 142 memory_manager_state_.reset(new GpuCommandBufferStubBase::MemoryManagerState( |
141 surface_state_.reset(new GpuCommandBufferStubBase::SurfaceState( | 143 surface_id != 0, true, base::TimeTicks::Now())); |
142 surface_id, true, base::TimeTicks::Now())); | |
143 if (handle_.sync_point) | 144 if (handle_.sync_point) |
144 OnWaitSyncPoint(handle_.sync_point); | 145 OnWaitSyncPoint(handle_.sync_point); |
145 } | 146 } |
146 | 147 |
147 GpuCommandBufferStub::~GpuCommandBufferStub() { | 148 GpuCommandBufferStub::~GpuCommandBufferStub() { |
148 Destroy(); | 149 Destroy(); |
149 | 150 |
150 GpuChannelManager* gpu_channel_manager = channel_->gpu_channel_manager(); | 151 GpuChannelManager* gpu_channel_manager = channel_->gpu_channel_manager(); |
151 gpu_channel_manager->Send(new GpuHostMsg_DestroyCommandBuffer(surface_id())); | 152 gpu_channel_manager->Send(new GpuHostMsg_DestroyCommandBuffer(surface_id())); |
152 } | 153 } |
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
695 } | 696 } |
696 | 697 |
697 void GpuCommandBufferStub::OnDestroyVideoDecoder(int decoder_route_id) { | 698 void GpuCommandBufferStub::OnDestroyVideoDecoder(int decoder_route_id) { |
698 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnDestroyVideoDecoder"); | 699 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnDestroyVideoDecoder"); |
699 channel_->RemoveRoute(decoder_route_id); | 700 channel_->RemoveRoute(decoder_route_id); |
700 video_decoders_.Remove(decoder_route_id); | 701 video_decoders_.Remove(decoder_route_id); |
701 } | 702 } |
702 | 703 |
703 void GpuCommandBufferStub::OnSetSurfaceVisible(bool visible) { | 704 void GpuCommandBufferStub::OnSetSurfaceVisible(bool visible) { |
704 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnSetSurfaceVisible"); | 705 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnSetSurfaceVisible"); |
705 DCHECK(surface_state_.get()); | 706 memory_manager_state_->visible = visible; |
706 surface_state_->visible = visible; | 707 memory_manager_state_->last_used_time = base::TimeTicks::Now(); |
707 surface_state_->last_used_time = base::TimeTicks::Now(); | 708 channel_->gpu_channel_manager()->gpu_memory_manager()-> |
708 channel_->gpu_channel_manager()->gpu_memory_manager()-> | 709 ScheduleManage(visible); |
709 ScheduleManage(visible); | |
710 } | 710 } |
711 | 711 |
712 void GpuCommandBufferStub::OnDiscardBackbuffer() { | 712 void GpuCommandBufferStub::OnDiscardBackbuffer() { |
713 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnDiscardBackbuffer"); | 713 TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnDiscardBackbuffer"); |
714 if (!surface_) | 714 if (!surface_) |
715 return; | 715 return; |
716 surface_->SetBackbufferAllocation(false); | 716 surface_->SetBackbufferAllocation(false); |
717 } | 717 } |
718 | 718 |
719 void GpuCommandBufferStub::OnEnsureBackbuffer() { | 719 void GpuCommandBufferStub::OnEnsureBackbuffer() { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
767 | 767 |
768 void GpuCommandBufferStub::OnSignalSyncPointAck(uint32 id) { | 768 void GpuCommandBufferStub::OnSignalSyncPointAck(uint32 id) { |
769 Send(new GpuCommandBufferMsg_SignalSyncPointAck(route_id_, id)); | 769 Send(new GpuCommandBufferMsg_SignalSyncPointAck(route_id_, id)); |
770 } | 770 } |
771 | 771 |
772 void GpuCommandBufferStub::OnSetClientHasMemoryAllocationChangedCallback( | 772 void GpuCommandBufferStub::OnSetClientHasMemoryAllocationChangedCallback( |
773 bool has_callback) { | 773 bool has_callback) { |
774 TRACE_EVENT0( | 774 TRACE_EVENT0( |
775 "gpu", | 775 "gpu", |
776 "GpuCommandBufferStub::OnSetClientHasMemoryAllocationChangedCallback"); | 776 "GpuCommandBufferStub::OnSetClientHasMemoryAllocationChangedCallback"); |
777 client_has_memory_allocation_changed_callback_ = has_callback; | 777 memory_manager_state_->client_has_memory_allocation_changed_callback = |
| 778 has_callback; |
778 channel_->gpu_channel_manager()->gpu_memory_manager()-> | 779 channel_->gpu_channel_manager()->gpu_memory_manager()-> |
779 ScheduleManage(false); | 780 ScheduleManage(false); |
780 } | 781 } |
781 | 782 |
782 void GpuCommandBufferStub::SendConsoleMessage( | 783 void GpuCommandBufferStub::SendConsoleMessage( |
783 int32 id, | 784 int32 id, |
784 const std::string& message) { | 785 const std::string& message) { |
785 GPUCommandBufferConsoleMessage console_message; | 786 GPUCommandBufferConsoleMessage console_message; |
786 console_message.id = id; | 787 console_message.id = id; |
787 console_message.message = message; | 788 console_message.message = message; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
819 return gfx::Size(); | 820 return gfx::Size(); |
820 return surface_->GetSize(); | 821 return surface_->GetSize(); |
821 } | 822 } |
822 | 823 |
823 bool GpuCommandBufferStub::IsInSameContextShareGroup( | 824 bool GpuCommandBufferStub::IsInSameContextShareGroup( |
824 const GpuCommandBufferStubBase& other) const { | 825 const GpuCommandBufferStubBase& other) const { |
825 return context_group_ == | 826 return context_group_ == |
826 static_cast<const GpuCommandBufferStub&>(other).context_group_; | 827 static_cast<const GpuCommandBufferStub&>(other).context_group_; |
827 } | 828 } |
828 | 829 |
829 bool GpuCommandBufferStub:: | 830 |
830 client_has_memory_allocation_changed_callback() const { | 831 const GpuCommandBufferStubBase::MemoryManagerState& |
831 return client_has_memory_allocation_changed_callback_; | 832 GpuCommandBufferStub::memory_manager_state() const { |
| 833 return *memory_manager_state_.get(); |
832 } | 834 } |
833 | |
834 bool GpuCommandBufferStub::has_surface_state() const { | |
835 return surface_state_ != NULL; | |
836 } | |
837 | |
838 const GpuCommandBufferStubBase::SurfaceState& | |
839 GpuCommandBufferStub::surface_state() const { | |
840 DCHECK(has_surface_state()); | |
841 return *surface_state_.get(); | |
842 } | |
843 | |
844 void GpuCommandBufferStub::SetMemoryAllocation( | 835 void GpuCommandBufferStub::SetMemoryAllocation( |
845 const GpuMemoryAllocation& allocation) { | 836 const GpuMemoryAllocation& allocation) { |
846 Send(new GpuCommandBufferMsg_SetMemoryAllocation(route_id_, allocation)); | 837 Send(new GpuCommandBufferMsg_SetMemoryAllocation(route_id_, allocation)); |
847 // This can be called outside of OnMessageReceived, so the context needs to be | 838 // This can be called outside of OnMessageReceived, so the context needs to be |
848 // made current before calling methods on the surface. | 839 // made current before calling methods on the surface. |
849 if (!surface_ || !MakeCurrent()) | 840 if (!surface_ || !MakeCurrent()) |
850 return; | 841 return; |
851 surface_->SetFrontbufferAllocation(allocation.suggest_have_frontbuffer); | 842 surface_->SetFrontbufferAllocation(allocation.suggest_have_frontbuffer); |
852 } | 843 } |
853 | 844 |
854 #endif // defined(ENABLE_GPU) | 845 #endif // defined(ENABLE_GPU) |
OLD | NEW |