Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Side by Side Diff: cc/test/fake_web_graphics_context_3d.cc

Issue 12211110: Implement WebKit::WebUnitTestSupport::createLayerTreeViewForTesting() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add enum, fix NON_EXPORTED_BASE Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "cc/test/fake_web_graphics_context_3d.h"
6
7 #include <algorithm>
8 #include <string>
9
10 #include "base/logging.h"
11 #include "gpu/GLES2/gl2extchromium.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "third_party/khronos/GLES2/gl2ext.h"
14
15 using WebKit::WGC3Dboolean;
16 using WebKit::WGC3Denum;
17 using WebKit::WebGLId;
18 using WebKit::WebGraphicsContext3D;
19
20 namespace cc {
21
22 static const WebGLId kBufferId = 1;
23 static const WebGLId kFramebufferId = 2;
24 static const WebGLId kProgramId = 3;
25 static const WebGLId kRenderbufferId = 4;
26 static const WebGLId kShaderId = 5;
27
28 static unsigned s_context_id = 1;
29
30 const WebGLId FakeWebGraphicsContext3D::kExternalTextureId = 1337;
31
32 FakeWebGraphicsContext3D::FakeWebGraphicsContext3D()
33 : context_id_(s_context_id++),
34 next_texture_id_(1),
35 have_extension_io_surface_(false),
36 have_extension_egl_image_(false),
37 times_make_current_succeeds_(-1),
38 times_bind_texture_succeeds_(-1),
39 times_end_query_succeeds_(-1),
40 context_lost_(false),
41 context_lost_callback_(NULL),
42 width_(0),
43 height_(0) {
44 }
45
46 FakeWebGraphicsContext3D::FakeWebGraphicsContext3D(
47 const WebGraphicsContext3D::Attributes& attributes)
48 : context_id_(s_context_id++),
49 next_texture_id_(1),
50 attributes_(attributes),
51 have_extension_io_surface_(false),
52 have_extension_egl_image_(false),
53 times_make_current_succeeds_(-1),
54 times_bind_texture_succeeds_(-1),
55 times_end_query_succeeds_(-1),
56 context_lost_(false),
57 context_lost_callback_(NULL),
58 width_(0),
59 height_(0) {
60 }
61
62 FakeWebGraphicsContext3D::~FakeWebGraphicsContext3D() {
63 }
64
65 bool FakeWebGraphicsContext3D::makeContextCurrent() {
66 if (times_make_current_succeeds_ >= 0) {
67 if (!times_make_current_succeeds_) {
68 loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB,
69 GL_INNOCENT_CONTEXT_RESET_ARB);
70 }
71 --times_make_current_succeeds_;
72 }
73 return !context_lost_;
74 }
75
76 int FakeWebGraphicsContext3D::width() {
77 return width_;
78 }
79
80 int FakeWebGraphicsContext3D::height() {
81 return height_;
82 }
83
84 void FakeWebGraphicsContext3D::reshape(int width, int height) {
85 width_ = width;
86 height_ = height;
87 }
88
89 bool FakeWebGraphicsContext3D::isGLES2Compliant() {
90 return false;
91 }
92
93 bool FakeWebGraphicsContext3D::readBackFramebuffer(
94 unsigned char* pixels,
95 size_t bufferSize,
96 WebGLId framebuffer,
97 int width,
98 int height) {
99 return false;
100 }
101
102 WebGLId FakeWebGraphicsContext3D::getPlatformTextureId() {
103 return 0;
104 }
105
106 bool FakeWebGraphicsContext3D::isContextLost() {
107 return context_lost_;
108 }
109
110 WGC3Denum FakeWebGraphicsContext3D::getGraphicsResetStatusARB() {
111 return context_lost_ ? GL_UNKNOWN_CONTEXT_RESET_ARB : GL_NO_ERROR;
112 }
113
114 void* FakeWebGraphicsContext3D::mapBufferSubDataCHROMIUM(
115 WGC3Denum target,
116 WebKit::WGC3Dintptr offset,
117 WebKit::WGC3Dsizeiptr size,
118 WGC3Denum access) {
119 return 0;
120 }
121
122 void* FakeWebGraphicsContext3D::mapTexSubImage2DCHROMIUM(
123 WGC3Denum target,
124 WebKit::WGC3Dint level,
125 WebKit::WGC3Dint xoffset,
126 WebKit::WGC3Dint yoffset,
127 WebKit::WGC3Dsizei width,
128 WebKit::WGC3Dsizei height,
129 WGC3Denum format,
130 WGC3Denum type,
131 WGC3Denum access) {
132 return 0;
133 }
134
135 WebKit::WebString FakeWebGraphicsContext3D::getRequestableExtensionsCHROMIUM() {
136 return WebKit::WebString();
137 }
138
139 WGC3Denum FakeWebGraphicsContext3D::checkFramebufferStatus(
140 WGC3Denum target) {
141 if (context_lost_)
142 return GL_FRAMEBUFFER_UNDEFINED_OES;
143 return GL_FRAMEBUFFER_COMPLETE;
144 }
145
146 bool FakeWebGraphicsContext3D::getActiveAttrib(
147 WebGLId program,
148 WebKit::WGC3Duint index,
149 ActiveInfo&) {
150 return false;
151 }
152
153 bool FakeWebGraphicsContext3D::getActiveUniform(
154 WebGLId program,
155 WebKit::WGC3Duint index,
156 ActiveInfo&) {
157 return false;
158 }
159
160 WebKit::WGC3Dint FakeWebGraphicsContext3D::getAttribLocation(
161 WebGLId program,
162 const WebKit::WGC3Dchar* name) {
163 return 0;
164 }
165
166 WebGraphicsContext3D::Attributes
167 FakeWebGraphicsContext3D::getContextAttributes() {
168 return attributes_;
169 }
170
171 WGC3Denum FakeWebGraphicsContext3D::getError() {
172 return 0;
173 }
174
175 void FakeWebGraphicsContext3D::getIntegerv(
176 WGC3Denum pname,
177 WebKit::WGC3Dint* value) {
178 if (pname == GL_MAX_TEXTURE_SIZE)
179 *value = 1024;
180 }
181
182 void FakeWebGraphicsContext3D::getProgramiv(
183 WebGLId program,
184 WGC3Denum pname,
185 WebKit::WGC3Dint* value) {
186 if (pname == GL_LINK_STATUS)
187 *value = 1;
188 }
189
190 WebKit::WebString FakeWebGraphicsContext3D::getProgramInfoLog(
191 WebGLId program) {
192 return WebKit::WebString();
193 }
194
195 void FakeWebGraphicsContext3D::getShaderiv(
196 WebGLId shader,
197 WGC3Denum pname,
198 WebKit::WGC3Dint* value) {
199 if (pname == GL_COMPILE_STATUS)
200 *value = 1;
201 }
202
203 WebKit::WebString FakeWebGraphicsContext3D::getShaderInfoLog(
204 WebGLId shader) {
205 return WebKit::WebString();
206 }
207
208 WebKit::WebString FakeWebGraphicsContext3D::getShaderSource(
209 WebGLId shader) {
210 return WebKit::WebString();
211 }
212
213 WebKit::WebString FakeWebGraphicsContext3D::getString(WGC3Denum name) {
214 std::string string;
215
216 if (name == GL_EXTENSIONS) {
217 if (have_extension_io_surface_)
218 string += "GL_CHROMIUM_iosurface GL_ARB_texture_rectangle ";
219 if (have_extension_egl_image_)
220 string += "GL_OES_EGL_image_external";
221 }
222
223 return WebKit::WebString::fromUTF8(string.c_str());
224 }
225
226 WebKit::WGC3Dint FakeWebGraphicsContext3D::getUniformLocation(
227 WebGLId program,
228 const WebKit::WGC3Dchar* name) {
229 return 0;
230 }
231
232 WebKit::WGC3Dsizeiptr FakeWebGraphicsContext3D::getVertexAttribOffset(
233 WebKit::WGC3Duint index,
234 WGC3Denum pname) {
235 return 0;
236 }
237
238 WGC3Dboolean FakeWebGraphicsContext3D::isBuffer(
239 WebGLId buffer) {
240 return false;
241 }
242
243 WGC3Dboolean FakeWebGraphicsContext3D::isEnabled(
244 WGC3Denum cap) {
245 return false;
246 }
247
248 WGC3Dboolean FakeWebGraphicsContext3D::isFramebuffer(
249 WebGLId framebuffer) {
250 return false;
251 }
252
253 WGC3Dboolean FakeWebGraphicsContext3D::isProgram(
254 WebGLId program) {
255 return false;
256 }
257
258 WGC3Dboolean FakeWebGraphicsContext3D::isRenderbuffer(
259 WebGLId renderbuffer) {
260 return false;
261 }
262
263 WGC3Dboolean FakeWebGraphicsContext3D::isShader(
264 WebGLId shader) {
265 return false;
266 }
267
268 WGC3Dboolean FakeWebGraphicsContext3D::isTexture(
269 WebGLId texture) {
270 return false;
271 }
272
273 WebGLId FakeWebGraphicsContext3D::createBuffer() {
274 return kBufferId | context_id_ << 16;
275 }
276
277 void FakeWebGraphicsContext3D::deleteBuffer(WebKit::WebGLId id) {
278 EXPECT_EQ(kBufferId | context_id_ << 16, id);
279 }
280
281 WebGLId FakeWebGraphicsContext3D::createFramebuffer() {
282 return kFramebufferId | context_id_ << 16;
283 }
284
285 void FakeWebGraphicsContext3D::deleteFramebuffer(WebKit::WebGLId id) {
286 EXPECT_EQ(kFramebufferId | context_id_ << 16, id);
287 }
288
289 WebGLId FakeWebGraphicsContext3D::createProgram() {
290 return kProgramId | context_id_ << 16;
291 }
292
293 void FakeWebGraphicsContext3D::deleteProgram(WebKit::WebGLId id) {
294 EXPECT_EQ(kProgramId | context_id_ << 16, id);
295 }
296
297 WebGLId FakeWebGraphicsContext3D::createRenderbuffer() {
298 return kRenderbufferId | context_id_ << 16;
299 }
300
301 void FakeWebGraphicsContext3D::deleteRenderbuffer(WebKit::WebGLId id) {
302 EXPECT_EQ(kRenderbufferId | context_id_ << 16, id);
303 }
304
305 WebGLId FakeWebGraphicsContext3D::createShader(WGC3Denum) {
306 return kShaderId | context_id_ << 16;
307 }
308
309 void FakeWebGraphicsContext3D::deleteShader(WebKit::WebGLId id) {
310 EXPECT_EQ(kShaderId | context_id_ << 16, id);
311 }
312
313 WebGLId FakeWebGraphicsContext3D::createTexture() {
314 WebGLId texture_id = NextTextureId();
315 DCHECK_NE(texture_id, kExternalTextureId);
316 textures_.push_back(texture_id);
317 return texture_id;
318 }
319
320 void FakeWebGraphicsContext3D::deleteTexture(WebGLId texture_id) {
321 DCHECK(std::find(textures_.begin(), textures_.end(), texture_id) !=
322 textures_.end());
323 textures_.erase(std::find(textures_.begin(), textures_.end(), texture_id));
324 }
325
326 void FakeWebGraphicsContext3D::attachShader(WebGLId program, WebGLId shader) {
327 EXPECT_EQ(kProgramId | context_id_ << 16, program);
328 EXPECT_EQ(kShaderId | context_id_ << 16, shader);
329 }
330
331 void FakeWebGraphicsContext3D::useProgram(WebGLId program) {
332 if (!program)
333 return;
334 EXPECT_EQ(kProgramId | context_id_ << 16, program);
335 }
336
337 void FakeWebGraphicsContext3D::bindBuffer(WGC3Denum target, WebGLId buffer) {
338 if (!buffer)
339 return;
340 EXPECT_EQ(kBufferId | context_id_ << 16, buffer);
341 }
342
343 void FakeWebGraphicsContext3D::bindFramebuffer(
344 WGC3Denum target, WebGLId framebuffer) {
345 if (!framebuffer)
346 return;
347 EXPECT_EQ(kFramebufferId | context_id_ << 16, framebuffer);
348 }
349
350 void FakeWebGraphicsContext3D::bindRenderbuffer(
351 WGC3Denum target, WebGLId renderbuffer) {
352 if (!renderbuffer)
353 return;
354 EXPECT_EQ(kRenderbufferId | context_id_ << 16, renderbuffer);
355 }
356
357 void FakeWebGraphicsContext3D::bindTexture(
358 WGC3Denum target, WebGLId texture_id) {
359 if (times_bind_texture_succeeds_ >= 0) {
360 if (!times_bind_texture_succeeds_) {
361 loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB,
362 GL_INNOCENT_CONTEXT_RESET_ARB);
363 }
364 --times_bind_texture_succeeds_;
365 }
366
367 if (!texture_id)
368 return;
369 if (texture_id == kExternalTextureId)
370 return;
371 DCHECK(std::find(textures_.begin(), textures_.end(), texture_id) !=
372 textures_.end());
373 used_textures_.insert(texture_id);
374 }
375
376 WebGLId FakeWebGraphicsContext3D::createQueryEXT() {
377 return 1;
378 }
379
380 WGC3Dboolean FakeWebGraphicsContext3D::isQueryEXT(WebGLId query) {
381 return true;
382 }
383
384 void FakeWebGraphicsContext3D::endQueryEXT(WebKit::WGC3Denum target) {
385 if (times_end_query_succeeds_ >= 0) {
386 if (!times_end_query_succeeds_) {
387 loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB,
388 GL_INNOCENT_CONTEXT_RESET_ARB);
389 }
390 --times_end_query_succeeds_;
391 }
392 }
393
394 void FakeWebGraphicsContext3D::getQueryObjectuivEXT(
395 WebKit::WebGLId query,
396 WebKit::WGC3Denum pname,
397 WebKit::WGC3Duint* params) {
398 // If the context is lost, behave as if result is available.
399 if (pname == GL_QUERY_RESULT_AVAILABLE_EXT)
400 *params = 1;
401 }
402
403 void FakeWebGraphicsContext3D::setContextLostCallback(
404 WebGraphicsContextLostCallback* callback) {
405 context_lost_callback_ = callback;
406 }
407
408 void FakeWebGraphicsContext3D::loseContextCHROMIUM(WGC3Denum current,
409 WGC3Denum other) {
410 if (context_lost_)
411 return;
412 context_lost_ = true;
413 if (context_lost_callback_)
414 context_lost_callback_->onContextLost();
415 }
416
417 WebKit::WebGLId FakeWebGraphicsContext3D::NextTextureId() {
418 WebGLId texture_id = next_texture_id_++;
419 DCHECK(texture_id < (1 << 16));
420 texture_id |= context_id_ << 16;
421 return texture_id;
422 }
423
424 } // namespace cc
OLDNEW
« no previous file with comments | « cc/test/fake_web_graphics_context_3d.h ('k') | cc/test/fake_web_graphics_context_3d_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698