| OLD | NEW |
| 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 22 matching lines...) Expand all Loading... |
| 33 #include "third_party/skia/include/core/SkBitmap.h" | 33 #include "third_party/skia/include/core/SkBitmap.h" |
| 34 #include "third_party/skia/include/core/SkCanvas.h" | 34 #include "third_party/skia/include/core/SkCanvas.h" |
| 35 #include "third_party/skia/include/core/SkColor.h" | 35 #include "third_party/skia/include/core/SkColor.h" |
| 36 #include "third_party/skia/include/core/SkPaint.h" | 36 #include "third_party/skia/include/core/SkPaint.h" |
| 37 #include "third_party/skia/include/core/SkPath.h" | 37 #include "third_party/skia/include/core/SkPath.h" |
| 38 | 38 |
| 39 namespace test_runner { | 39 namespace test_runner { |
| 40 | 40 |
| 41 namespace { | 41 namespace { |
| 42 | 42 |
| 43 void PremultiplyAlpha(const unsigned color_in[3], | 43 void PremultiplyAlpha(const uint8_t color_in[3], |
| 44 float alpha, | 44 float alpha, |
| 45 float color_out[4]) { | 45 float color_out[4]) { |
| 46 for (int i = 0; i < 3; ++i) | 46 for (int i = 0; i < 3; ++i) |
| 47 color_out[i] = (color_in[i] / 255.0f) * alpha; | 47 color_out[i] = (color_in[i] / 255.0f) * alpha; |
| 48 | 48 |
| 49 color_out[3] = alpha; | 49 color_out[3] = alpha; |
| 50 } | 50 } |
| 51 | 51 |
| 52 const char* PointState(blink::WebTouchPoint::State state) { | 52 const char* PointState(blink::WebTouchPoint::State state) { |
| 53 switch (state) { | 53 switch (state) { |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 primitive = PrimitiveNone; | 330 primitive = PrimitiveNone; |
| 331 else if (string == kPrimitiveTriangle) | 331 else if (string == kPrimitiveTriangle) |
| 332 primitive = PrimitiveTriangle; | 332 primitive = PrimitiveTriangle; |
| 333 else | 333 else |
| 334 NOTREACHED(); | 334 NOTREACHED(); |
| 335 return primitive; | 335 return primitive; |
| 336 } | 336 } |
| 337 | 337 |
| 338 // FIXME: This method should already exist. Use it. | 338 // FIXME: This method should already exist. Use it. |
| 339 // For now just parse primary colors. | 339 // For now just parse primary colors. |
| 340 void TestPlugin::ParseColor(const blink::WebString& string, unsigned color[3]) { | 340 void TestPlugin::ParseColor(const blink::WebString& string, uint8_t color[3]) { |
| 341 color[0] = color[1] = color[2] = 0; | 341 color[0] = color[1] = color[2] = 0; |
| 342 if (string == "black") | 342 if (string == "black") |
| 343 return; | 343 return; |
| 344 | 344 |
| 345 if (string == "red") | 345 if (string == "red") |
| 346 color[0] = 255; | 346 color[0] = 255; |
| 347 else if (string == "green") | 347 else if (string == "green") |
| 348 color[1] = 255; | 348 color[1] = 255; |
| 349 else if (string == "blue") | 349 else if (string == "blue") |
| 350 color[2] = 255; | 350 color[2] = 255; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 361 return string == kPrimitiveTrue; | 361 return string == kPrimitiveTrue; |
| 362 } | 362 } |
| 363 | 363 |
| 364 bool TestPlugin::InitScene() { | 364 bool TestPlugin::InitScene() { |
| 365 if (!gl_) | 365 if (!gl_) |
| 366 return true; | 366 return true; |
| 367 | 367 |
| 368 float color[4]; | 368 float color[4]; |
| 369 PremultiplyAlpha(scene_.background_color, scene_.opacity, color); | 369 PremultiplyAlpha(scene_.background_color, scene_.opacity, color); |
| 370 | 370 |
| 371 color_texture_ = context_->createTexture(); | 371 gl_->GenTextures(1, &color_texture_); |
| 372 framebuffer_ = context_->createFramebuffer(); | 372 gl_->GenFramebuffers(1, &framebuffer_); |
| 373 | 373 |
| 374 gl_->Viewport(0, 0, rect_.width, rect_.height); | 374 gl_->Viewport(0, 0, rect_.width, rect_.height); |
| 375 gl_->Disable(GL_DEPTH_TEST); | 375 gl_->Disable(GL_DEPTH_TEST); |
| 376 gl_->Disable(GL_SCISSOR_TEST); | 376 gl_->Disable(GL_SCISSOR_TEST); |
| 377 | 377 |
| 378 gl_->ClearColor(color[0], color[1], color[2], color[3]); | 378 gl_->ClearColor(color[0], color[1], color[2], color[3]); |
| 379 | 379 |
| 380 gl_->Enable(GL_BLEND); | 380 gl_->Enable(GL_BLEND); |
| 381 gl_->BlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); | 381 gl_->BlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); |
| 382 | 382 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 canvas.drawPath(triangle_path, paint); | 419 canvas.drawPath(triangle_path, paint); |
| 420 } | 420 } |
| 421 } | 421 } |
| 422 | 422 |
| 423 void TestPlugin::DestroyScene() { | 423 void TestPlugin::DestroyScene() { |
| 424 if (scene_.program) { | 424 if (scene_.program) { |
| 425 gl_->DeleteProgram(scene_.program); | 425 gl_->DeleteProgram(scene_.program); |
| 426 scene_.program = 0; | 426 scene_.program = 0; |
| 427 } | 427 } |
| 428 if (scene_.vbo) { | 428 if (scene_.vbo) { |
| 429 context_->deleteBuffer(scene_.vbo); | 429 gl_->DeleteBuffers(1, &scene_.vbo); |
| 430 scene_.vbo = 0; | 430 scene_.vbo = 0; |
| 431 } | 431 } |
| 432 | 432 |
| 433 if (framebuffer_) { | 433 if (framebuffer_) { |
| 434 context_->deleteFramebuffer(framebuffer_); | 434 gl_->DeleteFramebuffers(1, &framebuffer_); |
| 435 framebuffer_ = 0; | 435 framebuffer_ = 0; |
| 436 } | 436 } |
| 437 | 437 |
| 438 if (color_texture_) { | 438 if (color_texture_) { |
| 439 context_->deleteTexture(color_texture_); | 439 gl_->DeleteTextures(1, &color_texture_); |
| 440 color_texture_ = 0; | 440 color_texture_ = 0; |
| 441 } | 441 } |
| 442 } | 442 } |
| 443 | 443 |
| 444 bool TestPlugin::InitProgram() { | 444 bool TestPlugin::InitProgram() { |
| 445 const std::string vertex_source( | 445 const std::string vertex_source( |
| 446 "attribute vec4 position; \n" | 446 "attribute vec4 position; \n" |
| 447 "void main() { \n" | 447 "void main() { \n" |
| 448 " gl_Position = position; \n" | 448 " gl_Position = position; \n" |
| 449 "} \n"); | 449 "} \n"); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 460 return false; | 460 return false; |
| 461 | 461 |
| 462 scene_.color_location = gl_->GetUniformLocation(scene_.program, "color"); | 462 scene_.color_location = gl_->GetUniformLocation(scene_.program, "color"); |
| 463 scene_.position_location = gl_->GetAttribLocation(scene_.program, "position"); | 463 scene_.position_location = gl_->GetAttribLocation(scene_.program, "position"); |
| 464 return true; | 464 return true; |
| 465 } | 465 } |
| 466 | 466 |
| 467 bool TestPlugin::InitPrimitive() { | 467 bool TestPlugin::InitPrimitive() { |
| 468 DCHECK_EQ(scene_.primitive, PrimitiveTriangle); | 468 DCHECK_EQ(scene_.primitive, PrimitiveTriangle); |
| 469 | 469 |
| 470 scene_.vbo = context_->createBuffer(); | 470 gl_->GenBuffers(1, &scene_.vbo); |
| 471 if (!scene_.vbo) | 471 if (!scene_.vbo) |
| 472 return false; | 472 return false; |
| 473 | 473 |
| 474 const float vertices[] = {0.0f, 0.8f, 0.0f, -0.8f, -0.8f, | 474 const float vertices[] = {0.0f, 0.8f, 0.0f, -0.8f, -0.8f, |
| 475 0.0f, 0.8f, -0.8f, 0.0f}; | 475 0.0f, 0.8f, -0.8f, 0.0f}; |
| 476 gl_->BindBuffer(GL_ARRAY_BUFFER, scene_.vbo); | 476 gl_->BindBuffer(GL_ARRAY_BUFFER, scene_.vbo); |
| 477 gl_->BufferData(GL_ARRAY_BUFFER, sizeof(vertices), 0, GL_STATIC_DRAW); | 477 gl_->BufferData(GL_ARRAY_BUFFER, sizeof(vertices), 0, GL_STATIC_DRAW); |
| 478 gl_->BufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices); | 478 gl_->BufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices); |
| 479 return true; | 479 return true; |
| 480 } | 480 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 492 gl_->Uniform4f(scene_.color_location, color[0], color[1], color[2], color[3]); | 492 gl_->Uniform4f(scene_.color_location, color[0], color[1], color[2], color[3]); |
| 493 | 493 |
| 494 // Bind primitive vertices. | 494 // Bind primitive vertices. |
| 495 gl_->BindBuffer(GL_ARRAY_BUFFER, scene_.vbo); | 495 gl_->BindBuffer(GL_ARRAY_BUFFER, scene_.vbo); |
| 496 gl_->EnableVertexAttribArray(scene_.position_location); | 496 gl_->EnableVertexAttribArray(scene_.position_location); |
| 497 gl_->VertexAttribPointer(scene_.position_location, 3, GL_FLOAT, GL_FALSE, 0, | 497 gl_->VertexAttribPointer(scene_.position_location, 3, GL_FLOAT, GL_FALSE, 0, |
| 498 nullptr); | 498 nullptr); |
| 499 gl_->DrawArrays(GL_TRIANGLES, 0, 3); | 499 gl_->DrawArrays(GL_TRIANGLES, 0, 3); |
| 500 } | 500 } |
| 501 | 501 |
| 502 unsigned TestPlugin::LoadShader(unsigned type, const std::string& source) { | 502 GLuint TestPlugin::LoadShader(GLenum type, const std::string& source) { |
| 503 unsigned shader = gl_->CreateShader(type); | 503 GLuint shader = gl_->CreateShader(type); |
| 504 if (shader) { | 504 if (shader) { |
| 505 context_->shaderSource(shader, source.data()); | 505 context_->shaderSource(shader, source.data()); |
| 506 gl_->CompileShader(shader); | 506 gl_->CompileShader(shader); |
| 507 | 507 |
| 508 int compiled = 0; | 508 int compiled = 0; |
| 509 gl_->GetShaderiv(shader, GL_COMPILE_STATUS, &compiled); | 509 gl_->GetShaderiv(shader, GL_COMPILE_STATUS, &compiled); |
| 510 if (!compiled) { | 510 if (!compiled) { |
| 511 gl_->DeleteShader(shader); | 511 gl_->DeleteShader(shader); |
| 512 shader = 0; | 512 shader = 0; |
| 513 } | 513 } |
| 514 } | 514 } |
| 515 return shader; | 515 return shader; |
| 516 } | 516 } |
| 517 | 517 |
| 518 unsigned TestPlugin::LoadProgram(const std::string& vertex_source, | 518 GLuint TestPlugin::LoadProgram(const std::string& vertex_source, |
| 519 const std::string& fragment_source) { | 519 const std::string& fragment_source) { |
| 520 unsigned vertex_shader = LoadShader(GL_VERTEX_SHADER, vertex_source); | 520 GLuint vertex_shader = LoadShader(GL_VERTEX_SHADER, vertex_source); |
| 521 unsigned fragment_shader = LoadShader(GL_FRAGMENT_SHADER, fragment_source); | 521 GLuint fragment_shader = LoadShader(GL_FRAGMENT_SHADER, fragment_source); |
| 522 unsigned program = gl_->CreateProgram(); | 522 GLuint program = gl_->CreateProgram(); |
| 523 if (vertex_shader && fragment_shader && program) { | 523 if (vertex_shader && fragment_shader && program) { |
| 524 gl_->AttachShader(program, vertex_shader); | 524 gl_->AttachShader(program, vertex_shader); |
| 525 gl_->AttachShader(program, fragment_shader); | 525 gl_->AttachShader(program, fragment_shader); |
| 526 gl_->LinkProgram(program); | 526 gl_->LinkProgram(program); |
| 527 | 527 |
| 528 int linked = 0; | 528 int linked = 0; |
| 529 gl_->GetProgramiv(program, GL_LINK_STATUS, &linked); | 529 gl_->GetProgramiv(program, GL_LINK_STATUS, &linked); |
| 530 if (!linked) { | 530 if (!linked) { |
| 531 gl_->DeleteProgram(program); | 531 gl_->DeleteProgram(program); |
| 532 program = 0; | 532 program = 0; |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 return kPluginPersistsMimeType; | 726 return kPluginPersistsMimeType; |
| 727 } | 727 } |
| 728 | 728 |
| 729 bool TestPlugin::IsSupportedMimeType(const blink::WebString& mime_type) { | 729 bool TestPlugin::IsSupportedMimeType(const blink::WebString& mime_type) { |
| 730 return mime_type == TestPlugin::MimeType() || | 730 return mime_type == TestPlugin::MimeType() || |
| 731 mime_type == PluginPersistsMimeType() || | 731 mime_type == PluginPersistsMimeType() || |
| 732 mime_type == CanCreateWithoutRendererMimeType(); | 732 mime_type == CanCreateWithoutRendererMimeType(); |
| 733 } | 733 } |
| 734 | 734 |
| 735 } // namespace test_runner | 735 } // namespace test_runner |
| OLD | NEW |