blob: a8855ab41a545795fae252807835bd44a212e6c7 (
plain)
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
|
// Copyright (c) 2013 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 "webkit/gpu/context_provider_in_process.h"
#include "webkit/gpu/grcontext_for_webgraphicscontext3d.h"
namespace webkit {
namespace gpu {
class ContextProviderInProcess::LostContextCallbackProxy
: public WebKit::WebGraphicsContext3D::WebGraphicsContextLostCallback {
public:
explicit LostContextCallbackProxy(ContextProviderInProcess* provider)
: provider_(provider) {
provider_->context3d_->setContextLostCallback(this);
}
virtual void onContextLost() {
provider_->OnLostContextInternal();
}
private:
ContextProviderInProcess* provider_;
};
class ContextProviderInProcess::MemoryAllocationCallbackProxy
: public WebKit::WebGraphicsContext3D::
WebGraphicsMemoryAllocationChangedCallbackCHROMIUM {
public:
explicit MemoryAllocationCallbackProxy(ContextProviderInProcess* provider)
: provider_(provider) {
provider_->context3d_->setMemoryAllocationChangedCallbackCHROMIUM(this);
}
virtual void onMemoryAllocationChanged(
WebKit::WebGraphicsMemoryAllocation alloc) {
provider_->OnMemoryAllocationChanged(!!alloc.gpuResourceSizeInBytes);
}
private:
ContextProviderInProcess* provider_;
};
ContextProviderInProcess::ContextProviderInProcess()
: destroyed_(false) {
}
ContextProviderInProcess::~ContextProviderInProcess() {}
bool ContextProviderInProcess::InitializeOnMainThread() {
DCHECK(!context3d_);
WebKit::WebGraphicsContext3D::Attributes attributes;
attributes.depth = false;
attributes.stencil = true;
attributes.antialias = false;
attributes.shareResources = true;
attributes.noAutomaticFlushes = true;
using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl;
context3d_.reset(
WebGraphicsContext3DInProcessCommandBufferImpl::CreateOffscreenContext(
attributes));
return context3d_;
}
bool ContextProviderInProcess::BindToCurrentThread() {
DCHECK(context3d_);
if (lost_context_callback_proxy_)
return true;
if (!context3d_->makeContextCurrent())
return false;
lost_context_callback_proxy_.reset(new LostContextCallbackProxy(this));
return true;
}
WebKit::WebGraphicsContext3D* ContextProviderInProcess::Context3d() {
DCHECK(context3d_);
DCHECK(lost_context_callback_proxy_); // Is bound to thread.
return context3d_.get();
}
class GrContext* ContextProviderInProcess::GrContext() {
DCHECK(context3d_);
DCHECK(lost_context_callback_proxy_); // Is bound to thread.
if (gr_context_)
return gr_context_->get();
gr_context_.reset(
new webkit::gpu::GrContextForWebGraphicsContext3D(context3d_.get()));
memory_allocation_callback_proxy_.reset(
new MemoryAllocationCallbackProxy(this));
return gr_context_->get();
}
void ContextProviderInProcess::VerifyContexts() {
DCHECK(context3d_);
DCHECK(lost_context_callback_proxy_); // Is bound to thread.
if (context3d_->isContextLost())
OnLostContextInternal();
}
void ContextProviderInProcess::OnLostContextInternal() {
{
base::AutoLock lock(destroyed_lock_);
if (destroyed_)
return;
destroyed_ = true;
}
OnLostContext();
}
bool ContextProviderInProcess::DestroyedOnMainThread() {
base::AutoLock lock(destroyed_lock_);
return destroyed_;
}
void ContextProviderInProcess::OnMemoryAllocationChanged(
bool nonzero_allocation) {
if (gr_context_)
gr_context_->SetMemoryLimit(nonzero_allocation);
}
} // namespace gpu
} // namespace webkit
|