forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshared_renderer_state.cc
163 lines (134 loc) · 4.45 KB
/
shared_renderer_state.cc
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
// Copyright 2014 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 "android_webview/browser/shared_renderer_state.h"
#include "android_webview/browser/browser_view_renderer_client.h"
#include "base/bind.h"
#include "base/location.h"
namespace android_webview {
DrawGLInput::DrawGLInput() : width(0), height(0) {
}
DrawGLInput::~DrawGLInput() {
}
DrawGLResult::DrawGLResult() : clip_contains_visible_rect(false) {
}
SharedRendererState::SharedRendererState(
scoped_refptr<base::MessageLoopProxy> ui_loop,
BrowserViewRendererClient* client)
: ui_loop_(ui_loop),
client_on_ui_(client),
weak_factory_on_ui_thread_(this),
ui_thread_weak_ptr_(weak_factory_on_ui_thread_.GetWeakPtr()),
compositor_(NULL),
memory_policy_dirty_(false),
hardware_allowed_(false),
hardware_initialized_(false),
share_context_(NULL) {
DCHECK(ui_loop_->BelongsToCurrentThread());
DCHECK(client_on_ui_);
}
SharedRendererState::~SharedRendererState() {}
void SharedRendererState::ClientRequestDrawGL() {
if (ui_loop_->BelongsToCurrentThread()) {
ClientRequestDrawGLOnUIThread();
} else {
ui_loop_->PostTask(
FROM_HERE,
base::Bind(&SharedRendererState::ClientRequestDrawGLOnUIThread,
ui_thread_weak_ptr_));
}
}
void SharedRendererState::ClientRequestDrawGLOnUIThread() {
DCHECK(ui_loop_->BelongsToCurrentThread());
if (!client_on_ui_->RequestDrawGL(NULL, false)) {
LOG(ERROR) << "Failed to request GL process. Deadlock likely";
}
}
void SharedRendererState::SetCompositorOnUiThread(
content::SynchronousCompositor* compositor) {
base::AutoLock lock(lock_);
DCHECK(ui_loop_->BelongsToCurrentThread());
compositor_ = compositor;
}
content::SynchronousCompositor* SharedRendererState::GetCompositor() {
base::AutoLock lock(lock_);
DCHECK(compositor_);
return compositor_;
}
void SharedRendererState::SetMemoryPolicy(
const content::SynchronousCompositorMemoryPolicy new_policy) {
base::AutoLock lock(lock_);
if (memory_policy_ != new_policy) {
memory_policy_ = new_policy;
memory_policy_dirty_ = true;
}
}
content::SynchronousCompositorMemoryPolicy
SharedRendererState::GetMemoryPolicy() const {
base::AutoLock lock(lock_);
return memory_policy_;
}
void SharedRendererState::SetDrawGLInput(scoped_ptr<DrawGLInput> input) {
base::AutoLock lock(lock_);
DCHECK(!draw_gl_input_.get());
draw_gl_input_ = input.Pass();
}
scoped_ptr<DrawGLInput> SharedRendererState::PassDrawGLInput() {
base::AutoLock lock(lock_);
return draw_gl_input_.Pass();
}
void SharedRendererState::SetHardwareAllowed(bool allowed) {
base::AutoLock lock(lock_);
hardware_allowed_ = allowed;
}
bool SharedRendererState::IsHardwareAllowed() const {
base::AutoLock lock(lock_);
return hardware_allowed_;
}
void SharedRendererState::SetHardwareInitialized(bool initialized) {
base::AutoLock lock(lock_);
hardware_initialized_ = initialized;
}
bool SharedRendererState::IsHardwareInitialized() const {
base::AutoLock lock(lock_);
return hardware_initialized_;
}
void SharedRendererState::SetSharedContext(gpu::GLInProcessContext* context) {
base::AutoLock lock(lock_);
DCHECK(!share_context_ || !context);
share_context_ = context;
}
gpu::GLInProcessContext* SharedRendererState::GetSharedContext() const {
base::AutoLock lock(lock_);
DCHECK(share_context_);
return share_context_;
}
void SharedRendererState::SetMemoryPolicyDirty(bool is_dirty) {
base::AutoLock lock(lock_);
memory_policy_dirty_ = is_dirty;
}
bool SharedRendererState::IsMemoryPolicyDirty() const {
base::AutoLock lock(lock_);
return memory_policy_dirty_;
}
void SharedRendererState::ReturnResources(
const cc::TransferableResourceArray& input) {
base::AutoLock lock(lock_);
cc::TransferableResource::ReturnResources(input, &returned_resources_);
}
void SharedRendererState::InsertReturnedResources(
const cc::ReturnedResourceArray& resources) {
base::AutoLock lock(lock_);
returned_resources_.insert(
returned_resources_.end(), resources.begin(), resources.end());
}
void SharedRendererState::SwapReturnedResources(
cc::ReturnedResourceArray* resources) {
base::AutoLock lock(lock_);
resources->swap(returned_resources_);
}
bool SharedRendererState::ReturnedResourcesEmpty() const {
base::AutoLock lock(lock_);
return returned_resources_.empty();
}
} // namespace android_webview