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

Side by Side Diff: components/test_runner/test_plugin.cc

Issue 1817323003: Revert of Remove create/delete methods from WebGraphicsContext3D. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@complex-casts
Patch Set: Created 4 years, 9 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
« no previous file with comments | « components/test_runner/test_plugin.h ('k') | gpu/blink/webgraphicscontext3d_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/test_runner/test_plugin.h" 5 #include "components/test_runner/test_plugin.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 21 matching lines...) Expand all
32 #include "third_party/skia/include/core/SkBitmap.h" 32 #include "third_party/skia/include/core/SkBitmap.h"
33 #include "third_party/skia/include/core/SkCanvas.h" 33 #include "third_party/skia/include/core/SkCanvas.h"
34 #include "third_party/skia/include/core/SkColor.h" 34 #include "third_party/skia/include/core/SkColor.h"
35 #include "third_party/skia/include/core/SkPaint.h" 35 #include "third_party/skia/include/core/SkPaint.h"
36 #include "third_party/skia/include/core/SkPath.h" 36 #include "third_party/skia/include/core/SkPath.h"
37 37
38 namespace test_runner { 38 namespace test_runner {
39 39
40 namespace { 40 namespace {
41 41
42 void PremultiplyAlpha(const uint8_t color_in[3], 42 void PremultiplyAlpha(const unsigned color_in[3],
43 float alpha, 43 float alpha,
44 float color_out[4]) { 44 float color_out[4]) {
45 for (int i = 0; i < 3; ++i) 45 for (int i = 0; i < 3; ++i)
46 color_out[i] = (color_in[i] / 255.0f) * alpha; 46 color_out[i] = (color_in[i] / 255.0f) * alpha;
47 47
48 color_out[3] = alpha; 48 color_out[3] = alpha;
49 } 49 }
50 50
51 const char* PointState(blink::WebTouchPoint::State state) { 51 const char* PointState(blink::WebTouchPoint::State state) {
52 switch (state) { 52 switch (state) {
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 primitive = PrimitiveNone; 327 primitive = PrimitiveNone;
328 else if (string == kPrimitiveTriangle) 328 else if (string == kPrimitiveTriangle)
329 primitive = PrimitiveTriangle; 329 primitive = PrimitiveTriangle;
330 else 330 else
331 NOTREACHED(); 331 NOTREACHED();
332 return primitive; 332 return primitive;
333 } 333 }
334 334
335 // FIXME: This method should already exist. Use it. 335 // FIXME: This method should already exist. Use it.
336 // For now just parse primary colors. 336 // For now just parse primary colors.
337 void TestPlugin::ParseColor(const blink::WebString& string, uint8_t color[3]) { 337 void TestPlugin::ParseColor(const blink::WebString& string, unsigned color[3]) {
338 color[0] = color[1] = color[2] = 0; 338 color[0] = color[1] = color[2] = 0;
339 if (string == "black") 339 if (string == "black")
340 return; 340 return;
341 341
342 if (string == "red") 342 if (string == "red")
343 color[0] = 255; 343 color[0] = 255;
344 else if (string == "green") 344 else if (string == "green")
345 color[1] = 255; 345 color[1] = 255;
346 else if (string == "blue") 346 else if (string == "blue")
347 color[2] = 255; 347 color[2] = 255;
348 else 348 else
349 NOTREACHED(); 349 NOTREACHED();
350 } 350 }
351 351
352 float TestPlugin::ParseOpacity(const blink::WebString& string) { 352 float TestPlugin::ParseOpacity(const blink::WebString& string) {
353 return static_cast<float>(atof(string.utf8().data())); 353 return static_cast<float>(atof(string.utf8().data()));
354 } 354 }
355 355
356 bool TestPlugin::ParseBoolean(const blink::WebString& string) { 356 bool TestPlugin::ParseBoolean(const blink::WebString& string) {
357 const CR_DEFINE_STATIC_LOCAL(blink::WebString, kPrimitiveTrue, ("true")); 357 const CR_DEFINE_STATIC_LOCAL(blink::WebString, kPrimitiveTrue, ("true"));
358 return string == kPrimitiveTrue; 358 return string == kPrimitiveTrue;
359 } 359 }
360 360
361 bool TestPlugin::InitScene() { 361 bool TestPlugin::InitScene() {
362 if (!gl_) 362 if (!context_)
363 return true; 363 return true;
364 364
365 float color[4]; 365 float color[4];
366 PremultiplyAlpha(scene_.background_color, scene_.opacity, color); 366 PremultiplyAlpha(scene_.background_color, scene_.opacity, color);
367 367
368 gl_->GenTextures(1, &color_texture_); 368 color_texture_ = context_->createTexture();
369 gl_->GenFramebuffers(1, &framebuffer_); 369 framebuffer_ = context_->createFramebuffer();
370 370
371 gl_->Viewport(0, 0, rect_.width, rect_.height); 371 gl_->Viewport(0, 0, rect_.width, rect_.height);
372 gl_->Disable(GL_DEPTH_TEST); 372 gl_->Disable(GL_DEPTH_TEST);
373 gl_->Disable(GL_SCISSOR_TEST); 373 gl_->Disable(GL_SCISSOR_TEST);
374 374
375 gl_->ClearColor(color[0], color[1], color[2], color[3]); 375 gl_->ClearColor(color[0], color[1], color[2], color[3]);
376 376
377 gl_->Enable(GL_BLEND); 377 gl_->Enable(GL_BLEND);
378 gl_->BlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); 378 gl_->BlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
379 379
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 canvas.drawPath(triangle_path, paint); 416 canvas.drawPath(triangle_path, paint);
417 } 417 }
418 } 418 }
419 419
420 void TestPlugin::DestroyScene() { 420 void TestPlugin::DestroyScene() {
421 if (scene_.program) { 421 if (scene_.program) {
422 gl_->DeleteProgram(scene_.program); 422 gl_->DeleteProgram(scene_.program);
423 scene_.program = 0; 423 scene_.program = 0;
424 } 424 }
425 if (scene_.vbo) { 425 if (scene_.vbo) {
426 gl_->DeleteBuffers(1, &scene_.vbo); 426 context_->deleteBuffer(scene_.vbo);
427 scene_.vbo = 0; 427 scene_.vbo = 0;
428 } 428 }
429 429
430 if (framebuffer_) { 430 if (framebuffer_) {
431 gl_->DeleteFramebuffers(1, &framebuffer_); 431 context_->deleteFramebuffer(framebuffer_);
432 framebuffer_ = 0; 432 framebuffer_ = 0;
433 } 433 }
434 434
435 if (color_texture_) { 435 if (color_texture_) {
436 gl_->DeleteTextures(1, &color_texture_); 436 context_->deleteTexture(color_texture_);
437 color_texture_ = 0; 437 color_texture_ = 0;
438 } 438 }
439 } 439 }
440 440
441 bool TestPlugin::InitProgram() { 441 bool TestPlugin::InitProgram() {
442 const std::string vertex_source( 442 const std::string vertex_source(
443 "attribute vec4 position; \n" 443 "attribute vec4 position; \n"
444 "void main() { \n" 444 "void main() { \n"
445 " gl_Position = position; \n" 445 " gl_Position = position; \n"
446 "} \n"); 446 "} \n");
(...skipping 10 matching lines...) Expand all
457 return false; 457 return false;
458 458
459 scene_.color_location = gl_->GetUniformLocation(scene_.program, "color"); 459 scene_.color_location = gl_->GetUniformLocation(scene_.program, "color");
460 scene_.position_location = gl_->GetAttribLocation(scene_.program, "position"); 460 scene_.position_location = gl_->GetAttribLocation(scene_.program, "position");
461 return true; 461 return true;
462 } 462 }
463 463
464 bool TestPlugin::InitPrimitive() { 464 bool TestPlugin::InitPrimitive() {
465 DCHECK_EQ(scene_.primitive, PrimitiveTriangle); 465 DCHECK_EQ(scene_.primitive, PrimitiveTriangle);
466 466
467 gl_->GenBuffers(1, &scene_.vbo); 467 scene_.vbo = context_->createBuffer();
468 if (!scene_.vbo) 468 if (!scene_.vbo)
469 return false; 469 return false;
470 470
471 const float vertices[] = {0.0f, 0.8f, 0.0f, -0.8f, -0.8f, 471 const float vertices[] = {0.0f, 0.8f, 0.0f, -0.8f, -0.8f,
472 0.0f, 0.8f, -0.8f, 0.0f}; 472 0.0f, 0.8f, -0.8f, 0.0f};
473 gl_->BindBuffer(GL_ARRAY_BUFFER, scene_.vbo); 473 gl_->BindBuffer(GL_ARRAY_BUFFER, scene_.vbo);
474 gl_->BufferData(GL_ARRAY_BUFFER, sizeof(vertices), 0, GL_STATIC_DRAW); 474 gl_->BufferData(GL_ARRAY_BUFFER, sizeof(vertices), 0, GL_STATIC_DRAW);
475 gl_->BufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices); 475 gl_->BufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices);
476 return true; 476 return true;
477 } 477 }
(...skipping 11 matching lines...) Expand all
489 gl_->Uniform4f(scene_.color_location, color[0], color[1], color[2], color[3]); 489 gl_->Uniform4f(scene_.color_location, color[0], color[1], color[2], color[3]);
490 490
491 // Bind primitive vertices. 491 // Bind primitive vertices.
492 gl_->BindBuffer(GL_ARRAY_BUFFER, scene_.vbo); 492 gl_->BindBuffer(GL_ARRAY_BUFFER, scene_.vbo);
493 gl_->EnableVertexAttribArray(scene_.position_location); 493 gl_->EnableVertexAttribArray(scene_.position_location);
494 gl_->VertexAttribPointer(scene_.position_location, 3, GL_FLOAT, GL_FALSE, 0, 494 gl_->VertexAttribPointer(scene_.position_location, 3, GL_FLOAT, GL_FALSE, 0,
495 nullptr); 495 nullptr);
496 gl_->DrawArrays(GL_TRIANGLES, 0, 3); 496 gl_->DrawArrays(GL_TRIANGLES, 0, 3);
497 } 497 }
498 498
499 GLuint TestPlugin::LoadShader(GLenum type, const std::string& source) { 499 unsigned TestPlugin::LoadShader(unsigned type, const std::string& source) {
500 GLuint shader = gl_->CreateShader(type); 500 unsigned shader = gl_->CreateShader(type);
501 if (shader) { 501 if (shader) {
502 context_->shaderSource(shader, source.data()); 502 context_->shaderSource(shader, source.data());
503 gl_->CompileShader(shader); 503 gl_->CompileShader(shader);
504 504
505 int compiled = 0; 505 int compiled = 0;
506 gl_->GetShaderiv(shader, GL_COMPILE_STATUS, &compiled); 506 gl_->GetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
507 if (!compiled) { 507 if (!compiled) {
508 gl_->DeleteShader(shader); 508 gl_->DeleteShader(shader);
509 shader = 0; 509 shader = 0;
510 } 510 }
511 } 511 }
512 return shader; 512 return shader;
513 } 513 }
514 514
515 GLuint TestPlugin::LoadProgram(const std::string& vertex_source, 515 unsigned TestPlugin::LoadProgram(const std::string& vertex_source,
516 const std::string& fragment_source) { 516 const std::string& fragment_source) {
517 GLuint vertex_shader = LoadShader(GL_VERTEX_SHADER, vertex_source); 517 unsigned vertex_shader = LoadShader(GL_VERTEX_SHADER, vertex_source);
518 GLuint fragment_shader = LoadShader(GL_FRAGMENT_SHADER, fragment_source); 518 unsigned fragment_shader = LoadShader(GL_FRAGMENT_SHADER, fragment_source);
519 GLuint program = gl_->CreateProgram(); 519 unsigned program = gl_->CreateProgram();
520 if (vertex_shader && fragment_shader && program) { 520 if (vertex_shader && fragment_shader && program) {
521 gl_->AttachShader(program, vertex_shader); 521 gl_->AttachShader(program, vertex_shader);
522 gl_->AttachShader(program, fragment_shader); 522 gl_->AttachShader(program, fragment_shader);
523 gl_->LinkProgram(program); 523 gl_->LinkProgram(program);
524 524
525 int linked = 0; 525 int linked = 0;
526 gl_->GetProgramiv(program, GL_LINK_STATUS, &linked); 526 gl_->GetProgramiv(program, GL_LINK_STATUS, &linked);
527 if (!linked) { 527 if (!linked) {
528 gl_->DeleteProgram(program); 528 gl_->DeleteProgram(program);
529 program = 0; 529 program = 0;
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 return kPluginPersistsMimeType; 723 return kPluginPersistsMimeType;
724 } 724 }
725 725
726 bool TestPlugin::IsSupportedMimeType(const blink::WebString& mime_type) { 726 bool TestPlugin::IsSupportedMimeType(const blink::WebString& mime_type) {
727 return mime_type == TestPlugin::MimeType() || 727 return mime_type == TestPlugin::MimeType() ||
728 mime_type == PluginPersistsMimeType() || 728 mime_type == PluginPersistsMimeType() ||
729 mime_type == CanCreateWithoutRendererMimeType(); 729 mime_type == CanCreateWithoutRendererMimeType();
730 } 730 }
731 731
732 } // namespace test_runner 732 } // namespace test_runner
OLDNEW
« no previous file with comments | « components/test_runner/test_plugin.h ('k') | gpu/blink/webgraphicscontext3d_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698