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
|
// Copyright (c) 2010 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/plugins/ppapi/ppb_graphics_3d_impl.h"
#include "gpu/command_buffer/common/command_buffer.h"
#include "ppapi/c/dev/ppb_graphics_3d_dev.h"
#include "webkit/plugins/ppapi/common.h"
#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
namespace webkit {
namespace ppapi {
namespace {
// Size of the transfer buffer.
enum { kTransferBufferSize = 512 * 1024 };
PP_Bool IsGraphics3D(PP_Resource resource) {
return BoolToPPBool(!!Resource::GetAs<PPB_Graphics3D_Impl>(resource));
}
PP_Bool GetConfigs(int32_t* configs, int32_t config_size, int32_t* num_config) {
// TODO(neb): Implement me!
return PP_FALSE;
}
PP_Bool ChooseConfig(const int32_t* attrib_list, int32_t* configs,
int32_t config_size, int32_t* num_config) {
// TODO(neb): Implement me!
return PP_FALSE;
}
PP_Bool GetConfigAttrib(int32_t config, int32_t attribute, int32_t* value) {
// TODO(neb): Implement me!
return PP_FALSE;
}
const char* QueryString(int32_t name) {
switch (name) {
case EGL_CLIENT_APIS:
return "OpenGL_ES";
case EGL_EXTENSIONS:
return "";
case EGL_VENDOR:
return "Google";
case EGL_VERSION:
return "1.0 Google";
default:
return NULL;
}
}
PP_Resource CreateContext(PP_Instance instance_id, int32_t config,
int32_t share_context,
const int32_t* attrib_list) {
DCHECK_EQ(0, share_context);
PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
if (!instance) {
return 0;
}
scoped_refptr<PPB_Graphics3D_Impl> context(
new PPB_Graphics3D_Impl(instance->module()));
if (!context->Init(instance_id, config, attrib_list)) {
return 0;
}
return context->GetReference();
}
void* GetProcAddress(const char* name) {
// TODO(neb): Implement me!
return NULL;
}
PP_Bool SwapBuffers(PP_Resource graphics3d) {
scoped_refptr<PPB_Graphics3D_Impl> context(
Resource::GetAs<PPB_Graphics3D_Impl>(graphics3d));
return BoolToPPBool(context && context->SwapBuffers());
}
uint32_t GetError() {
// TODO(alokp): Fix this.
return 0;
}
const PPB_Graphics3D_Dev ppb_graphics3d = {
&IsGraphics3D,
&GetConfigs,
&ChooseConfig,
&GetConfigAttrib,
&QueryString,
&CreateContext,
&GetProcAddress,
&SwapBuffers,
&GetError
};
} // namespace
PPB_Graphics3D_Impl::PPB_Graphics3D_Impl(PluginModule* module)
: Resource(module),
bound_instance_(NULL) {
}
const PPB_Graphics3D_Dev* PPB_Graphics3D_Impl::GetInterface() {
return &ppb_graphics3d;
}
PPB_Graphics3D_Impl::~PPB_Graphics3D_Impl() {
Destroy();
}
PPB_Graphics3D_Impl* PPB_Graphics3D_Impl::AsPPB_Graphics3D_Impl() {
return this;
}
bool PPB_Graphics3D_Impl::Init(PP_Instance instance_id, int32_t config,
const int32_t* attrib_list) {
PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
if (!instance) {
return false;
}
// Create and initialize the objects required to issue GLES2 calls.
platform_context_.reset(instance->delegate()->CreateContext3D());
if (!platform_context_.get()) {
Destroy();
return false;
}
if (!platform_context_->Init()) {
Destroy();
return false;
}
gles2_implementation_ = platform_context_->GetGLES2Implementation();
DCHECK(gles2_implementation_);
return true;
}
bool PPB_Graphics3D_Impl::BindToInstance(PluginInstance* new_instance) {
if (bound_instance_ == new_instance)
return true; // Rebinding the same device, nothing to do.
if (bound_instance_ && new_instance)
return false; // Can't change a bound device.
if (new_instance) {
// Resize the backing texture to the size of the instance when it is bound.
platform_context_->ResizeBackingTexture(new_instance->position().size());
// This is a temporary hack. The SwapBuffers is issued to force the resize
// to take place before any subsequent rendering. This might lead to a
// partially rendered frame being displayed. It is also not thread safe
// since the SwapBuffers is written to the command buffer and that command
// buffer might be written to by another thread.
// TODO(apatrick): Figure out the semantics of binding and resizing.
platform_context_->SwapBuffers();
}
bound_instance_ = new_instance;
return true;
}
bool PPB_Graphics3D_Impl::SwapBuffers() {
if (!platform_context_.get())
return false;
return platform_context_->SwapBuffers();
}
unsigned PPB_Graphics3D_Impl::GetError() {
if (!platform_context_.get())
return 0;
return platform_context_->GetError();
}
void PPB_Graphics3D_Impl::ResizeBackingTexture(const gfx::Size& size) {
if (!platform_context_.get())
return;
platform_context_->ResizeBackingTexture(size);
}
void PPB_Graphics3D_Impl::SetSwapBuffersCallback(Callback0::Type* callback) {
if (!platform_context_.get())
return;
platform_context_->SetSwapBuffersCallback(callback);
}
unsigned PPB_Graphics3D_Impl::GetBackingTextureId() {
if (!platform_context_.get())
return 0;
return platform_context_->GetBackingTextureId();
}
void PPB_Graphics3D_Impl::Destroy() {
gles2_implementation_ = NULL;
platform_context_.reset();
}
} // namespace ppapi
} // namespace webkit
|