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
|
// Copyright (c) 2011 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 "ui/gfx/compositor/compositor_cc.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositor.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFloatPoint.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h"
#include "ui/gfx/compositor/layer.h"
#include "ui/gfx/gl/gl_context.h"
#include "ui/gfx/gl/gl_surface.h"
#include "ui/gfx/gl/gl_implementation.h"
#include "webkit/glue/webthread_impl.h"
#include "webkit/gpu/webgraphicscontext3d_in_process_impl.h"
namespace {
webkit_glue::WebThreadImpl* g_compositor_thread = NULL;
} // anonymous namespace
namespace ui {
SharedResourcesCC::SharedResourcesCC() : initialized_(false) {
}
SharedResourcesCC::~SharedResourcesCC() {
}
// static
SharedResourcesCC* SharedResourcesCC::GetInstance() {
// We use LeakySingletonTraits so that we don't race with
// the tear down of the gl_bindings.
SharedResourcesCC* instance = Singleton<SharedResourcesCC,
LeakySingletonTraits<SharedResourcesCC> >::get();
if (instance->Initialize()) {
return instance;
} else {
instance->Destroy();
return NULL;
}
}
bool SharedResourcesCC::Initialize() {
if (initialized_)
return true;
{
// The following line of code exists soley to disable IO restrictions
// on this thread long enough to perform the GL bindings.
// TODO(wjmaclean) Remove this when GL initialisation cleaned up.
base::ThreadRestrictions::ScopedAllowIO allow_io;
if (!gfx::GLSurface::InitializeOneOff() ||
gfx::GetGLImplementation() == gfx::kGLImplementationNone) {
LOG(ERROR) << "Could not load the GL bindings";
return false;
}
}
surface_ = gfx::GLSurface::CreateOffscreenGLSurface(false, gfx::Size(1, 1));
if (!surface_.get()) {
LOG(ERROR) << "Unable to create offscreen GL surface.";
return false;
}
context_ = gfx::GLContext::CreateGLContext(
NULL, surface_.get(), gfx::PreferIntegratedGpu);
if (!context_.get()) {
LOG(ERROR) << "Unable to create GL context.";
return false;
}
initialized_ = true;
return true;
}
void SharedResourcesCC::Destroy() {
context_ = NULL;
surface_ = NULL;
initialized_ = false;
}
bool SharedResourcesCC::MakeSharedContextCurrent() {
DCHECK(initialized_);
return context_->MakeCurrent(surface_.get());
}
void* SharedResourcesCC::GetDisplay() {
return surface_->GetDisplay();
}
gfx::GLShareGroup* SharedResourcesCC::GetShareGroup() {
DCHECK(initialized_);
return context_->share_group();
}
TextureCC::TextureCC()
: texture_id_(0),
flipped_(false) {
}
void TextureCC::SetCanvas(const SkCanvas& canvas,
const gfx::Point& origin,
const gfx::Size& overall_size) {
NOTREACHED();
}
void TextureCC::Draw(const ui::TextureDrawParams& params,
const gfx::Rect& clip_bounds_in_texture) {
NOTREACHED();
}
CompositorCC::CompositorCC(CompositorDelegate* delegate,
gfx::AcceleratedWidget widget,
const gfx::Size& size)
: Compositor(delegate, size),
widget_(widget),
root_web_layer_(WebKit::WebLayer::create(this)) {
WebKit::WebLayerTreeView::Settings settings;
settings.enableCompositorThread = !!g_compositor_thread;
host_ = WebKit::WebLayerTreeView::create(this, root_web_layer_, settings);
root_web_layer_.setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f));
OnWidgetSizeChanged();
}
CompositorCC::~CompositorCC() {
}
void CompositorCC::InitializeThread() {
g_compositor_thread = new webkit_glue::WebThreadImpl("Browser Compositor");
WebKit::WebCompositor::setThread(g_compositor_thread);
}
void CompositorCC::TerminateThread() {
DCHECK(g_compositor_thread);
delete g_compositor_thread;
g_compositor_thread = NULL;
}
Texture* CompositorCC::CreateTexture() {
NOTREACHED();
return NULL;
}
void CompositorCC::Blur(const gfx::Rect& bounds) {
NOTIMPLEMENTED();
}
void CompositorCC::ScheduleDraw() {
if (g_compositor_thread)
host_.composite();
else
Compositor::ScheduleDraw();
}
void CompositorCC::OnNotifyStart(bool clear) {
}
void CompositorCC::OnNotifyEnd() {
}
void CompositorCC::OnWidgetSizeChanged() {
host_.setViewportSize(size());
root_web_layer_.setBounds(size());
}
void CompositorCC::OnRootLayerChanged() {
root_web_layer_.removeAllChildren();
root_web_layer_.addChild(root_layer()->web_layer());
}
void CompositorCC::DrawTree() {
host_.composite();
}
void CompositorCC::ReadPixels(SkBitmap* bitmap) {
NOTIMPLEMENTED();
}
void CompositorCC::animateAndLayout(double frameBeginTime) {
}
void CompositorCC::applyScrollDelta(const WebKit::WebSize&) {
}
WebKit::WebGraphicsContext3D* CompositorCC::createContext3D() {
gfx::GLShareGroup* share_group =
SharedResourcesCC::GetInstance()->GetShareGroup();
WebKit::WebGraphicsContext3D* context =
new webkit::gpu::WebGraphicsContext3DInProcessImpl(widget_, share_group);
WebKit::WebGraphicsContext3D::Attributes attrs;
context->initialize(attrs, 0, true);
return context;
}
void CompositorCC::didRebindGraphicsContext(bool success) {
}
void CompositorCC::scheduleComposite() {
ScheduleDraw();
}
void CompositorCC::notifyNeedsComposite() {
ScheduleDraw();
}
Compositor* Compositor::Create(CompositorDelegate* owner,
gfx::AcceleratedWidget widget,
const gfx::Size& size) {
return new CompositorCC(owner, widget, size);
}
} // namespace ui
|