[email protected] | 6802e3c6 | 2012-06-06 22:32:44 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #if defined(ENABLE_GPU) |
| 6 | |
[email protected] | 80c4975 | 2011-04-18 23:55:10 | [diff] [blame] | 7 | #include "base/bind.h" |
[email protected] | 9d37f06 | 2011-11-22 01:24:52 | [diff] [blame] | 8 | #include "base/bind_helpers.h" |
[email protected] | 79311e8 | 2011-09-20 00:40:50 | [diff] [blame] | 9 | #include "base/command_line.h" |
[email protected] | 366ae24 | 2011-05-10 02:23:58 | [diff] [blame] | 10 | #include "base/debug/trace_event.h" |
[email protected] | 51ddf72 | 2012-09-01 00:55:09 | [diff] [blame] | 11 | #include "base/hash.h" |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 12 | #include "base/shared_memory.h" |
[email protected] | 672c731 | 2012-02-03 16:28:55 | [diff] [blame] | 13 | #include "base/time.h" |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 14 | #include "build/build_config.h" |
[email protected] | f24a1e2b | 2011-04-08 01:48:48 | [diff] [blame] | 15 | #include "content/common/gpu/gpu_channel.h" |
| 16 | #include "content/common/gpu/gpu_channel_manager.h" |
| 17 | #include "content/common/gpu/gpu_command_buffer_stub.h" |
[email protected] | 672c731 | 2012-02-03 16:28:55 | [diff] [blame] | 18 | #include "content/common/gpu/gpu_memory_manager.h" |
[email protected] | fb246af | 2012-08-18 03:11:41 | [diff] [blame] | 19 | #include "content/common/gpu/gpu_memory_tracking.h" |
[email protected] | 202b54ff | 2011-04-22 21:36:38 | [diff] [blame] | 20 | #include "content/common/gpu/gpu_messages.h" |
[email protected] | 2dcf702 | 2011-04-15 19:20:41 | [diff] [blame] | 21 | #include "content/common/gpu/gpu_watchdog.h" |
[email protected] | bc4a343 | 2011-11-21 23:55:56 | [diff] [blame] | 22 | #include "content/common/gpu/image_transport_surface.h" |
[email protected] | cdd3d64 | 2012-06-27 19:59:14 | [diff] [blame] | 23 | #include "content/common/gpu/media/gpu_video_decode_accelerator.h" |
[email protected] | c02f93e4 | 2012-06-05 23:35:16 | [diff] [blame] | 24 | #include "content/common/gpu/sync_point_manager.h" |
[email protected] | d1a9e06 | 2012-07-13 00:45:14 | [diff] [blame] | 25 | #include "content/public/common/content_client.h" |
[email protected] | 290fc49 | 2011-11-22 23:25:23 | [diff] [blame] | 26 | #include "gpu/command_buffer/common/constants.h" |
[email protected] | d670e70 | 2012-03-30 10:38:21 | [diff] [blame] | 27 | #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
[email protected] | 00b19257 | 2012-07-28 04:00:22 | [diff] [blame] | 28 | #include "gpu/command_buffer/service/memory_tracking.h" |
[email protected] | c9e2cbbb | 2012-05-12 21:17:27 | [diff] [blame] | 29 | #include "ui/gl/gl_bindings.h" |
| 30 | #include "ui/gl/gl_switches.h" |
[email protected] | bc4a343 | 2011-11-21 23:55:56 | [diff] [blame] | 31 | |
[email protected] | cd0bd79 | 2012-04-14 00:52:16 | [diff] [blame] | 32 | #if defined(OS_WIN) |
[email protected] | d30ce6e | 2012-04-16 15:32:36 | [diff] [blame] | 33 | #include "content/public/common/sandbox_init.h" |
[email protected] | cd0bd79 | 2012-04-14 00:52:16 | [diff] [blame] | 34 | #endif |
| 35 | |
[email protected] | 34aaa568 | 2012-09-25 00:48:50 | [diff] [blame] | 36 | #if defined(OS_ANDROID) |
| 37 | #include "content/common/gpu/stream_texture_manager_android.h" |
| 38 | #endif |
| 39 | |
[email protected] | 56fc2f2 | 2012-07-09 23:50:36 | [diff] [blame] | 40 | namespace { |
[email protected] | d1a9e06 | 2012-07-13 00:45:14 | [diff] [blame] | 41 | |
[email protected] | 00b19257 | 2012-07-28 04:00:22 | [diff] [blame] | 42 | // The GpuCommandBufferMemoryTracker class provides a bridge between the |
| 43 | // ContextGroup's memory type managers and the GpuMemoryManager class. |
| 44 | class GpuCommandBufferMemoryTracker : public gpu::gles2::MemoryTracker { |
| 45 | public: |
[email protected] | fb246af | 2012-08-18 03:11:41 | [diff] [blame] | 46 | GpuCommandBufferMemoryTracker(GpuChannel* channel) { |
| 47 | gpu_memory_manager_tracking_group_ = new GpuMemoryTrackingGroup( |
| 48 | channel->renderer_pid(), |
| 49 | channel->gpu_channel_manager()->gpu_memory_manager()); |
| 50 | } |
| 51 | |
[email protected] | 00b19257 | 2012-07-28 04:00:22 | [diff] [blame] | 52 | void TrackMemoryAllocatedChange(size_t old_size, size_t new_size) { |
[email protected] | fb246af | 2012-08-18 03:11:41 | [diff] [blame] | 53 | gpu_memory_manager_tracking_group_->TrackMemoryAllocatedChange( |
| 54 | old_size, new_size); |
[email protected] | 00b19257 | 2012-07-28 04:00:22 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | private: |
[email protected] | fb246af | 2012-08-18 03:11:41 | [diff] [blame] | 58 | ~GpuCommandBufferMemoryTracker() { |
| 59 | delete gpu_memory_manager_tracking_group_; |
| 60 | } |
| 61 | GpuMemoryTrackingGroup* gpu_memory_manager_tracking_group_; |
[email protected] | 00b19257 | 2012-07-28 04:00:22 | [diff] [blame] | 62 | |
| 63 | DISALLOW_COPY_AND_ASSIGN(GpuCommandBufferMemoryTracker); |
| 64 | }; |
| 65 | |
[email protected] | d1a9e06 | 2012-07-13 00:45:14 | [diff] [blame] | 66 | // FastSetActiveURL will shortcut the expensive call to SetActiveURL when the |
| 67 | // url_hash matches. |
| 68 | void FastSetActiveURL(const GURL& url, size_t url_hash) { |
| 69 | // Leave the previously set URL in the empty case -- empty URLs are given by |
| 70 | // WebKitPlatformSupportImpl::createOffscreenGraphicsContext3D. Hopefully the |
| 71 | // onscreen context URL was set previously and will show up even when a crash |
| 72 | // occurs during offscreen command processing. |
| 73 | if (url.is_empty()) |
| 74 | return; |
| 75 | static size_t g_last_url_hash = 0; |
| 76 | if (url_hash != g_last_url_hash) { |
| 77 | g_last_url_hash = url_hash; |
| 78 | content::GetContentClient()->SetActiveURL(url); |
| 79 | } |
| 80 | } |
| 81 | |
[email protected] | 56fc2f2 | 2012-07-09 23:50:36 | [diff] [blame] | 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 |
| 84 | // allow a pattern of alternating fast and slow frames to occur. |
| 85 | const int64 kHandleMoreWorkPeriodMs = 2; |
| 86 | const int64 kHandleMoreWorkPeriodBusyMs = 1; |
[email protected] | d1a9e06 | 2012-07-13 00:45:14 | [diff] [blame] | 87 | |
| 88 | } // namespace |
[email protected] | 56fc2f2 | 2012-07-09 23:50:36 | [diff] [blame] | 89 | |
[email protected] | 5178c442 | 2012-10-17 12:08:07 | [diff] [blame^] | 90 | GpuCommandBufferStub::MemoryManagerState::MemoryManagerState( |
| 91 | bool has_surface, |
| 92 | bool visible, |
| 93 | base::TimeTicks last_used_time) |
| 94 | : has_surface(has_surface), |
[email protected] | 672c731 | 2012-02-03 16:28:55 | [diff] [blame] | 95 | visible(visible), |
[email protected] | 5178c442 | 2012-10-17 12:08:07 | [diff] [blame^] | 96 | client_has_memory_allocation_changed_callback(false), |
[email protected] | 672c731 | 2012-02-03 16:28:55 | [diff] [blame] | 97 | last_used_time(last_used_time) { |
| 98 | } |
| 99 | |
[email protected] | a3ded6d | 2010-10-19 06:44:39 | [diff] [blame] | 100 | GpuCommandBufferStub::GpuCommandBufferStub( |
| 101 | GpuChannel* channel, |
[email protected] | 3b1ecc26 | 2011-08-03 22:49:57 | [diff] [blame] | 102 | GpuCommandBufferStub* share_group, |
[email protected] | fc4ed09 | 2012-02-21 19:46:55 | [diff] [blame] | 103 | const gfx::GLSurfaceHandle& handle, |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 104 | gpu::gles2::MailboxManager* mailbox_manager, |
[email protected] | a3ded6d | 2010-10-19 06:44:39 | [diff] [blame] | 105 | const gfx::Size& size, |
[email protected] | e82fb79 | 2011-09-22 00:33:29 | [diff] [blame] | 106 | const gpu::gles2::DisallowedFeatures& disallowed_features, |
[email protected] | a3ded6d | 2010-10-19 06:44:39 | [diff] [blame] | 107 | const std::string& allowed_extensions, |
| 108 | const std::vector<int32>& attribs, |
[email protected] | 276f8906 | 2011-10-13 22:55:50 | [diff] [blame] | 109 | gfx::GpuPreference gpu_preference, |
[email protected] | a3ded6d | 2010-10-19 06:44:39 | [diff] [blame] | 110 | int32 route_id, |
[email protected] | 9f4f332 | 2012-01-18 22:29:56 | [diff] [blame] | 111 | int32 surface_id, |
[email protected] | f81f595 | 2011-07-21 18:52:47 | [diff] [blame] | 112 | GpuWatchdog* watchdog, |
[email protected] | d1a9e06 | 2012-07-13 00:45:14 | [diff] [blame] | 113 | bool software, |
[email protected] | 7f1a51c32 | 2012-07-19 18:52:02 | [diff] [blame] | 114 | const GURL& active_url) |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 115 | : channel_(channel), |
[email protected] | 6ebf2fc | 2010-07-01 01:06:32 | [diff] [blame] | 116 | handle_(handle), |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 117 | initial_size_(size), |
[email protected] | e82fb79 | 2011-09-22 00:33:29 | [diff] [blame] | 118 | disallowed_features_(disallowed_features), |
[email protected] | bc51875 | 2010-10-20 21:38:27 | [diff] [blame] | 119 | allowed_extensions_(allowed_extensions), |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 120 | requested_attribs_(attribs), |
[email protected] | 276f8906 | 2011-10-13 22:55:50 | [diff] [blame] | 121 | gpu_preference_(gpu_preference), |
[email protected] | 77e74db | 2010-08-04 17:46:23 | [diff] [blame] | 122 | route_id_(route_id), |
[email protected] | 5178c442 | 2012-10-17 12:08:07 | [diff] [blame^] | 123 | surface_id_(surface_id), |
[email protected] | f81f595 | 2011-07-21 18:52:47 | [diff] [blame] | 124 | software_(software), |
[email protected] | a3847714 | 2011-05-28 02:45:58 | [diff] [blame] | 125 | last_flush_count_(0), |
[email protected] | e7da6aef | 2011-06-22 19:29:03 | [diff] [blame] | 126 | parent_stub_for_initialization_(), |
| 127 | parent_texture_for_initialization_(0), |
[email protected] | 35a0b4b | 2012-06-15 03:53:30 | [diff] [blame] | 128 | watchdog_(watchdog), |
[email protected] | 56fc2f2 | 2012-07-09 23:50:36 | [diff] [blame] | 129 | sync_point_wait_count_(0), |
[email protected] | d1a9e06 | 2012-07-13 00:45:14 | [diff] [blame] | 130 | delayed_work_scheduled_(false), |
| 131 | active_url_(active_url) { |
[email protected] | 51ddf72 | 2012-09-01 00:55:09 | [diff] [blame] | 132 | active_url_hash_ = base::Hash(active_url.possibly_invalid_spec()); |
[email protected] | d1a9e06 | 2012-07-13 00:45:14 | [diff] [blame] | 133 | FastSetActiveURL(active_url_, active_url_hash_); |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 134 | if (share_group) { |
[email protected] | 3b1ecc26 | 2011-08-03 22:49:57 | [diff] [blame] | 135 | context_group_ = share_group->context_group_; |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 136 | } else { |
[email protected] | 00b19257 | 2012-07-28 04:00:22 | [diff] [blame] | 137 | context_group_ = new gpu::gles2::ContextGroup( |
[email protected] | fb246af | 2012-08-18 03:11:41 | [diff] [blame] | 138 | mailbox_manager, |
| 139 | new GpuCommandBufferMemoryTracker(channel), |
| 140 | true); |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 141 | } |
[email protected] | 5178c442 | 2012-10-17 12:08:07 | [diff] [blame^] | 142 | memory_manager_state_.reset(new GpuCommandBufferStubBase::MemoryManagerState( |
| 143 | surface_id != 0, true, base::TimeTicks::Now())); |
[email protected] | 35a0b4b | 2012-06-15 03:53:30 | [diff] [blame] | 144 | if (handle_.sync_point) |
| 145 | OnWaitSyncPoint(handle_.sync_point); |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | GpuCommandBufferStub::~GpuCommandBufferStub() { |
[email protected] | 79311e8 | 2011-09-20 00:40:50 | [diff] [blame] | 149 | Destroy(); |
[email protected] | d8a58e4 | 2011-01-27 15:24:25 | [diff] [blame] | 150 | |
[email protected] | f24a1e2b | 2011-04-08 01:48:48 | [diff] [blame] | 151 | GpuChannelManager* gpu_channel_manager = channel_->gpu_channel_manager(); |
[email protected] | 672c731 | 2012-02-03 16:28:55 | [diff] [blame] | 152 | gpu_channel_manager->Send(new GpuHostMsg_DestroyCommandBuffer(surface_id())); |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 153 | } |
| 154 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 155 | bool GpuCommandBufferStub::OnMessageReceived(const IPC::Message& message) { |
[email protected] | d1a9e06 | 2012-07-13 00:45:14 | [diff] [blame] | 156 | FastSetActiveURL(active_url_, active_url_hash_); |
| 157 | |
[email protected] | 79311e8 | 2011-09-20 00:40:50 | [diff] [blame] | 158 | // Ensure the appropriate GL context is current before handling any IPC |
| 159 | // messages directed at the command buffer. This ensures that the message |
[email protected] | 6802e3c6 | 2012-06-06 22:32:44 | [diff] [blame] | 160 | // handler can assume that the context is current (not necessary for |
[email protected] | 68c7028 | 2012-06-25 23:31:17 | [diff] [blame] | 161 | // Echo, RetireSyncPoint, or WaitSyncPoint). |
[email protected] | 6802e3c6 | 2012-06-06 22:32:44 | [diff] [blame] | 162 | if (decoder_.get() && |
[email protected] | 68c7028 | 2012-06-25 23:31:17 | [diff] [blame] | 163 | message.type() != GpuCommandBufferMsg_Echo::ID && |
| 164 | message.type() != GpuCommandBufferMsg_RetireSyncPoint::ID && |
| 165 | message.type() != GpuCommandBufferMsg_WaitSyncPoint::ID) { |
[email protected] | 062e5e8 | 2012-06-20 19:30:35 | [diff] [blame] | 166 | if (!MakeCurrent()) |
[email protected] | 79311e8 | 2011-09-20 00:40:50 | [diff] [blame] | 167 | return false; |
[email protected] | 79311e8 | 2011-09-20 00:40:50 | [diff] [blame] | 168 | } |
| 169 | |
[email protected] | 310bed51 | 2011-05-09 21:12:25 | [diff] [blame] | 170 | // Always use IPC_MESSAGE_HANDLER_DELAY_REPLY for synchronous message handlers |
| 171 | // here. This is so the reply can be delayed if the scheduler is unscheduled. |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 172 | bool handled = true; |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 173 | IPC_BEGIN_MESSAGE_MAP(GpuCommandBufferStub, message) |
[email protected] | 310bed51 | 2011-05-09 21:12:25 | [diff] [blame] | 174 | IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_Initialize, |
| 175 | OnInitialize); |
[email protected] | 503b3a2 | 2011-12-12 23:29:40 | [diff] [blame] | 176 | IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_SetGetBuffer, |
| 177 | OnSetGetBuffer); |
[email protected] | 68eff95 | 2012-02-17 21:56:35 | [diff] [blame] | 178 | IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_SetSharedStateBuffer, |
| 179 | OnSetSharedStateBuffer); |
[email protected] | 3c644d8 | 2011-06-20 19:58:24 | [diff] [blame] | 180 | IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_SetParent, |
| 181 | OnSetParent); |
[email protected] | 1ef068c | 2012-03-02 16:30:47 | [diff] [blame] | 182 | IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_Echo, OnEcho); |
[email protected] | 310bed51 | 2011-05-09 21:12:25 | [diff] [blame] | 183 | IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_GetState, OnGetState); |
[email protected] | 451e966 | 2011-10-10 21:14:34 | [diff] [blame] | 184 | IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_GetStateFast, |
| 185 | OnGetStateFast); |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 186 | IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_AsyncFlush, OnAsyncFlush); |
[email protected] | d0f02c4 | 2011-07-21 21:40:48 | [diff] [blame] | 187 | IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_Rescheduled, OnRescheduled); |
[email protected] | 310bed51 | 2011-05-09 21:12:25 | [diff] [blame] | 188 | IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_CreateTransferBuffer, |
| 189 | OnCreateTransferBuffer); |
| 190 | IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_RegisterTransferBuffer, |
| 191 | OnRegisterTransferBuffer); |
| 192 | IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_DestroyTransferBuffer, |
| 193 | OnDestroyTransferBuffer); |
| 194 | IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_GetTransferBuffer, |
| 195 | OnGetTransferBuffer); |
[email protected] | c842306 | 2011-07-29 19:25:38 | [diff] [blame] | 196 | IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_CreateVideoDecoder, |
| 197 | OnCreateVideoDecoder) |
[email protected] | a13da24 | 2011-07-07 19:48:17 | [diff] [blame] | 198 | IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_DestroyVideoDecoder, |
| 199 | OnDestroyVideoDecoder) |
[email protected] | 8cc980c5 | 2011-10-14 20:35:51 | [diff] [blame] | 200 | IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SetSurfaceVisible, |
| 201 | OnSetSurfaceVisible) |
[email protected] | 251622e | 2012-03-23 16:17:40 | [diff] [blame] | 202 | IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_DiscardBackbuffer, |
| 203 | OnDiscardBackbuffer) |
| 204 | IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_EnsureBackbuffer, |
| 205 | OnEnsureBackbuffer) |
[email protected] | c02f93e4 | 2012-06-05 23:35:16 | [diff] [blame] | 206 | IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_RetireSyncPoint, |
| 207 | OnRetireSyncPoint) |
| 208 | IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_WaitSyncPoint, |
| 209 | OnWaitSyncPoint) |
[email protected] | 5ab44ef | 2012-06-19 00:03:51 | [diff] [blame] | 210 | IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SignalSyncPoint, |
| 211 | OnSignalSyncPoint) |
[email protected] | c1f1214 | 2012-05-01 22:21:06 | [diff] [blame] | 212 | IPC_MESSAGE_HANDLER( |
| 213 | GpuCommandBufferMsg_SetClientHasMemoryAllocationChangedCallback, |
| 214 | OnSetClientHasMemoryAllocationChangedCallback) |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 215 | IPC_MESSAGE_UNHANDLED(handled = false) |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 216 | IPC_END_MESSAGE_MAP() |
[email protected] | a13da24 | 2011-07-07 19:48:17 | [diff] [blame] | 217 | |
[email protected] | 56fc2f2 | 2012-07-09 23:50:36 | [diff] [blame] | 218 | // Ensure that any delayed work that was created will be handled. |
| 219 | ScheduleDelayedWork(kHandleMoreWorkPeriodMs); |
| 220 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 221 | DCHECK(handled); |
| 222 | return handled; |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | bool GpuCommandBufferStub::Send(IPC::Message* message) { |
| 226 | return channel_->Send(message); |
| 227 | } |
| 228 | |
[email protected] | d0f02c4 | 2011-07-21 21:40:48 | [diff] [blame] | 229 | bool GpuCommandBufferStub::IsScheduled() { |
[email protected] | 35a0b4b | 2012-06-15 03:53:30 | [diff] [blame] | 230 | return sync_point_wait_count_ == 0 && |
| 231 | (!scheduler_.get() || scheduler_->IsScheduled()); |
[email protected] | d0f02c4 | 2011-07-21 21:40:48 | [diff] [blame] | 232 | } |
| 233 | |
[email protected] | 20f656f | 2011-12-08 02:25:15 | [diff] [blame] | 234 | bool GpuCommandBufferStub::HasMoreWork() { |
| 235 | return scheduler_.get() && scheduler_->HasMoreWork(); |
| 236 | } |
| 237 | |
[email protected] | f5f910d5 | 2012-03-06 22:33:09 | [diff] [blame] | 238 | void GpuCommandBufferStub::PollWork() { |
[email protected] | 56fc2f2 | 2012-07-09 23:50:36 | [diff] [blame] | 239 | TRACE_EVENT0("gpu", "GpuCommandBufferStub::PollWork"); |
| 240 | delayed_work_scheduled_ = false; |
[email protected] | a5b2abb91 | 2012-07-13 04:45:04 | [diff] [blame] | 241 | FastSetActiveURL(active_url_, active_url_hash_); |
[email protected] | 062e5e8 | 2012-06-20 19:30:35 | [diff] [blame] | 242 | if (decoder_.get() && !MakeCurrent()) |
| 243 | return; |
[email protected] | f5f910d5 | 2012-03-06 22:33:09 | [diff] [blame] | 244 | if (scheduler_.get()) |
| 245 | scheduler_->PollUnscheduleFences(); |
[email protected] | 56fc2f2 | 2012-07-09 23:50:36 | [diff] [blame] | 246 | ScheduleDelayedWork(kHandleMoreWorkPeriodBusyMs); |
[email protected] | f5f910d5 | 2012-03-06 22:33:09 | [diff] [blame] | 247 | } |
| 248 | |
[email protected] | df621aff | 2012-03-02 23:04:58 | [diff] [blame] | 249 | bool GpuCommandBufferStub::HasUnprocessedCommands() { |
| 250 | if (command_buffer_.get()) { |
| 251 | gpu::CommandBuffer::State state = command_buffer_->GetLastState(); |
[email protected] | 6dadf65 | 2012-03-22 02:49:24 | [diff] [blame] | 252 | return state.put_offset != state.get_offset && |
| 253 | !gpu::error::IsError(state.error); |
[email protected] | df621aff | 2012-03-02 23:04:58 | [diff] [blame] | 254 | } |
| 255 | return false; |
| 256 | } |
| 257 | |
[email protected] | 56fc2f2 | 2012-07-09 23:50:36 | [diff] [blame] | 258 | void GpuCommandBufferStub::ScheduleDelayedWork(int64 delay) { |
| 259 | if (HasMoreWork() && !delayed_work_scheduled_) { |
| 260 | delayed_work_scheduled_ = true; |
| 261 | MessageLoop::current()->PostDelayedTask( |
| 262 | FROM_HERE, |
| 263 | base::Bind(&GpuCommandBufferStub::PollWork, |
| 264 | AsWeakPtr()), |
| 265 | base::TimeDelta::FromMilliseconds(delay)); |
| 266 | } |
| 267 | } |
| 268 | |
[email protected] | 1ef068c | 2012-03-02 16:30:47 | [diff] [blame] | 269 | void GpuCommandBufferStub::OnEcho(const IPC::Message& message) { |
| 270 | TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnEcho"); |
| 271 | Send(new IPC::Message(message)); |
| 272 | } |
| 273 | |
[email protected] | ac9ab81 | 2012-03-06 22:44:05 | [diff] [blame] | 274 | void GpuCommandBufferStub::DelayEcho(IPC::Message* message) { |
| 275 | delayed_echos_.push_back(message); |
| 276 | } |
| 277 | |
| 278 | void GpuCommandBufferStub::OnReschedule() { |
[email protected] | 35a0b4b | 2012-06-15 03:53:30 | [diff] [blame] | 279 | if (!IsScheduled()) |
| 280 | return; |
[email protected] | ac9ab81 | 2012-03-06 22:44:05 | [diff] [blame] | 281 | while (!delayed_echos_.empty()) { |
| 282 | scoped_ptr<IPC::Message> message(delayed_echos_.front()); |
| 283 | delayed_echos_.pop_front(); |
| 284 | |
| 285 | OnMessageReceived(*message); |
| 286 | } |
| 287 | |
| 288 | channel_->OnScheduled(); |
| 289 | } |
| 290 | |
[email protected] | 062e5e8 | 2012-06-20 19:30:35 | [diff] [blame] | 291 | bool GpuCommandBufferStub::MakeCurrent() { |
| 292 | if (decoder_->MakeCurrent()) |
| 293 | return true; |
| 294 | DLOG(ERROR) << "Context lost because MakeCurrent failed."; |
| 295 | command_buffer_->SetContextLostReason(decoder_->GetContextLostReason()); |
| 296 | command_buffer_->SetParseError(gpu::error::kLostContext); |
| 297 | if (gfx::GLContext::LosesAllContextsOnContextLost()) |
| 298 | channel_->LoseAllContexts(); |
| 299 | return false; |
| 300 | } |
| 301 | |
[email protected] | 79311e8 | 2011-09-20 00:40:50 | [diff] [blame] | 302 | void GpuCommandBufferStub::Destroy() { |
[email protected] | c02f93e4 | 2012-06-05 23:35:16 | [diff] [blame] | 303 | while (!sync_points_.empty()) |
| 304 | OnRetireSyncPoint(sync_points_.front()); |
| 305 | |
[email protected] | 79311e8 | 2011-09-20 00:40:50 | [diff] [blame] | 306 | // The scheduler has raw references to the decoder and the command buffer so |
| 307 | // destroy it before those. |
[email protected] | 4ee0c305 | 2011-09-16 19:30:36 | [diff] [blame] | 308 | scheduler_.reset(); |
[email protected] | 79311e8 | 2011-09-20 00:40:50 | [diff] [blame] | 309 | |
[email protected] | ac9ab81 | 2012-03-06 22:44:05 | [diff] [blame] | 310 | while (!delayed_echos_.empty()) { |
| 311 | delete delayed_echos_.front(); |
| 312 | delayed_echos_.pop_front(); |
| 313 | } |
| 314 | |
[email protected] | 706b69f | 2012-07-27 04:59:30 | [diff] [blame] | 315 | bool have_context = false; |
[email protected] | 0f938689 | 2012-02-15 01:44:07 | [diff] [blame] | 316 | if (decoder_.get()) |
[email protected] | 706b69f | 2012-07-27 04:59:30 | [diff] [blame] | 317 | have_context = decoder_->MakeCurrent(); |
[email protected] | 0f938689 | 2012-02-15 01:44:07 | [diff] [blame] | 318 | FOR_EACH_OBSERVER(DestructionObserver, |
| 319 | destruction_observers_, |
| 320 | OnWillDestroyStub(this)); |
| 321 | |
[email protected] | 79311e8 | 2011-09-20 00:40:50 | [diff] [blame] | 322 | if (decoder_.get()) { |
[email protected] | 706b69f | 2012-07-27 04:59:30 | [diff] [blame] | 323 | decoder_->Destroy(have_context); |
[email protected] | 79311e8 | 2011-09-20 00:40:50 | [diff] [blame] | 324 | decoder_.reset(); |
| 325 | } |
| 326 | |
[email protected] | 4ee0c305 | 2011-09-16 19:30:36 | [diff] [blame] | 327 | command_buffer_.reset(); |
[email protected] | 79311e8 | 2011-09-20 00:40:50 | [diff] [blame] | 328 | |
| 329 | context_ = NULL; |
| 330 | surface_ = NULL; |
[email protected] | 672c731 | 2012-02-03 16:28:55 | [diff] [blame] | 331 | |
[email protected] | 5d5374e | 2012-06-19 16:46:51 | [diff] [blame] | 332 | channel_->gpu_channel_manager()->gpu_memory_manager()->ScheduleManage(false); |
[email protected] | 79311e8 | 2011-09-20 00:40:50 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | void GpuCommandBufferStub::OnInitializeFailed(IPC::Message* reply_message) { |
| 336 | Destroy(); |
[email protected] | 2e7bbf2 | 2011-07-22 18:41:29 | [diff] [blame] | 337 | GpuCommandBufferMsg_Initialize::WriteReplyParams(reply_message, false); |
| 338 | Send(reply_message); |
| 339 | } |
| 340 | |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 341 | void GpuCommandBufferStub::OnInitialize( |
[email protected] | 310bed51 | 2011-05-09 21:12:25 | [diff] [blame] | 342 | IPC::Message* reply_message) { |
[email protected] | 3551cb20 | 2012-05-24 10:55:32 | [diff] [blame] | 343 | TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnInitialize"); |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 344 | DCHECK(!command_buffer_.get()); |
| 345 | |
[email protected] | 1d471e8 | 2012-06-01 06:13:40 | [diff] [blame] | 346 | command_buffer_.reset(new gpu::CommandBufferService( |
| 347 | context_group_->transfer_buffer_manager())); |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 348 | |
[email protected] | 503b3a2 | 2011-12-12 23:29:40 | [diff] [blame] | 349 | if (!command_buffer_->Initialize()) { |
[email protected] | 198e0c44 | 2011-12-02 19:45:06 | [diff] [blame] | 350 | DLOG(ERROR) << "CommandBufferService failed to initialize.\n"; |
[email protected] | 79311e8 | 2011-09-20 00:40:50 | [diff] [blame] | 351 | OnInitializeFailed(reply_message); |
| 352 | return; |
| 353 | } |
| 354 | |
| 355 | decoder_.reset(::gpu::gles2::GLES2Decoder::Create(context_group_.get())); |
| 356 | |
| 357 | scheduler_.reset(new gpu::GpuScheduler(command_buffer_.get(), |
| 358 | decoder_.get(), |
[email protected] | 8a9e1a1 | 2011-12-20 01:46:05 | [diff] [blame] | 359 | decoder_.get())); |
[email protected] | 6802e3c6 | 2012-06-06 22:32:44 | [diff] [blame] | 360 | if (preempt_by_counter_.get()) |
| 361 | scheduler_->SetPreemptByCounter(preempt_by_counter_); |
[email protected] | 79311e8 | 2011-09-20 00:40:50 | [diff] [blame] | 362 | |
| 363 | decoder_->set_engine(scheduler_.get()); |
| 364 | |
[email protected] | 47940c8 | 2012-02-08 02:23:49 | [diff] [blame] | 365 | if (!handle_.is_null()) { |
[email protected] | 839d517 | 2011-10-13 17:18:11 | [diff] [blame] | 366 | #if defined(OS_MACOSX) || defined(UI_COMPOSITOR_IMAGE_TRANSPORT) |
[email protected] | 2e7bbf2 | 2011-07-22 18:41:29 | [diff] [blame] | 367 | if (software_) { |
[email protected] | 198e0c44 | 2011-12-02 19:45:06 | [diff] [blame] | 368 | DLOG(ERROR) << "No software support.\n"; |
[email protected] | 2e7bbf2 | 2011-07-22 18:41:29 | [diff] [blame] | 369 | OnInitializeFailed(reply_message); |
| 370 | return; |
| 371 | } |
[email protected] | 290fc49 | 2011-11-22 23:25:23 | [diff] [blame] | 372 | #endif |
[email protected] | 2e7bbf2 | 2011-07-22 18:41:29 | [diff] [blame] | 373 | |
[email protected] | 79311e8 | 2011-09-20 00:40:50 | [diff] [blame] | 374 | surface_ = ImageTransportSurface::CreateSurface( |
| 375 | channel_->gpu_channel_manager(), |
[email protected] | 9f4f332 | 2012-01-18 22:29:56 | [diff] [blame] | 376 | this, |
[email protected] | 04d58ce | 2011-09-29 13:12:23 | [diff] [blame] | 377 | handle_); |
[email protected] | 79311e8 | 2011-09-20 00:40:50 | [diff] [blame] | 378 | } else { |
[email protected] | b8673e6 | 2012-09-25 03:15:00 | [diff] [blame] | 379 | GpuChannelManager* manager = channel_->gpu_channel_manager(); |
| 380 | surface_ = manager->GetDefaultOffscreenSurface(); |
[email protected] | 79311e8 | 2011-09-20 00:40:50 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | if (!surface_.get()) { |
[email protected] | cdcd5bd | 2011-10-15 00:19:38 | [diff] [blame] | 384 | // Ensure the decoder is not destroyed if it is not initialized. |
| 385 | decoder_.reset(); |
| 386 | |
[email protected] | cc63025a | 2011-10-29 02:16:24 | [diff] [blame] | 387 | DLOG(ERROR) << "Failed to create surface.\n"; |
[email protected] | 79311e8 | 2011-09-20 00:40:50 | [diff] [blame] | 388 | OnInitializeFailed(reply_message); |
| 389 | return; |
| 390 | } |
| 391 | |
[email protected] | 276f8906 | 2011-10-13 22:55:50 | [diff] [blame] | 392 | context_ = gfx::GLContext::CreateGLContext( |
| 393 | channel_->share_group(), |
| 394 | surface_.get(), |
[email protected] | 96a28ea | 2012-06-09 02:16:09 | [diff] [blame] | 395 | gpu_preference_); |
[email protected] | 79311e8 | 2011-09-20 00:40:50 | [diff] [blame] | 396 | if (!context_.get()) { |
[email protected] | cdcd5bd | 2011-10-15 00:19:38 | [diff] [blame] | 397 | // Ensure the decoder is not destroyed if it is not initialized. |
| 398 | decoder_.reset(); |
| 399 | |
[email protected] | cc63025a | 2011-10-29 02:16:24 | [diff] [blame] | 400 | DLOG(ERROR) << "Failed to create context.\n"; |
[email protected] | 79311e8 | 2011-09-20 00:40:50 | [diff] [blame] | 401 | OnInitializeFailed(reply_message); |
| 402 | return; |
| 403 | } |
[email protected] | 4bbe6d0c | 2011-09-16 18:58:54 | [diff] [blame] | 404 | |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 405 | if (!context_->MakeCurrent(surface_.get())) { |
[email protected] | 35a0b4b | 2012-06-15 03:53:30 | [diff] [blame] | 406 | // Ensure the decoder is not destroyed if it is not initialized. |
| 407 | decoder_.reset(); |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 408 | LOG(ERROR) << "Failed to make context current."; |
| 409 | OnInitializeFailed(reply_message); |
| 410 | return; |
| 411 | } |
| 412 | |
[email protected] | 65dfc60 | 2012-07-23 20:39:39 | [diff] [blame] | 413 | if (!context_group_->has_program_cache()) { |
| 414 | context_group_->set_program_cache( |
| 415 | channel_->gpu_channel_manager()->program_cache()); |
| 416 | } |
| 417 | |
[email protected] | 79311e8 | 2011-09-20 00:40:50 | [diff] [blame] | 418 | // Initialize the decoder with either the view or pbuffer GLContext. |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 419 | if (!decoder_->Initialize(surface_, |
| 420 | context_, |
[email protected] | 06994467 | 2012-04-25 20:52:23 | [diff] [blame] | 421 | !surface_id(), |
[email protected] | 79311e8 | 2011-09-20 00:40:50 | [diff] [blame] | 422 | initial_size_, |
[email protected] | e82fb79 | 2011-09-22 00:33:29 | [diff] [blame] | 423 | disallowed_features_, |
[email protected] | 79311e8 | 2011-09-20 00:40:50 | [diff] [blame] | 424 | allowed_extensions_.c_str(), |
| 425 | requested_attribs_)) { |
[email protected] | cc63025a | 2011-10-29 02:16:24 | [diff] [blame] | 426 | DLOG(ERROR) << "Failed to initialize decoder."; |
[email protected] | 79311e8 | 2011-09-20 00:40:50 | [diff] [blame] | 427 | OnInitializeFailed(reply_message); |
| 428 | return; |
| 429 | } |
| 430 | |
| 431 | if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 432 | switches::kEnableGPUServiceLogging)) { |
[email protected] | e844ae2 | 2012-01-14 03:36:26 | [diff] [blame] | 433 | decoder_->set_log_commands(true); |
[email protected] | 79311e8 | 2011-09-20 00:40:50 | [diff] [blame] | 434 | } |
| 435 | |
[email protected] | 6b6e7ee | 2011-12-13 08:04:52 | [diff] [blame] | 436 | decoder_->SetMsgCallback( |
| 437 | base::Bind(&GpuCommandBufferStub::SendConsoleMessage, |
| 438 | base::Unretained(this))); |
| 439 | |
[email protected] | 79311e8 | 2011-09-20 00:40:50 | [diff] [blame] | 440 | command_buffer_->SetPutOffsetChangeCallback( |
[email protected] | d1a9e06 | 2012-07-13 00:45:14 | [diff] [blame] | 441 | base::Bind(&GpuCommandBufferStub::PutChanged, base::Unretained(this))); |
[email protected] | 503b3a2 | 2011-12-12 23:29:40 | [diff] [blame] | 442 | command_buffer_->SetGetBufferChangeCallback( |
| 443 | base::Bind(&gpu::GpuScheduler::SetGetBuffer, |
| 444 | base::Unretained(scheduler_.get()))); |
[email protected] | 79311e8 | 2011-09-20 00:40:50 | [diff] [blame] | 445 | command_buffer_->SetParseErrorCallback( |
[email protected] | 9d37f06 | 2011-11-22 01:24:52 | [diff] [blame] | 446 | base::Bind(&GpuCommandBufferStub::OnParseError, base::Unretained(this))); |
[email protected] | 79311e8 | 2011-09-20 00:40:50 | [diff] [blame] | 447 | scheduler_->SetScheduledCallback( |
[email protected] | ac9ab81 | 2012-03-06 22:44:05 | [diff] [blame] | 448 | base::Bind(&GpuCommandBufferStub::OnReschedule, base::Unretained(this))); |
[email protected] | 79311e8 | 2011-09-20 00:40:50 | [diff] [blame] | 449 | |
[email protected] | 79311e8 | 2011-09-20 00:40:50 | [diff] [blame] | 450 | if (watchdog_) { |
| 451 | scheduler_->SetCommandProcessedCallback( |
[email protected] | 9d37f06 | 2011-11-22 01:24:52 | [diff] [blame] | 452 | base::Bind(&GpuCommandBufferStub::OnCommandProcessed, |
| 453 | base::Unretained(this))); |
[email protected] | 79311e8 | 2011-09-20 00:40:50 | [diff] [blame] | 454 | } |
| 455 | |
[email protected] | 34aaa568 | 2012-09-25 00:48:50 | [diff] [blame] | 456 | #if defined(OS_ANDROID) |
| 457 | decoder_->SetStreamTextureManager(channel_->stream_texture_manager()); |
| 458 | #endif |
| 459 | |
[email protected] | 79311e8 | 2011-09-20 00:40:50 | [diff] [blame] | 460 | if (parent_stub_for_initialization_) { |
| 461 | decoder_->SetParent(parent_stub_for_initialization_->decoder_.get(), |
| 462 | parent_texture_for_initialization_); |
| 463 | parent_stub_for_initialization_.reset(); |
| 464 | parent_texture_for_initialization_ = 0; |
| 465 | } |
[email protected] | 310bed51 | 2011-05-09 21:12:25 | [diff] [blame] | 466 | |
[email protected] | 2e7bbf2 | 2011-07-22 18:41:29 | [diff] [blame] | 467 | GpuCommandBufferMsg_Initialize::WriteReplyParams(reply_message, true); |
[email protected] | 310bed51 | 2011-05-09 21:12:25 | [diff] [blame] | 468 | Send(reply_message); |
[email protected] | 672c731 | 2012-02-03 16:28:55 | [diff] [blame] | 469 | |
[email protected] | 5d5374e | 2012-06-19 16:46:51 | [diff] [blame] | 470 | channel_->gpu_channel_manager()->gpu_memory_manager()->ScheduleManage(true); |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 471 | } |
| 472 | |
[email protected] | 503b3a2 | 2011-12-12 23:29:40 | [diff] [blame] | 473 | void GpuCommandBufferStub::OnSetGetBuffer( |
| 474 | int32 shm_id, IPC::Message* reply_message) { |
[email protected] | 3551cb20 | 2012-05-24 10:55:32 | [diff] [blame] | 475 | TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnSetGetBuffer"); |
[email protected] | 773bf5e | 2012-01-06 01:07:13 | [diff] [blame] | 476 | if (command_buffer_.get()) { |
| 477 | command_buffer_->SetGetBuffer(shm_id); |
| 478 | } else { |
| 479 | DLOG(ERROR) << "no command_buffer."; |
| 480 | reply_message->set_reply_error(); |
| 481 | } |
[email protected] | 503b3a2 | 2011-12-12 23:29:40 | [diff] [blame] | 482 | Send(reply_message); |
| 483 | } |
| 484 | |
[email protected] | 68eff95 | 2012-02-17 21:56:35 | [diff] [blame] | 485 | void GpuCommandBufferStub::OnSetSharedStateBuffer( |
| 486 | int32 shm_id, IPC::Message* reply_message) { |
[email protected] | 3551cb20 | 2012-05-24 10:55:32 | [diff] [blame] | 487 | TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnSetSharedStateBuffer"); |
[email protected] | 68eff95 | 2012-02-17 21:56:35 | [diff] [blame] | 488 | if (command_buffer_.get()) { |
| 489 | command_buffer_->SetSharedStateBuffer(shm_id); |
| 490 | } else { |
| 491 | DLOG(ERROR) << "no command_buffer."; |
| 492 | reply_message->set_reply_error(); |
| 493 | } |
| 494 | Send(reply_message); |
| 495 | } |
| 496 | |
[email protected] | 3c644d8 | 2011-06-20 19:58:24 | [diff] [blame] | 497 | void GpuCommandBufferStub::OnSetParent(int32 parent_route_id, |
| 498 | uint32 parent_texture_id, |
| 499 | IPC::Message* reply_message) { |
[email protected] | 3551cb20 | 2012-05-24 10:55:32 | [diff] [blame] | 500 | TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnSetParent"); |
[email protected] | e7da6aef | 2011-06-22 19:29:03 | [diff] [blame] | 501 | GpuCommandBufferStub* parent_stub = NULL; |
| 502 | if (parent_route_id != MSG_ROUTING_NONE) { |
| 503 | parent_stub = channel_->LookupCommandBuffer(parent_route_id); |
[email protected] | 3c644d8 | 2011-06-20 19:58:24 | [diff] [blame] | 504 | } |
| 505 | |
[email protected] | e7da6aef | 2011-06-22 19:29:03 | [diff] [blame] | 506 | bool result = true; |
| 507 | if (scheduler_.get()) { |
[email protected] | 79311e8 | 2011-09-20 00:40:50 | [diff] [blame] | 508 | gpu::gles2::GLES2Decoder* parent_decoder = |
| 509 | parent_stub ? parent_stub->decoder_.get() : NULL; |
| 510 | result = decoder_->SetParent(parent_decoder, parent_texture_id); |
[email protected] | e7da6aef | 2011-06-22 19:29:03 | [diff] [blame] | 511 | } else { |
| 512 | // If we don't have a scheduler, it means that Initialize hasn't been called |
| 513 | // yet. Keep around the requested parent stub and texture so that we can set |
| 514 | // it in Initialize(). |
| 515 | parent_stub_for_initialization_ = parent_stub ? |
| 516 | parent_stub->AsWeakPtr() : base::WeakPtr<GpuCommandBufferStub>(); |
| 517 | parent_texture_for_initialization_ = parent_texture_id; |
| 518 | } |
[email protected] | 3c644d8 | 2011-06-20 19:58:24 | [diff] [blame] | 519 | GpuCommandBufferMsg_SetParent::WriteReplyParams(reply_message, result); |
| 520 | Send(reply_message); |
| 521 | } |
| 522 | |
[email protected] | 310bed51 | 2011-05-09 21:12:25 | [diff] [blame] | 523 | void GpuCommandBufferStub::OnGetState(IPC::Message* reply_message) { |
[email protected] | 3551cb20 | 2012-05-24 10:55:32 | [diff] [blame] | 524 | TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnGetState"); |
[email protected] | 773bf5e | 2012-01-06 01:07:13 | [diff] [blame] | 525 | if (command_buffer_.get()) { |
| 526 | gpu::CommandBuffer::State state = command_buffer_->GetState(); |
| 527 | if (state.error == gpu::error::kLostContext && |
| 528 | gfx::GLContext::LosesAllContextsOnContextLost()) |
| 529 | channel_->LoseAllContexts(); |
[email protected] | 310bed51 | 2011-05-09 21:12:25 | [diff] [blame] | 530 | |
[email protected] | 773bf5e | 2012-01-06 01:07:13 | [diff] [blame] | 531 | GpuCommandBufferMsg_GetState::WriteReplyParams(reply_message, state); |
| 532 | } else { |
| 533 | DLOG(ERROR) << "no command_buffer."; |
| 534 | reply_message->set_reply_error(); |
| 535 | } |
[email protected] | 310bed51 | 2011-05-09 21:12:25 | [diff] [blame] | 536 | Send(reply_message); |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 537 | } |
| 538 | |
[email protected] | 0a68ac87 | 2011-06-07 04:48:27 | [diff] [blame] | 539 | void GpuCommandBufferStub::OnParseError() { |
| 540 | TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnParseError"); |
[email protected] | 773bf5e | 2012-01-06 01:07:13 | [diff] [blame] | 541 | DCHECK(command_buffer_.get()); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 542 | gpu::CommandBuffer::State state = command_buffer_->GetState(); |
| 543 | IPC::Message* msg = new GpuCommandBufferMsg_Destroyed( |
| 544 | route_id_, state.context_lost_reason); |
[email protected] | 0a68ac87 | 2011-06-07 04:48:27 | [diff] [blame] | 545 | msg->set_unblock(true); |
| 546 | Send(msg); |
| 547 | } |
| 548 | |
[email protected] | 451e966 | 2011-10-10 21:14:34 | [diff] [blame] | 549 | void GpuCommandBufferStub::OnGetStateFast(IPC::Message* reply_message) { |
| 550 | TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnGetStateFast"); |
[email protected] | 773bf5e | 2012-01-06 01:07:13 | [diff] [blame] | 551 | DCHECK(command_buffer_.get()); |
[email protected] | d0f02c4 | 2011-07-21 21:40:48 | [diff] [blame] | 552 | gpu::CommandBuffer::State state = command_buffer_->GetState(); |
[email protected] | 451e966 | 2011-10-10 21:14:34 | [diff] [blame] | 553 | if (state.error == gpu::error::kLostContext && |
| 554 | gfx::GLContext::LosesAllContextsOnContextLost()) |
| 555 | channel_->LoseAllContexts(); |
[email protected] | 1d4ea84 | 2011-07-20 01:11:51 | [diff] [blame] | 556 | |
[email protected] | 451e966 | 2011-10-10 21:14:34 | [diff] [blame] | 557 | GpuCommandBufferMsg_GetStateFast::WriteReplyParams(reply_message, state); |
| 558 | Send(reply_message); |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 559 | } |
| 560 | |
[email protected] | 451e966 | 2011-10-10 21:14:34 | [diff] [blame] | 561 | void GpuCommandBufferStub::OnAsyncFlush(int32 put_offset, |
| 562 | uint32 flush_count) { |
| 563 | TRACE_EVENT1("gpu", "GpuCommandBufferStub::OnAsyncFlush", |
| 564 | "put_offset", put_offset); |
[email protected] | 773bf5e | 2012-01-06 01:07:13 | [diff] [blame] | 565 | DCHECK(command_buffer_.get()); |
[email protected] | fde205d | 2011-05-31 22:29:50 | [diff] [blame] | 566 | if (flush_count - last_flush_count_ < 0x8000000U) { |
[email protected] | a3847714 | 2011-05-28 02:45:58 | [diff] [blame] | 567 | last_flush_count_ = flush_count; |
| 568 | command_buffer_->Flush(put_offset); |
| 569 | } else { |
[email protected] | fde205d | 2011-05-31 22:29:50 | [diff] [blame] | 570 | // We received this message out-of-order. This should not happen but is here |
| 571 | // to catch regressions. Ignore the message. |
| 572 | NOTREACHED() << "Received a Flush message out-of-order"; |
[email protected] | a3847714 | 2011-05-28 02:45:58 | [diff] [blame] | 573 | } |
[email protected] | d0f02c4 | 2011-07-21 21:40:48 | [diff] [blame] | 574 | |
| 575 | ReportState(); |
| 576 | } |
| 577 | |
| 578 | void GpuCommandBufferStub::OnRescheduled() { |
[email protected] | 20f656f | 2011-12-08 02:25:15 | [diff] [blame] | 579 | gpu::CommandBuffer::State pre_state = command_buffer_->GetLastState(); |
| 580 | command_buffer_->Flush(pre_state.put_offset); |
| 581 | gpu::CommandBuffer::State post_state = command_buffer_->GetLastState(); |
[email protected] | d0f02c4 | 2011-07-21 21:40:48 | [diff] [blame] | 582 | |
[email protected] | 20f656f | 2011-12-08 02:25:15 | [diff] [blame] | 583 | if (pre_state.get_offset != post_state.get_offset) |
| 584 | ReportState(); |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 585 | } |
| 586 | |
[email protected] | ce9eea60 | 2011-04-12 20:09:57 | [diff] [blame] | 587 | void GpuCommandBufferStub::OnCreateTransferBuffer(int32 size, |
| 588 | int32 id_request, |
[email protected] | 310bed51 | 2011-05-09 21:12:25 | [diff] [blame] | 589 | IPC::Message* reply_message) { |
[email protected] | 3551cb20 | 2012-05-24 10:55:32 | [diff] [blame] | 590 | TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnCreateTransferBuffer"); |
[email protected] | 773bf5e | 2012-01-06 01:07:13 | [diff] [blame] | 591 | if (command_buffer_.get()) { |
| 592 | int32 id = command_buffer_->CreateTransferBuffer(size, id_request); |
| 593 | GpuCommandBufferMsg_CreateTransferBuffer::WriteReplyParams( |
| 594 | reply_message, id); |
| 595 | } else { |
| 596 | reply_message->set_reply_error(); |
| 597 | } |
[email protected] | 310bed51 | 2011-05-09 21:12:25 | [diff] [blame] | 598 | Send(reply_message); |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 599 | } |
| 600 | |
[email protected] | 0100b7a | 2011-02-24 22:54:50 | [diff] [blame] | 601 | void GpuCommandBufferStub::OnRegisterTransferBuffer( |
| 602 | base::SharedMemoryHandle transfer_buffer, |
| 603 | size_t size, |
[email protected] | ce9eea60 | 2011-04-12 20:09:57 | [diff] [blame] | 604 | int32 id_request, |
[email protected] | 310bed51 | 2011-05-09 21:12:25 | [diff] [blame] | 605 | IPC::Message* reply_message) { |
[email protected] | 3551cb20 | 2012-05-24 10:55:32 | [diff] [blame] | 606 | TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnRegisterTransferBuffer"); |
[email protected] | 0100b7a | 2011-02-24 22:54:50 | [diff] [blame] | 607 | base::SharedMemory shared_memory(transfer_buffer, false); |
[email protected] | 7df1d1a | 2011-02-26 02:07:57 | [diff] [blame] | 608 | |
[email protected] | 773bf5e | 2012-01-06 01:07:13 | [diff] [blame] | 609 | if (command_buffer_.get()) { |
| 610 | int32 id = command_buffer_->RegisterTransferBuffer(&shared_memory, |
| 611 | size, |
| 612 | id_request); |
| 613 | GpuCommandBufferMsg_RegisterTransferBuffer::WriteReplyParams(reply_message, |
| 614 | id); |
| 615 | } else { |
| 616 | reply_message->set_reply_error(); |
| 617 | } |
[email protected] | 310bed51 | 2011-05-09 21:12:25 | [diff] [blame] | 618 | |
[email protected] | 310bed51 | 2011-05-09 21:12:25 | [diff] [blame] | 619 | Send(reply_message); |
[email protected] | 0100b7a | 2011-02-24 22:54:50 | [diff] [blame] | 620 | } |
| 621 | |
[email protected] | 310bed51 | 2011-05-09 21:12:25 | [diff] [blame] | 622 | void GpuCommandBufferStub::OnDestroyTransferBuffer( |
| 623 | int32 id, |
| 624 | IPC::Message* reply_message) { |
[email protected] | 3551cb20 | 2012-05-24 10:55:32 | [diff] [blame] | 625 | TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnDestroyTransferBuffer"); |
[email protected] | 773bf5e | 2012-01-06 01:07:13 | [diff] [blame] | 626 | if (command_buffer_.get()) { |
| 627 | command_buffer_->DestroyTransferBuffer(id); |
| 628 | } else { |
| 629 | reply_message->set_reply_error(); |
| 630 | } |
[email protected] | 310bed51 | 2011-05-09 21:12:25 | [diff] [blame] | 631 | Send(reply_message); |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | void GpuCommandBufferStub::OnGetTransferBuffer( |
| 635 | int32 id, |
[email protected] | 310bed51 | 2011-05-09 21:12:25 | [diff] [blame] | 636 | IPC::Message* reply_message) { |
[email protected] | 3551cb20 | 2012-05-24 10:55:32 | [diff] [blame] | 637 | TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnGetTransferBuffer"); |
[email protected] | 773bf5e | 2012-01-06 01:07:13 | [diff] [blame] | 638 | if (command_buffer_.get()) { |
| 639 | base::SharedMemoryHandle transfer_buffer = base::SharedMemoryHandle(); |
| 640 | uint32 size = 0; |
[email protected] | 310bed51 | 2011-05-09 21:12:25 | [diff] [blame] | 641 | |
[email protected] | 773bf5e | 2012-01-06 01:07:13 | [diff] [blame] | 642 | gpu::Buffer buffer = command_buffer_->GetTransferBuffer(id); |
| 643 | if (buffer.shared_memory) { |
[email protected] | cd0bd79 | 2012-04-14 00:52:16 | [diff] [blame] | 644 | #if defined(OS_WIN) |
| 645 | transfer_buffer = NULL; |
[email protected] | d30ce6e | 2012-04-16 15:32:36 | [diff] [blame] | 646 | content::BrokerDuplicateHandle(buffer.shared_memory->handle(), |
[email protected] | cd0bd79 | 2012-04-14 00:52:16 | [diff] [blame] | 647 | channel_->renderer_pid(), &transfer_buffer, FILE_MAP_READ | |
| 648 | FILE_MAP_WRITE, 0); |
[email protected] | 8f9904d | 2012-05-09 00:20:22 | [diff] [blame] | 649 | DCHECK(transfer_buffer != NULL); |
[email protected] | cd0bd79 | 2012-04-14 00:52:16 | [diff] [blame] | 650 | #else |
| 651 | buffer.shared_memory->ShareToProcess(channel_->renderer_pid(), |
[email protected] | 773bf5e | 2012-01-06 01:07:13 | [diff] [blame] | 652 | &transfer_buffer); |
[email protected] | cd0bd79 | 2012-04-14 00:52:16 | [diff] [blame] | 653 | #endif |
[email protected] | 773bf5e | 2012-01-06 01:07:13 | [diff] [blame] | 654 | size = buffer.size; |
| 655 | } |
| 656 | |
| 657 | GpuCommandBufferMsg_GetTransferBuffer::WriteReplyParams(reply_message, |
| 658 | transfer_buffer, |
| 659 | size); |
| 660 | } else { |
| 661 | reply_message->set_reply_error(); |
| 662 | } |
[email protected] | 310bed51 | 2011-05-09 21:12:25 | [diff] [blame] | 663 | Send(reply_message); |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 664 | } |
| 665 | |
[email protected] | 310bed51 | 2011-05-09 21:12:25 | [diff] [blame] | 666 | void GpuCommandBufferStub::OnCommandProcessed() { |
| 667 | if (watchdog_) |
| 668 | watchdog_->CheckArmed(); |
| 669 | } |
| 670 | |
[email protected] | ef16c17 | 2011-04-28 23:37:14 | [diff] [blame] | 671 | void GpuCommandBufferStub::ReportState() { |
| 672 | gpu::CommandBuffer::State state = command_buffer_->GetState(); |
| 673 | if (state.error == gpu::error::kLostContext && |
| 674 | gfx::GLContext::LosesAllContextsOnContextLost()) { |
| 675 | channel_->LoseAllContexts(); |
| 676 | } else { |
[email protected] | 68eff95 | 2012-02-17 21:56:35 | [diff] [blame] | 677 | command_buffer_->UpdateState(); |
[email protected] | ef16c17 | 2011-04-28 23:37:14 | [diff] [blame] | 678 | } |
| 679 | } |
| 680 | |
[email protected] | d1a9e06 | 2012-07-13 00:45:14 | [diff] [blame] | 681 | void GpuCommandBufferStub::PutChanged() { |
| 682 | FastSetActiveURL(active_url_, active_url_hash_); |
| 683 | scheduler_->PutChanged(); |
| 684 | } |
| 685 | |
[email protected] | a13da24 | 2011-07-07 19:48:17 | [diff] [blame] | 686 | void GpuCommandBufferStub::OnCreateVideoDecoder( |
[email protected] | e5ca636 | 2012-03-30 09:45:58 | [diff] [blame] | 687 | media::VideoCodecProfile profile, |
[email protected] | c842306 | 2011-07-29 19:25:38 | [diff] [blame] | 688 | IPC::Message* reply_message) { |
[email protected] | 3551cb20 | 2012-05-24 10:55:32 | [diff] [blame] | 689 | TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnCreateVideoDecoder"); |
[email protected] | 502e605 | 2011-08-17 00:17:23 | [diff] [blame] | 690 | int decoder_route_id = channel_->GenerateRouteID(); |
[email protected] | 502e605 | 2011-08-17 00:17:23 | [diff] [blame] | 691 | GpuVideoDecodeAccelerator* decoder = |
| 692 | new GpuVideoDecodeAccelerator(this, decoder_route_id, this); |
| 693 | video_decoders_.AddWithID(decoder, decoder_route_id); |
| 694 | channel_->AddRoute(decoder_route_id, decoder); |
[email protected] | cd0bd79 | 2012-04-14 00:52:16 | [diff] [blame] | 695 | decoder->Initialize(profile, reply_message); |
[email protected] | a13da24 | 2011-07-07 19:48:17 | [diff] [blame] | 696 | } |
| 697 | |
[email protected] | 502e605 | 2011-08-17 00:17:23 | [diff] [blame] | 698 | void GpuCommandBufferStub::OnDestroyVideoDecoder(int decoder_route_id) { |
[email protected] | 3551cb20 | 2012-05-24 10:55:32 | [diff] [blame] | 699 | TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnDestroyVideoDecoder"); |
[email protected] | 502e605 | 2011-08-17 00:17:23 | [diff] [blame] | 700 | channel_->RemoveRoute(decoder_route_id); |
| 701 | video_decoders_.Remove(decoder_route_id); |
[email protected] | a13da24 | 2011-07-07 19:48:17 | [diff] [blame] | 702 | } |
| 703 | |
[email protected] | 8cc980c5 | 2011-10-14 20:35:51 | [diff] [blame] | 704 | void GpuCommandBufferStub::OnSetSurfaceVisible(bool visible) { |
[email protected] | 3551cb20 | 2012-05-24 10:55:32 | [diff] [blame] | 705 | TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnSetSurfaceVisible"); |
[email protected] | 5178c442 | 2012-10-17 12:08:07 | [diff] [blame^] | 706 | memory_manager_state_->visible = visible; |
| 707 | memory_manager_state_->last_used_time = base::TimeTicks::Now(); |
| 708 | channel_->gpu_channel_manager()->gpu_memory_manager()-> |
| 709 | ScheduleManage(visible); |
[email protected] | 8cc980c5 | 2011-10-14 20:35:51 | [diff] [blame] | 710 | } |
| 711 | |
[email protected] | 251622e | 2012-03-23 16:17:40 | [diff] [blame] | 712 | void GpuCommandBufferStub::OnDiscardBackbuffer() { |
[email protected] | 3551cb20 | 2012-05-24 10:55:32 | [diff] [blame] | 713 | TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnDiscardBackbuffer"); |
[email protected] | 251622e | 2012-03-23 16:17:40 | [diff] [blame] | 714 | if (!surface_) |
| 715 | return; |
[email protected] | 3ac71bf | 2012-05-16 15:55:53 | [diff] [blame] | 716 | surface_->SetBackbufferAllocation(false); |
[email protected] | 251622e | 2012-03-23 16:17:40 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | void GpuCommandBufferStub::OnEnsureBackbuffer() { |
[email protected] | 3551cb20 | 2012-05-24 10:55:32 | [diff] [blame] | 720 | TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnEnsureBackbuffer"); |
[email protected] | 251622e | 2012-03-23 16:17:40 | [diff] [blame] | 721 | if (!surface_) |
| 722 | return; |
[email protected] | 3ac71bf | 2012-05-16 15:55:53 | [diff] [blame] | 723 | surface_->SetBackbufferAllocation(true); |
[email protected] | 251622e | 2012-03-23 16:17:40 | [diff] [blame] | 724 | } |
| 725 | |
[email protected] | c02f93e4 | 2012-06-05 23:35:16 | [diff] [blame] | 726 | void GpuCommandBufferStub::AddSyncPoint(uint32 sync_point) { |
| 727 | sync_points_.push_back(sync_point); |
| 728 | } |
| 729 | |
| 730 | void GpuCommandBufferStub::OnRetireSyncPoint(uint32 sync_point) { |
| 731 | DCHECK(!sync_points_.empty() && sync_points_.front() == sync_point); |
| 732 | sync_points_.pop_front(); |
| 733 | GpuChannelManager* manager = channel_->gpu_channel_manager(); |
| 734 | manager->sync_point_manager()->RetireSyncPoint(sync_point); |
| 735 | } |
| 736 | |
| 737 | void GpuCommandBufferStub::OnWaitSyncPoint(uint32 sync_point) { |
[email protected] | 35a0b4b | 2012-06-15 03:53:30 | [diff] [blame] | 738 | if (sync_point_wait_count_ == 0) { |
| 739 | TRACE_EVENT_ASYNC_BEGIN1("gpu", "WaitSyncPoint", this, |
| 740 | "GpuCommandBufferStub", this); |
| 741 | } |
| 742 | ++sync_point_wait_count_; |
[email protected] | c02f93e4 | 2012-06-05 23:35:16 | [diff] [blame] | 743 | GpuChannelManager* manager = channel_->gpu_channel_manager(); |
| 744 | manager->sync_point_manager()->AddSyncPointCallback( |
| 745 | sync_point, |
| 746 | base::Bind(&GpuCommandBufferStub::OnSyncPointRetired, |
| 747 | this->AsWeakPtr())); |
| 748 | } |
| 749 | |
| 750 | void GpuCommandBufferStub::OnSyncPointRetired() { |
[email protected] | 35a0b4b | 2012-06-15 03:53:30 | [diff] [blame] | 751 | --sync_point_wait_count_; |
| 752 | if (sync_point_wait_count_ == 0) { |
| 753 | TRACE_EVENT_ASYNC_END1("gpu", "WaitSyncPoint", this, |
| 754 | "GpuCommandBufferStub", this); |
| 755 | } |
| 756 | OnReschedule(); |
[email protected] | c02f93e4 | 2012-06-05 23:35:16 | [diff] [blame] | 757 | } |
| 758 | |
[email protected] | 5ab44ef | 2012-06-19 00:03:51 | [diff] [blame] | 759 | void GpuCommandBufferStub::OnSignalSyncPoint(uint32 sync_point, uint32 id) { |
| 760 | GpuChannelManager* manager = channel_->gpu_channel_manager(); |
| 761 | manager->sync_point_manager()->AddSyncPointCallback( |
| 762 | sync_point, |
| 763 | base::Bind(&GpuCommandBufferStub::OnSignalSyncPointAck, |
| 764 | this->AsWeakPtr(), |
| 765 | id)); |
| 766 | } |
| 767 | |
| 768 | void GpuCommandBufferStub::OnSignalSyncPointAck(uint32 id) { |
| 769 | Send(new GpuCommandBufferMsg_SignalSyncPointAck(route_id_, id)); |
| 770 | } |
| 771 | |
[email protected] | c1f1214 | 2012-05-01 22:21:06 | [diff] [blame] | 772 | void GpuCommandBufferStub::OnSetClientHasMemoryAllocationChangedCallback( |
| 773 | bool has_callback) { |
[email protected] | 3551cb20 | 2012-05-24 10:55:32 | [diff] [blame] | 774 | TRACE_EVENT0( |
| 775 | "gpu", |
| 776 | "GpuCommandBufferStub::OnSetClientHasMemoryAllocationChangedCallback"); |
[email protected] | 5178c442 | 2012-10-17 12:08:07 | [diff] [blame^] | 777 | memory_manager_state_->client_has_memory_allocation_changed_callback = |
| 778 | has_callback; |
[email protected] | 5d5374e | 2012-06-19 16:46:51 | [diff] [blame] | 779 | channel_->gpu_channel_manager()->gpu_memory_manager()-> |
| 780 | ScheduleManage(false); |
[email protected] | c1f1214 | 2012-05-01 22:21:06 | [diff] [blame] | 781 | } |
| 782 | |
[email protected] | 6b6e7ee | 2011-12-13 08:04:52 | [diff] [blame] | 783 | void GpuCommandBufferStub::SendConsoleMessage( |
| 784 | int32 id, |
| 785 | const std::string& message) { |
| 786 | GPUCommandBufferConsoleMessage console_message; |
| 787 | console_message.id = id; |
| 788 | console_message.message = message; |
| 789 | IPC::Message* msg = new GpuCommandBufferMsg_ConsoleMsg( |
| 790 | route_id_, console_message); |
| 791 | msg->set_unblock(true); |
| 792 | Send(msg); |
| 793 | } |
| 794 | |
[email protected] | 0f938689 | 2012-02-15 01:44:07 | [diff] [blame] | 795 | void GpuCommandBufferStub::AddDestructionObserver( |
| 796 | DestructionObserver* observer) { |
| 797 | destruction_observers_.AddObserver(observer); |
| 798 | } |
| 799 | |
| 800 | void GpuCommandBufferStub::RemoveDestructionObserver( |
| 801 | DestructionObserver* observer) { |
| 802 | destruction_observers_.RemoveObserver(observer); |
| 803 | } |
| 804 | |
[email protected] | 6802e3c6 | 2012-06-06 22:32:44 | [diff] [blame] | 805 | void GpuCommandBufferStub::SetPreemptByCounter( |
[email protected] | 68c7028 | 2012-06-25 23:31:17 | [diff] [blame] | 806 | scoped_refptr<gpu::RefCountedCounter> counter) { |
[email protected] | 6802e3c6 | 2012-06-06 22:32:44 | [diff] [blame] | 807 | preempt_by_counter_ = counter; |
| 808 | if (scheduler_.get()) |
| 809 | scheduler_->SetPreemptByCounter(preempt_by_counter_); |
| 810 | } |
| 811 | |
[email protected] | 4b8a6b09 | 2012-10-05 01:20:06 | [diff] [blame] | 812 | bool GpuCommandBufferStub::GetTotalGpuMemory(size_t* bytes) { |
| 813 | if (!MakeCurrent()) |
| 814 | return false; |
| 815 | return context_->GetTotalGpuMemory(bytes); |
| 816 | } |
| 817 | |
[email protected] | 1d56e964 | 2012-05-04 15:40:13 | [diff] [blame] | 818 | gfx::Size GpuCommandBufferStub::GetSurfaceSize() const { |
| 819 | if (!surface_) |
| 820 | return gfx::Size(); |
| 821 | return surface_->GetSize(); |
| 822 | } |
| 823 | |
[email protected] | c5370901 | 2012-02-21 03:22:22 | [diff] [blame] | 824 | bool GpuCommandBufferStub::IsInSameContextShareGroup( |
| 825 | const GpuCommandBufferStubBase& other) const { |
| 826 | return context_group_ == |
| 827 | static_cast<const GpuCommandBufferStub&>(other).context_group_; |
| 828 | } |
| 829 | |
[email protected] | c1f1214 | 2012-05-01 22:21:06 | [diff] [blame] | 830 | |
[email protected] | 5178c442 | 2012-10-17 12:08:07 | [diff] [blame^] | 831 | const GpuCommandBufferStubBase::MemoryManagerState& |
| 832 | GpuCommandBufferStub::memory_manager_state() const { |
| 833 | return *memory_manager_state_.get(); |
[email protected] | 672c731 | 2012-02-03 16:28:55 | [diff] [blame] | 834 | } |
[email protected] | 74b407d | 2012-02-11 01:13:55 | [diff] [blame] | 835 | void GpuCommandBufferStub::SetMemoryAllocation( |
| 836 | const GpuMemoryAllocation& allocation) { |
[email protected] | 3ac71bf | 2012-05-16 15:55:53 | [diff] [blame] | 837 | Send(new GpuCommandBufferMsg_SetMemoryAllocation(route_id_, allocation)); |
[email protected] | 062e5e8 | 2012-06-20 19:30:35 | [diff] [blame] | 838 | // This can be called outside of OnMessageReceived, so the context needs to be |
| 839 | // made current before calling methods on the surface. |
| 840 | if (!surface_ || !MakeCurrent()) |
[email protected] | 3ac71bf | 2012-05-16 15:55:53 | [diff] [blame] | 841 | return; |
| 842 | surface_->SetFrontbufferAllocation(allocation.suggest_have_frontbuffer); |
[email protected] | 74b407d | 2012-02-11 01:13:55 | [diff] [blame] | 843 | } |
| 844 | |
[email protected] | 8e5cc28 | 2010-12-05 18:11:39 | [diff] [blame] | 845 | #endif // defined(ENABLE_GPU) |