1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "gpu/ipc/service/gpu_command_buffer_stub.h"
#include <utility>
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/hash.h"
#include "base/json/json_writer.h"
#include "base/macros.h"
#include "base/memory/memory_pressure_listener.h"
#include "base/memory/ptr_util.h"
#include "base/memory/shared_memory.h"
#include "base/metrics/histogram_macros.h"
#include "base/time/time.h"
#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "gpu/command_buffer/common/constants.h"
#include "gpu/command_buffer/common/gpu_memory_buffer_support.h"
#include "gpu/command_buffer/common/mailbox.h"
#include "gpu/command_buffer/common/sync_token.h"
#include "gpu/command_buffer/service/gl_context_virtual.h"
#include "gpu/command_buffer/service/gl_state_restorer_impl.h"
#include "gpu/command_buffer/service/image_manager.h"
#include "gpu/command_buffer/service/logger.h"
#include "gpu/command_buffer/service/mailbox_manager.h"
#include "gpu/command_buffer/service/memory_tracking.h"
#include "gpu/command_buffer/service/query_manager.h"
#include "gpu/command_buffer/service/service_utils.h"
#include "gpu/command_buffer/service/sync_point_manager.h"
#include "gpu/command_buffer/service/transfer_buffer_manager.h"
#include "gpu/ipc/common/gpu_messages.h"
#include "gpu/ipc/service/gpu_channel.h"
#include "gpu/ipc/service/gpu_channel_manager.h"
#include "gpu/ipc/service/gpu_channel_manager_delegate.h"
#include "gpu/ipc/service/gpu_memory_buffer_factory.h"
#include "gpu/ipc/service/gpu_memory_manager.h"
#include "gpu/ipc/service/gpu_memory_tracking.h"
#include "gpu/ipc/service/gpu_watchdog_thread.h"
#include "gpu/ipc/service/image_transport_surface.h"
#include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_context.h"
#include "ui/gl/gl_image.h"
#include "ui/gl/gl_implementation.h"
#include "ui/gl/gl_switches.h"
#include "ui/gl/init/gl_factory.h"
#if defined(OS_WIN)
#include "base/win/win_util.h"
#endif
#if defined(OS_ANDROID)
#include "gpu/ipc/service/stream_texture_android.h"
#endif
// Macro to reduce code duplication when logging memory in
// GpuCommandBufferMemoryTracker. This is needed as the UMA_HISTOGRAM_* macros
// require a unique call-site per histogram (you can't funnel multiple strings
// into the same call-site).
#define GPU_COMMAND_BUFFER_MEMORY_BLOCK(category) \
do { \
uint64_t mb_used = tracking_group_->GetSize() / (1024 * 1024); \
switch (context_type_) { \
case gles2::CONTEXT_TYPE_WEBGL1: \
case gles2::CONTEXT_TYPE_WEBGL2: \
UMA_HISTOGRAM_MEMORY_LARGE_MB("GPU.ContextMemory.WebGL." category, \
mb_used); \
break; \
case gles2::CONTEXT_TYPE_OPENGLES2: \
case gles2::CONTEXT_TYPE_OPENGLES3: \
UMA_HISTOGRAM_MEMORY_LARGE_MB("GPU.ContextMemory.GLES." category, \
mb_used); \
break; \
} \
} while (false)
namespace gpu {
struct WaitForCommandState {
WaitForCommandState(int32_t start, int32_t end, IPC::Message* reply)
: start(start), end(end), reply(reply) {}
int32_t start;
int32_t end;
std::unique_ptr<IPC::Message> reply;
};
namespace {
// The GpuCommandBufferMemoryTracker class provides a bridge between the
// ContextGroup's memory type managers and the GpuMemoryManager class.
class GpuCommandBufferMemoryTracker : public gles2::MemoryTracker {
public:
explicit GpuCommandBufferMemoryTracker(
GpuChannel* channel,
uint64_t share_group_tracing_guid,
gles2::ContextType context_type,
scoped_refptr<base::SingleThreadTaskRunner> task_runner)
: tracking_group_(
channel->gpu_channel_manager()
->gpu_memory_manager()
->CreateTrackingGroup(channel->GetClientPID(), this)),
client_tracing_id_(channel->client_tracing_id()),
client_id_(channel->client_id()),
share_group_tracing_guid_(share_group_tracing_guid),
context_type_(context_type),
memory_pressure_listener_(new base::MemoryPressureListener(
base::Bind(&GpuCommandBufferMemoryTracker::LogMemoryStatsPressure,
base::Unretained(this)))) {
// Set up |memory_stats_timer_| to call LogMemoryPeriodic periodically
// via the provided |task_runner|.
memory_stats_timer_.SetTaskRunner(std::move(task_runner));
memory_stats_timer_.Start(
FROM_HERE, base::TimeDelta::FromSeconds(30), this,
&GpuCommandBufferMemoryTracker::LogMemoryStatsPeriodic);
}
void TrackMemoryAllocatedChange(
size_t old_size, size_t new_size) override {
tracking_group_->TrackMemoryAllocatedChange(
old_size, new_size);
}
bool EnsureGPUMemoryAvailable(size_t size_needed) override {
return tracking_group_->EnsureGPUMemoryAvailable(size_needed);
}
uint64_t ClientTracingId() const override { return client_tracing_id_; }
int ClientId() const override { return client_id_; }
uint64_t ShareGroupTracingGUID() const override {
return share_group_tracing_guid_;
}
private:
~GpuCommandBufferMemoryTracker() override { LogMemoryStatsShutdown(); }
void LogMemoryStatsPeriodic() { GPU_COMMAND_BUFFER_MEMORY_BLOCK("Periodic"); }
void LogMemoryStatsShutdown() { GPU_COMMAND_BUFFER_MEMORY_BLOCK("Shutdown"); }
void LogMemoryStatsPressure(
base::MemoryPressureListener::MemoryPressureLevel pressure_level) {
// Only log on CRITICAL memory pressure.
if (pressure_level ==
base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) {
GPU_COMMAND_BUFFER_MEMORY_BLOCK("Pressure");
}
}
std::unique_ptr<GpuMemoryTrackingGroup> tracking_group_;
const uint64_t client_tracing_id_;
const int client_id_;
const uint64_t share_group_tracing_guid_;
// Variables used in memory stat histogram logging.
const gles2::ContextType context_type_;
base::RepeatingTimer memory_stats_timer_;
std::unique_ptr<base::MemoryPressureListener> memory_pressure_listener_;
DISALLOW_COPY_AND_ASSIGN(GpuCommandBufferMemoryTracker);
};
// FastSetActiveURL will shortcut the expensive call to SetActiveURL when the
// url_hash matches.
void FastSetActiveURL(const GURL& url, size_t url_hash, GpuChannel* channel) {
// Leave the previously set URL in the empty case -- empty URLs are given by
// BlinkPlatformImpl::createOffscreenGraphicsContext3DProvider. Hopefully the
// onscreen context URL was set previously and will show up even when a crash
// occurs during offscreen command processing.
if (url.is_empty())
return;
static size_t g_last_url_hash = 0;
if (url_hash != g_last_url_hash) {
g_last_url_hash = url_hash;
DCHECK(channel && channel->gpu_channel_manager() &&
channel->gpu_channel_manager()->delegate());
channel->gpu_channel_manager()->delegate()->SetActiveURL(url);
}
}
// The first time polling a fence, delay some extra time to allow other
// stubs to process some work, or else the timing of the fences could
// allow a pattern of alternating fast and slow frames to occur.
const int64_t kHandleMoreWorkPeriodMs = 2;
const int64_t kHandleMoreWorkPeriodBusyMs = 1;
// Prevents idle work from being starved.
const int64_t kMaxTimeSinceIdleMs = 10;
class DevToolsChannelData : public base::trace_event::ConvertableToTraceFormat {
public:
static std::unique_ptr<base::trace_event::ConvertableToTraceFormat>
CreateForChannel(GpuChannel* channel);
~DevToolsChannelData() override {}
void AppendAsTraceFormat(std::string* out) const override {
std::string tmp;
base::JSONWriter::Write(*value_, &tmp);
*out += tmp;
}
private:
explicit DevToolsChannelData(base::Value* value) : value_(value) {}
std::unique_ptr<base::Value> value_;
DISALLOW_COPY_AND_ASSIGN(DevToolsChannelData);
};
std::unique_ptr<base::trace_event::ConvertableToTraceFormat>
DevToolsChannelData::CreateForChannel(GpuChannel* channel) {
std::unique_ptr<base::DictionaryValue> res(new base::DictionaryValue);
res->SetInteger("renderer_pid", channel->GetClientPID());
res->SetDouble("used_bytes", channel->GetMemoryUsage());
return base::WrapUnique(new DevToolsChannelData(res.release()));
}
CommandBufferId GetCommandBufferID(int channel_id, int32_t route_id) {
return CommandBufferId::FromUnsafeValue(
(static_cast<uint64_t>(channel_id) << 32) | route_id);
}
} // namespace
std::unique_ptr<GpuCommandBufferStub> GpuCommandBufferStub::Create(
GpuChannel* channel,
GpuCommandBufferStub* share_command_buffer_stub,
const GPUCreateCommandBufferConfig& init_params,
int32_t route_id,
std::unique_ptr<base::SharedMemory> shared_state_shm) {
std::unique_ptr<GpuCommandBufferStub> stub(
new GpuCommandBufferStub(channel, init_params, route_id));
if (!stub->Initialize(share_command_buffer_stub, init_params,
std::move(shared_state_shm)))
return nullptr;
return stub;
}
GpuCommandBufferStub::GpuCommandBufferStub(
GpuChannel* channel,
const GPUCreateCommandBufferConfig& init_params,
int32_t route_id)
: channel_(channel),
initialized_(false),
surface_handle_(init_params.surface_handle),
use_virtualized_gl_context_(false),
command_buffer_id_(GetCommandBufferID(channel->client_id(), route_id)),
stream_id_(init_params.stream_id),
route_id_(route_id),
last_flush_count_(0),
waiting_for_sync_point_(false),
previous_processed_num_(0),
active_url_(init_params.active_url),
active_url_hash_(base::Hash(active_url_.possibly_invalid_spec())) {}
GpuCommandBufferStub::~GpuCommandBufferStub() {
Destroy();
}
GpuMemoryManager* GpuCommandBufferStub::GetMemoryManager() const {
return channel()->gpu_channel_manager()->gpu_memory_manager();
}
bool GpuCommandBufferStub::OnMessageReceived(const IPC::Message& message) {
TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"),
"GPUTask",
"data",
DevToolsChannelData::CreateForChannel(channel()));
FastSetActiveURL(active_url_, active_url_hash_, channel_);
bool have_context = false;
// Ensure the appropriate GL context is current before handling any IPC
// messages directed at the command buffer. This ensures that the message
// handler can assume that the context is current (not necessary for
// RetireSyncPoint or WaitSyncPoint).
if (decoder_.get() &&
message.type() != GpuCommandBufferMsg_SetGetBuffer::ID &&
message.type() != GpuCommandBufferMsg_WaitForTokenInRange::ID &&
message.type() != GpuCommandBufferMsg_WaitForGetOffsetInRange::ID &&
message.type() != GpuCommandBufferMsg_RegisterTransferBuffer::ID &&
message.type() != GpuCommandBufferMsg_DestroyTransferBuffer::ID) {
if (!MakeCurrent())
return false;
have_context = true;
}
// Always use IPC_MESSAGE_HANDLER_DELAY_REPLY for synchronous message handlers
// here. This is so the reply can be delayed if the scheduler is unscheduled.
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(GpuCommandBufferStub, message)
IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_SetGetBuffer,
OnSetGetBuffer);
IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_TakeFrontBuffer, OnTakeFrontBuffer);
IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_ReturnFrontBuffer,
OnReturnFrontBuffer);
IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_WaitForTokenInRange,
OnWaitForTokenInRange);
IPC_MESSAGE_HANDLER_DELAY_REPLY(GpuCommandBufferMsg_WaitForGetOffsetInRange,
OnWaitForGetOffsetInRange);
IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_AsyncFlush, OnAsyncFlush);
IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_RegisterTransferBuffer,
OnRegisterTransferBuffer);
IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_DestroyTransferBuffer,
OnDestroyTransferBuffer);
IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_WaitSyncToken,
OnWaitSyncToken)
IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SignalSyncToken,
OnSignalSyncToken)
IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SignalQuery,
OnSignalQuery)
IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_CreateImage, OnCreateImage);
IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_DestroyImage, OnDestroyImage);
IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_CreateStreamTexture,
OnCreateStreamTexture)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
CheckCompleteWaits();
// Ensure that any delayed work that was created will be handled.
if (have_context) {
if (executor_)
executor_->ProcessPendingQueries();
ScheduleDelayedWork(
base::TimeDelta::FromMilliseconds(kHandleMoreWorkPeriodMs));
}
return handled;
}
bool GpuCommandBufferStub::Send(IPC::Message* message) {
return channel_->Send(message);
}
#if defined(OS_WIN)
void GpuCommandBufferStub::DidCreateAcceleratedSurfaceChildWindow(
SurfaceHandle parent_window,
SurfaceHandle child_window) {
GpuChannelManager* gpu_channel_manager = channel_->gpu_channel_manager();
gpu_channel_manager->delegate()->SendAcceleratedSurfaceCreatedChildWindow(
parent_window, child_window);
}
#endif
void GpuCommandBufferStub::DidSwapBuffersComplete(
SwapBuffersCompleteParams params) {
GpuCommandBufferMsg_SwapBuffersCompleted_Params send_params;
#if defined(OS_MACOSX)
send_params.ca_context_id = params.ca_context_id;
send_params.fullscreen_low_power_ca_context_valid =
params.fullscreen_low_power_ca_context_valid;
send_params.fullscreen_low_power_ca_context_id =
params.fullscreen_low_power_ca_context_id;
send_params.io_surface = params.io_surface;
send_params.pixel_size = params.pixel_size;
send_params.scale_factor = params.scale_factor;
send_params.in_use_responses = params.in_use_responses;
#endif
send_params.latency_info = std::move(params.latency_info);
send_params.result = params.result;
Send(new GpuCommandBufferMsg_SwapBuffersCompleted(route_id_, send_params));
}
const gles2::FeatureInfo* GpuCommandBufferStub::GetFeatureInfo() const {
return context_group_->feature_info();
}
void GpuCommandBufferStub::SetLatencyInfoCallback(
const LatencyInfoCallback& callback) {
latency_info_callback_ = callback;
}
void GpuCommandBufferStub::UpdateVSyncParameters(base::TimeTicks timebase,
base::TimeDelta interval) {
Send(new GpuCommandBufferMsg_UpdateVSyncParameters(route_id_, timebase,
interval));
}
bool GpuCommandBufferStub::IsScheduled() {
return (!executor_.get() || executor_->scheduled());
}
void GpuCommandBufferStub::PollWork() {
// Post another delayed task if we have not yet reached the time at which
// we should process delayed work.
base::TimeTicks current_time = base::TimeTicks::Now();
DCHECK(!process_delayed_work_time_.is_null());
if (process_delayed_work_time_ > current_time) {
channel_->task_runner()->PostDelayedTask(
FROM_HERE, base::Bind(&GpuCommandBufferStub::PollWork, AsWeakPtr()),
process_delayed_work_time_ - current_time);
return;
}
process_delayed_work_time_ = base::TimeTicks();
PerformWork();
}
void GpuCommandBufferStub::PerformWork() {
TRACE_EVENT0("gpu", "GpuCommandBufferStub::PerformWork");
FastSetActiveURL(active_url_, active_url_hash_, channel_);
if (decoder_.get() && !MakeCurrent())
return;
if (executor_) {
uint32_t current_unprocessed_num =
channel()->gpu_channel_manager()->GetUnprocessedOrderNum();
// We're idle when no messages were processed or scheduled.
bool is_idle = (previous_processed_num_ == current_unprocessed_num);
if (!is_idle && !last_idle_time_.is_null()) {
base::TimeDelta time_since_idle =
base::TimeTicks::Now() - last_idle_time_;
base::TimeDelta max_time_since_idle =
base::TimeDelta::FromMilliseconds(kMaxTimeSinceIdleMs);
// Force idle when it's been too long since last time we were idle.
if (time_since_idle > max_time_since_idle)
is_idle = true;
}
if (is_idle) {
last_idle_time_ = base::TimeTicks::Now();
executor_->PerformIdleWork();
}
executor_->ProcessPendingQueries();
executor_->PerformPollingWork();
}
ScheduleDelayedWork(
base::TimeDelta::FromMilliseconds(kHandleMoreWorkPeriodBusyMs));
}
bool GpuCommandBufferStub::HasUnprocessedCommands() {
if (command_buffer_) {
CommandBuffer::State state = command_buffer_->GetLastState();
return command_buffer_->GetPutOffset() != state.get_offset &&
!error::IsError(state.error);
}
return false;
}
void GpuCommandBufferStub::ScheduleDelayedWork(base::TimeDelta delay) {
bool has_more_work = executor_.get() && (executor_->HasPendingQueries() ||
executor_->HasMoreIdleWork() ||
executor_->HasPollingWork());
if (!has_more_work) {
last_idle_time_ = base::TimeTicks();
return;
}
base::TimeTicks current_time = base::TimeTicks::Now();
// |process_delayed_work_time_| is set if processing of delayed work is
// already scheduled. Just update the time if already scheduled.
if (!process_delayed_work_time_.is_null()) {
process_delayed_work_time_ = current_time + delay;
return;
}
// Idle when no messages are processed between now and when
// PollWork is called.
previous_processed_num_ =
channel()->gpu_channel_manager()->GetProcessedOrderNum();
if (last_idle_time_.is_null())
last_idle_time_ = current_time;
// IsScheduled() returns true after passing all unschedule fences
// and this is when we can start performing idle work. Idle work
// is done synchronously so we can set delay to 0 and instead poll
// for more work at the rate idle work is performed. This also ensures
// that idle work is done as efficiently as possible without any
// unnecessary delays.
if (executor_.get() && executor_->scheduled() &&
executor_->HasMoreIdleWork()) {
delay = base::TimeDelta();
}
process_delayed_work_time_ = current_time + delay;
channel_->task_runner()->PostDelayedTask(
FROM_HERE, base::Bind(&GpuCommandBufferStub::PollWork, AsWeakPtr()),
delay);
}
bool GpuCommandBufferStub::MakeCurrent() {
if (decoder_->MakeCurrent())
return true;
DLOG(ERROR) << "Context lost because MakeCurrent failed.";
command_buffer_->SetContextLostReason(decoder_->GetContextLostReason());
command_buffer_->SetParseError(error::kLostContext);
CheckContextLost();
return false;
}
void GpuCommandBufferStub::Destroy() {
if (wait_for_token_) {
Send(wait_for_token_->reply.release());
wait_for_token_.reset();
}
if (wait_for_get_offset_) {
Send(wait_for_get_offset_->reply.release());
wait_for_get_offset_.reset();
}
if (initialized_) {
GpuChannelManager* gpu_channel_manager = channel_->gpu_channel_manager();
// If we are currently shutting down the GPU process to help with recovery
// (exit_on_context_lost workaround), then don't tell the browser about
// offscreen context destruction here since it's not client-invoked, and
// might bypass the 3D API blocking logic.
if ((surface_handle_ == gpu::kNullSurfaceHandle) && !active_url_.is_empty()
&& !gpu_channel_manager->is_exiting_for_lost_context()) {
gpu_channel_manager->delegate()->DidDestroyOffscreenContext(active_url_);
}
}
if (decoder_)
decoder_->set_engine(NULL);
// The scheduler has raw references to the decoder and the command buffer so
// destroy it before those.
executor_.reset();
sync_point_client_.reset();
bool have_context = false;
if (decoder_ && decoder_->GetGLContext()) {
// Try to make the context current regardless of whether it was lost, so we
// don't leak resources.
have_context = decoder_->GetGLContext()->MakeCurrent(surface_.get());
}
for (auto& observer : destruction_observers_)
observer.OnWillDestroyStub();
if (decoder_) {
decoder_->Destroy(have_context);
decoder_.reset();
}
command_buffer_.reset();
// Remove this after crbug.com/248395 is sorted out.
surface_ = NULL;
}
bool GpuCommandBufferStub::Initialize(
GpuCommandBufferStub* share_command_buffer_stub,
const GPUCreateCommandBufferConfig& init_params,
std::unique_ptr<base::SharedMemory> shared_state_shm) {
TRACE_EVENT0("gpu", "GpuCommandBufferStub::Initialize");
FastSetActiveURL(active_url_, active_url_hash_, channel_);
GpuChannelManager* manager = channel_->gpu_channel_manager();
DCHECK(manager);
if (share_command_buffer_stub) {
context_group_ = share_command_buffer_stub->context_group_;
DCHECK(context_group_->bind_generates_resource() ==
init_params.attribs.bind_generates_resource);
} else {
scoped_refptr<gles2::FeatureInfo> feature_info =
new gles2::FeatureInfo(manager->gpu_driver_bug_workarounds());
gpu::GpuMemoryBufferFactory* gmb_factory =
channel_->gpu_channel_manager()->gpu_memory_buffer_factory();
context_group_ = new gles2::ContextGroup(
manager->gpu_preferences(), channel_->mailbox_manager(),
new GpuCommandBufferMemoryTracker(
channel_, command_buffer_id_.GetUnsafeValue(),
init_params.attribs.context_type, channel_->task_runner()),
manager->shader_translator_cache(),
manager->framebuffer_completeness_cache(), feature_info,
init_params.attribs.bind_generates_resource,
gmb_factory ? gmb_factory->AsImageFactory() : nullptr,
channel_->watchdog() /* progress_reporter */);
}
#if defined(OS_MACOSX)
// Virtualize PreferIntegratedGpu contexts by default on OS X to prevent
// performance regressions when enabling FCM.
// http://crbug.com/180463
if (init_params.attribs.gpu_preference == gl::PreferIntegratedGpu)
use_virtualized_gl_context_ = true;
#endif
use_virtualized_gl_context_ |=
context_group_->feature_info()->workarounds().use_virtualized_gl_contexts;
// MailboxManagerSync synchronization correctness currently depends on having
// only a single context. See crbug.com/510243 for details.
use_virtualized_gl_context_ |= channel_->mailbox_manager()->UsesSync();
gl::GLSurfaceFormat surface_format = gl::GLSurfaceFormat();
bool offscreen = (surface_handle_ == kNullSurfaceHandle);
gl::GLSurface* default_surface = manager->GetDefaultOffscreenSurface();
if (!default_surface) {
DLOG(ERROR) << "Failed to create default offscreen surface.";
return false;
}
#if defined(OS_ANDROID)
if (init_params.attribs.red_size <= 5 &&
init_params.attribs.green_size <= 6 &&
init_params.attribs.blue_size <= 5 &&
init_params.attribs.alpha_size == 0)
surface_format.SetRGB565();
// TODO(klausw): explicitly copy rgba sizes?
// We can only use virtualized contexts for onscreen command buffers if their
// config is compatible with the offscreen ones - otherwise MakeCurrent fails.
if (!surface_format.IsCompatible(default_surface->GetFormat()) && !offscreen)
use_virtualized_gl_context_ = false;
#endif
command_buffer_.reset(new CommandBufferService(
context_group_->transfer_buffer_manager()));
decoder_.reset(gles2::GLES2Decoder::Create(context_group_.get()));
executor_.reset(new CommandExecutor(command_buffer_.get(), decoder_.get(),
decoder_.get()));
sync_point_client_ = channel_->sync_point_manager()->CreateSyncPointClient(
channel_->GetSyncPointOrderData(stream_id_),
CommandBufferNamespace::GPU_IO, command_buffer_id_);
executor_->SetPreemptByFlag(channel_->preempted_flag());
decoder_->set_engine(executor_.get());
if (offscreen) {
surface_ = default_surface;
} else {
surface_ = ImageTransportSurface::CreateNativeSurface(
AsWeakPtr(), surface_handle_, surface_format);
if (!surface_ || !surface_->Initialize(surface_format)) {
surface_ = nullptr;
DLOG(ERROR) << "Failed to create surface.";
return false;
}
}
scoped_refptr<gl::GLContext> context;
gl::GLShareGroup* gl_share_group = channel_->share_group();
if (use_virtualized_gl_context_ && gl_share_group) {
context = gl_share_group->GetSharedContext(surface_.get());
if (!context.get()) {
context = gl::init::CreateGLContext(
gl_share_group, surface_.get(),
GenerateGLContextAttribs(init_params.attribs,
context_group_->gpu_preferences()));
if (!context.get()) {
DLOG(ERROR) << "Failed to create shared context for virtualization.";
return false;
}
// Ensure that context creation did not lose track of the intended
// gl_share_group.
DCHECK(context->share_group() == gl_share_group);
gl_share_group->SetSharedContext(surface_.get(), context.get());
}
// This should be either:
// (1) a non-virtual GL context, or
// (2) a mock context.
DCHECK(context->GetHandle() ||
gl::GetGLImplementation() == gl::kGLImplementationMockGL);
context = new GLContextVirtual(
gl_share_group, context.get(), decoder_->AsWeakPtr());
if (!context->Initialize(
surface_.get(),
GenerateGLContextAttribs(init_params.attribs,
context_group_->gpu_preferences()))) {
// The real context created above for the default offscreen surface
// might not be compatible with this surface.
context = NULL;
DLOG(ERROR) << "Failed to initialize virtual GL context.";
return false;
}
}
if (!context.get()) {
context = gl::init::CreateGLContext(
gl_share_group, surface_.get(),
GenerateGLContextAttribs(init_params.attribs,
context_group_->gpu_preferences()));
}
if (!context.get()) {
DLOG(ERROR) << "Failed to create context.";
return false;
}
if (!context->MakeCurrent(surface_.get())) {
LOG(ERROR) << "Failed to make context current.";
return false;
}
if (!context->GetGLStateRestorer()) {
context->SetGLStateRestorer(
new GLStateRestorerImpl(decoder_->AsWeakPtr()));
}
if (!context_group_->has_program_cache() &&
!context_group_->feature_info()->workarounds().disable_program_cache) {
context_group_->set_program_cache(manager->program_cache());
}
// Initialize the decoder with either the view or pbuffer GLContext.
if (!decoder_->Initialize(surface_, context, offscreen,
gpu::gles2::DisallowedFeatures(),
init_params.attribs)) {
DLOG(ERROR) << "Failed to initialize decoder.";
return false;
}
if (manager->gpu_preferences().enable_gpu_service_logging) {
decoder_->set_log_commands(true);
}
decoder_->GetLogger()->SetMsgCallback(
base::Bind(&GpuCommandBufferStub::SendConsoleMessage,
base::Unretained(this)));
decoder_->SetShaderCacheCallback(
base::Bind(&GpuCommandBufferStub::SendCachedShader,
base::Unretained(this)));
decoder_->SetFenceSyncReleaseCallback(base::Bind(
&GpuCommandBufferStub::OnFenceSyncRelease, base::Unretained(this)));
decoder_->SetWaitFenceSyncCallback(base::Bind(
&GpuCommandBufferStub::OnWaitFenceSync, base::Unretained(this)));
decoder_->SetDescheduleUntilFinishedCallback(
base::Bind(&GpuCommandBufferStub::OnDescheduleUntilFinished,
base::Unretained(this)));
decoder_->SetRescheduleAfterFinishedCallback(
base::Bind(&GpuCommandBufferStub::OnRescheduleAfterFinished,
base::Unretained(this)));
command_buffer_->SetPutOffsetChangeCallback(
base::Bind(&GpuCommandBufferStub::PutChanged, base::Unretained(this)));
command_buffer_->SetGetBufferChangeCallback(base::Bind(
&CommandExecutor::SetGetBuffer, base::Unretained(executor_.get())));
command_buffer_->SetParseErrorCallback(
base::Bind(&GpuCommandBufferStub::OnParseError, base::Unretained(this)));
if (channel_->watchdog()) {
executor_->SetCommandProcessedCallback(base::Bind(
&GpuCommandBufferStub::OnCommandProcessed, base::Unretained(this)));
}
const size_t kSharedStateSize = sizeof(CommandBufferSharedState);
if (!shared_state_shm->Map(kSharedStateSize)) {
DLOG(ERROR) << "Failed to map shared state buffer.";
return false;
}
command_buffer_->SetSharedStateBuffer(MakeBackingFromSharedMemory(
std::move(shared_state_shm), kSharedStateSize));
if (offscreen && !active_url_.is_empty())
manager->delegate()->DidCreateOffscreenContext(active_url_);
initialized_ = true;
return true;
}
void GpuCommandBufferStub::OnCreateStreamTexture(uint32_t texture_id,
int32_t stream_id,
bool* succeeded) {
#if defined(OS_ANDROID)
*succeeded = StreamTexture::Create(this, texture_id, stream_id);
#else
*succeeded = false;
#endif
}
void GpuCommandBufferStub::OnSetGetBuffer(int32_t shm_id,
IPC::Message* reply_message) {
TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnSetGetBuffer");
if (command_buffer_)
command_buffer_->SetGetBuffer(shm_id);
Send(reply_message);
}
void GpuCommandBufferStub::OnTakeFrontBuffer(const Mailbox& mailbox) {
TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnTakeFrontBuffer");
if (!decoder_) {
LOG(ERROR) << "Can't take front buffer before initialization.";
return;
}
decoder_->TakeFrontBuffer(mailbox);
}
void GpuCommandBufferStub::OnReturnFrontBuffer(const Mailbox& mailbox,
bool is_lost) {
decoder_->ReturnFrontBuffer(mailbox, is_lost);
}
void GpuCommandBufferStub::OnParseError() {
TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnParseError");
DCHECK(command_buffer_.get());
CommandBuffer::State state = command_buffer_->GetLastState();
IPC::Message* msg = new GpuCommandBufferMsg_Destroyed(
route_id_, state.context_lost_reason, state.error);
msg->set_unblock(true);
Send(msg);
// Tell the browser about this context loss as well, so it can
// determine whether client APIs like WebGL need to be immediately
// blocked from automatically running.
GpuChannelManager* gpu_channel_manager = channel_->gpu_channel_manager();
gpu_channel_manager->delegate()->DidLoseContext(
(surface_handle_ == kNullSurfaceHandle), state.context_lost_reason,
active_url_);
CheckContextLost();
}
void GpuCommandBufferStub::OnWaitForTokenInRange(int32_t start,
int32_t end,
IPC::Message* reply_message) {
TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnWaitForTokenInRange");
DCHECK(command_buffer_.get());
CheckContextLost();
if (wait_for_token_)
LOG(ERROR) << "Got WaitForToken command while currently waiting for token.";
wait_for_token_ =
base::MakeUnique<WaitForCommandState>(start, end, reply_message);
CheckCompleteWaits();
}
void GpuCommandBufferStub::OnWaitForGetOffsetInRange(
int32_t start,
int32_t end,
IPC::Message* reply_message) {
TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnWaitForGetOffsetInRange");
DCHECK(command_buffer_.get());
CheckContextLost();
if (wait_for_get_offset_) {
LOG(ERROR)
<< "Got WaitForGetOffset command while currently waiting for offset.";
}
wait_for_get_offset_ =
base::MakeUnique<WaitForCommandState>(start, end, reply_message);
CheckCompleteWaits();
}
void GpuCommandBufferStub::CheckCompleteWaits() {
if (wait_for_token_ || wait_for_get_offset_) {
CommandBuffer::State state = command_buffer_->GetLastState();
if (wait_for_token_ &&
(CommandBuffer::InRange(
wait_for_token_->start, wait_for_token_->end, state.token) ||
state.error != error::kNoError)) {
ReportState();
GpuCommandBufferMsg_WaitForTokenInRange::WriteReplyParams(
wait_for_token_->reply.get(), state);
Send(wait_for_token_->reply.release());
wait_for_token_.reset();
}
if (wait_for_get_offset_ &&
(CommandBuffer::InRange(wait_for_get_offset_->start,
wait_for_get_offset_->end,
state.get_offset) ||
state.error != error::kNoError)) {
ReportState();
GpuCommandBufferMsg_WaitForGetOffsetInRange::WriteReplyParams(
wait_for_get_offset_->reply.get(), state);
Send(wait_for_get_offset_->reply.release());
wait_for_get_offset_.reset();
}
}
}
void GpuCommandBufferStub::OnAsyncFlush(
int32_t put_offset,
uint32_t flush_count,
const std::vector<ui::LatencyInfo>& latency_info) {
TRACE_EVENT1(
"gpu", "GpuCommandBufferStub::OnAsyncFlush", "put_offset", put_offset);
DCHECK(command_buffer_);
// We received this message out-of-order. This should not happen but is here
// to catch regressions. Ignore the message.
DVLOG_IF(0, flush_count - last_flush_count_ >= 0x8000000U)
<< "Received a Flush message out-of-order";
if (flush_count > last_flush_count_ &&
ui::LatencyInfo::Verify(latency_info,
"GpuCommandBufferStub::OnAsyncFlush") &&
!latency_info_callback_.is_null()) {
latency_info_callback_.Run(latency_info);
}
last_flush_count_ = flush_count;
CommandBuffer::State pre_state = command_buffer_->GetLastState();
command_buffer_->Flush(put_offset);
CommandBuffer::State post_state = command_buffer_->GetLastState();
if (pre_state.get_offset != post_state.get_offset)
ReportState();
#if defined(OS_ANDROID)
GpuChannelManager* manager = channel_->gpu_channel_manager();
manager->DidAccessGpu();
#endif
}
void GpuCommandBufferStub::OnRegisterTransferBuffer(
int32_t id,
base::SharedMemoryHandle transfer_buffer,
uint32_t size) {
TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnRegisterTransferBuffer");
// Take ownership of the memory and map it into this process.
// This validates the size.
std::unique_ptr<base::SharedMemory> shared_memory(
new base::SharedMemory(transfer_buffer, false));
if (!shared_memory->Map(size)) {
DVLOG(0) << "Failed to map shared memory.";
return;
}
if (command_buffer_) {
command_buffer_->RegisterTransferBuffer(
id, MakeBackingFromSharedMemory(std::move(shared_memory), size));
}
}
void GpuCommandBufferStub::OnDestroyTransferBuffer(int32_t id) {
TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnDestroyTransferBuffer");
if (command_buffer_)
command_buffer_->DestroyTransferBuffer(id);
}
void GpuCommandBufferStub::OnCommandProcessed() {
DCHECK(channel_->watchdog());
channel_->watchdog()->CheckArmed();
}
void GpuCommandBufferStub::ReportState() { command_buffer_->UpdateState(); }
void GpuCommandBufferStub::PutChanged() {
FastSetActiveURL(active_url_, active_url_hash_, channel_);
executor_->PutChanged();
}
void GpuCommandBufferStub::PullTextureUpdates(
CommandBufferNamespace namespace_id,
CommandBufferId command_buffer_id,
uint32_t release) {
gles2::MailboxManager* mailbox_manager =
context_group_->mailbox_manager();
if (mailbox_manager->UsesSync() && MakeCurrent()) {
SyncToken sync_token(namespace_id, 0, command_buffer_id, release);
mailbox_manager->PullTextureUpdates(sync_token);
}
}
void GpuCommandBufferStub::OnWaitSyncToken(const SyncToken& sync_token) {
OnWaitFenceSync(sync_token.namespace_id(), sync_token.command_buffer_id(),
sync_token.release_count());
}
void GpuCommandBufferStub::OnSignalSyncToken(const SyncToken& sync_token,
uint32_t id) {
scoped_refptr<SyncPointClientState> release_state =
channel_->sync_point_manager()->GetSyncPointClientState(
sync_token.namespace_id(), sync_token.command_buffer_id());
if (release_state) {
sync_point_client_->Wait(release_state.get(), sync_token.release_count(),
base::Bind(&GpuCommandBufferStub::OnSignalAck,
this->AsWeakPtr(), id));
} else {
OnSignalAck(id);
}
}
void GpuCommandBufferStub::OnSignalAck(uint32_t id) {
Send(new GpuCommandBufferMsg_SignalAck(route_id_, id));
}
void GpuCommandBufferStub::OnSignalQuery(uint32_t query_id, uint32_t id) {
if (decoder_) {
gles2::QueryManager* query_manager = decoder_->GetQueryManager();
if (query_manager) {
gles2::QueryManager::Query* query =
query_manager->GetQuery(query_id);
if (query) {
query->AddCallback(
base::Bind(&GpuCommandBufferStub::OnSignalAck,
this->AsWeakPtr(),
id));
return;
}
}
}
// Something went wrong, run callback immediately.
OnSignalAck(id);
}
void GpuCommandBufferStub::OnFenceSyncRelease(uint64_t release) {
if (sync_point_client_->client_state()->IsFenceSyncReleased(release)) {
DLOG(ERROR) << "Fence Sync has already been released.";
return;
}
gles2::MailboxManager* mailbox_manager =
context_group_->mailbox_manager();
if (mailbox_manager->UsesSync() && MakeCurrent()) {
SyncToken sync_token(CommandBufferNamespace::GPU_IO, 0,
command_buffer_id_, release);
mailbox_manager->PushTextureUpdates(sync_token);
}
command_buffer_->SetReleaseCount(release);
sync_point_client_->ReleaseFenceSync(release);
}
void GpuCommandBufferStub::OnDescheduleUntilFinished() {
DCHECK(executor_->scheduled());
DCHECK(executor_->HasPollingWork());
executor_->SetScheduled(false);
channel_->OnStreamRescheduled(stream_id_, false);
}
void GpuCommandBufferStub::OnRescheduleAfterFinished() {
DCHECK(!executor_->scheduled());
executor_->SetScheduled(true);
channel_->OnStreamRescheduled(stream_id_, true);
}
bool GpuCommandBufferStub::OnWaitFenceSync(
CommandBufferNamespace namespace_id,
CommandBufferId command_buffer_id,
uint64_t release) {
DCHECK(!waiting_for_sync_point_);
DCHECK(executor_->scheduled());
scoped_refptr<SyncPointClientState> release_state =
channel_->sync_point_manager()->GetSyncPointClientState(
namespace_id, command_buffer_id);
if (!release_state)
return true;
if (release_state->IsFenceSyncReleased(release)) {
PullTextureUpdates(namespace_id, command_buffer_id, release);
return true;
}
TRACE_EVENT_ASYNC_BEGIN1("gpu", "WaitFenceSync", this, "GpuCommandBufferStub",
this);
waiting_for_sync_point_ = true;
sync_point_client_->WaitNonThreadSafe(
release_state.get(), release, channel_->task_runner(),
base::Bind(&GpuCommandBufferStub::OnWaitFenceSyncCompleted,
this->AsWeakPtr(), namespace_id, command_buffer_id, release));
if (!waiting_for_sync_point_)
return true;
executor_->SetScheduled(false);
channel_->OnStreamRescheduled(stream_id_, false);
return false;
}
void GpuCommandBufferStub::OnWaitFenceSyncCompleted(
CommandBufferNamespace namespace_id,
CommandBufferId command_buffer_id,
uint64_t release) {
DCHECK(waiting_for_sync_point_);
TRACE_EVENT_ASYNC_END1("gpu", "WaitFenceSync", this, "GpuCommandBufferStub",
this);
PullTextureUpdates(namespace_id, command_buffer_id, release);
waiting_for_sync_point_ = false;
executor_->SetScheduled(true);
channel_->OnStreamRescheduled(stream_id_, true);
}
void GpuCommandBufferStub::OnCreateImage(
const GpuCommandBufferMsg_CreateImage_Params& params) {
TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnCreateImage");
const int32_t id = params.id;
const gfx::GpuMemoryBufferHandle& handle = params.gpu_memory_buffer;
const gfx::Size& size = params.size;
const gfx::BufferFormat& format = params.format;
const uint32_t internalformat = params.internal_format;
const uint64_t image_release_count = params.image_release_count;
if (!decoder_)
return;
gles2::ImageManager* image_manager = decoder_->GetImageManager();
DCHECK(image_manager);
if (image_manager->LookupImage(id)) {
LOG(ERROR) << "Image already exists with same ID.";
return;
}
if (!gpu::IsGpuMemoryBufferFormatSupported(format,
decoder_->GetCapabilities())) {
LOG(ERROR) << "Format is not supported.";
return;
}
if (!gpu::IsImageSizeValidForGpuMemoryBufferFormat(size, format)) {
LOG(ERROR) << "Invalid image size for format.";
return;
}
if (!gpu::IsImageFormatCompatibleWithGpuMemoryBufferFormat(internalformat,
format)) {
LOG(ERROR) << "Incompatible image format.";
return;
}
scoped_refptr<gl::GLImage> image = channel()->CreateImageForGpuMemoryBuffer(
handle, size, format, internalformat, surface_handle_);
if (!image.get())
return;
image_manager->AddImage(image.get(), id);
if (image_release_count) {
DLOG_IF(ERROR,
image_release_count !=
sync_point_client_->client_state()->fence_sync_release() + 1)
<< "Client released fences out of order.";
sync_point_client_->ReleaseFenceSync(image_release_count);
}
}
void GpuCommandBufferStub::OnDestroyImage(int32_t id) {
TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnDestroyImage");
if (!decoder_)
return;
gles2::ImageManager* image_manager = decoder_->GetImageManager();
DCHECK(image_manager);
if (!image_manager->LookupImage(id)) {
LOG(ERROR) << "Image with ID doesn't exist.";
return;
}
image_manager->RemoveImage(id);
}
void GpuCommandBufferStub::SendConsoleMessage(int32_t id,
const std::string& message) {
GPUCommandBufferConsoleMessage console_message;
console_message.id = id;
console_message.message = message;
IPC::Message* msg = new GpuCommandBufferMsg_ConsoleMsg(
route_id_, console_message);
msg->set_unblock(true);
Send(msg);
}
void GpuCommandBufferStub::SendCachedShader(
const std::string& key, const std::string& shader) {
channel_->CacheShader(key, shader);
}
void GpuCommandBufferStub::AddDestructionObserver(
DestructionObserver* observer) {
destruction_observers_.AddObserver(observer);
}
void GpuCommandBufferStub::RemoveDestructionObserver(
DestructionObserver* observer) {
destruction_observers_.RemoveObserver(observer);
}
gles2::MemoryTracker* GpuCommandBufferStub::GetMemoryTracker() const {
return context_group_->memory_tracker();
}
bool GpuCommandBufferStub::CheckContextLost() {
DCHECK(command_buffer_);
CommandBuffer::State state = command_buffer_->GetLastState();
bool was_lost = state.error == error::kLostContext;
if (was_lost) {
bool was_lost_by_robustness =
decoder_ && decoder_->WasContextLostByRobustnessExtension();
// Work around issues with recovery by allowing a new GPU process to launch.
if ((was_lost_by_robustness ||
context_group_->feature_info()->workarounds().exit_on_context_lost)) {
channel_->gpu_channel_manager()->MaybeExitOnContextLost();
}
// Lose all other contexts if the reset was triggered by the robustness
// extension instead of being synthetic.
if (was_lost_by_robustness &&
(gl::GLContext::LosesAllContextsOnContextLost() ||
use_virtualized_gl_context_)) {
channel_->LoseAllContexts();
}
}
CheckCompleteWaits();
return was_lost;
}
void GpuCommandBufferStub::MarkContextLost() {
if (!command_buffer_ ||
command_buffer_->GetLastState().error == error::kLostContext)
return;
command_buffer_->SetContextLostReason(error::kUnknown);
if (decoder_)
decoder_->MarkContextLost(error::kUnknown);
command_buffer_->SetParseError(error::kLostContext);
}
} // namespace gpu
|