| 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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 const blink::WebRect& unobscured_rect, | 234 const blink::WebRect& unobscured_rect, |
| 235 const blink::WebVector<blink::WebRect>& cut_outs_rects, | 235 const blink::WebVector<blink::WebRect>& cut_outs_rects, |
| 236 bool is_visible) { | 236 bool is_visible) { |
| 237 if (clip_rect == rect_) | 237 if (clip_rect == rect_) |
| 238 return; | 238 return; |
| 239 rect_ = clip_rect; | 239 rect_ = clip_rect; |
| 240 | 240 |
| 241 if (rect_.isEmpty()) { | 241 if (rect_.isEmpty()) { |
| 242 texture_mailbox_ = cc::TextureMailbox(); | 242 texture_mailbox_ = cc::TextureMailbox(); |
| 243 } else if (context_) { | 243 } else if (context_) { |
| 244 context_->viewport(0, 0, rect_.width, rect_.height); | 244 gl_->Viewport(0, 0, rect_.width, rect_.height); |
| 245 | 245 |
| 246 gl_->BindTexture(GL_TEXTURE_2D, color_texture_); | 246 gl_->BindTexture(GL_TEXTURE_2D, color_texture_); |
| 247 context_->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 247 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 248 context_->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 248 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 249 context_->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 249 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 250 context_->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 250 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 251 context_->texImage2D(GL_TEXTURE_2D, | 251 gl_->TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, rect_.width, rect_.height, 0, |
| 252 0, | 252 GL_RGBA, GL_UNSIGNED_BYTE, 0); |
| 253 GL_RGBA, | |
| 254 rect_.width, | |
| 255 rect_.height, | |
| 256 0, | |
| 257 GL_RGBA, | |
| 258 GL_UNSIGNED_BYTE, | |
| 259 0); | |
| 260 gl_->BindFramebuffer(GL_FRAMEBUFFER, framebuffer_); | 253 gl_->BindFramebuffer(GL_FRAMEBUFFER, framebuffer_); |
| 261 gl_->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | 254 gl_->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, |
| 262 GL_TEXTURE_2D, color_texture_, 0); | 255 GL_TEXTURE_2D, color_texture_, 0); |
| 263 | 256 |
| 264 DrawSceneGL(); | 257 DrawSceneGL(); |
| 265 | 258 |
| 266 gpu::Mailbox mailbox; | 259 gpu::Mailbox mailbox; |
| 267 gl_->GenMailboxCHROMIUM(mailbox.name); | 260 gl_->GenMailboxCHROMIUM(mailbox.name); |
| 268 gl_->ProduceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); | 261 gl_->ProduceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); |
| 269 const GLuint64 fence_sync = gl_->InsertFenceSyncCHROMIUM(); | 262 const GLuint64 fence_sync = gl_->InsertFenceSyncCHROMIUM(); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 bool TestPlugin::InitScene() { | 361 bool TestPlugin::InitScene() { |
| 369 if (!context_) | 362 if (!context_) |
| 370 return true; | 363 return true; |
| 371 | 364 |
| 372 float color[4]; | 365 float color[4]; |
| 373 PremultiplyAlpha(scene_.background_color, scene_.opacity, color); | 366 PremultiplyAlpha(scene_.background_color, scene_.opacity, color); |
| 374 | 367 |
| 375 color_texture_ = context_->createTexture(); | 368 color_texture_ = context_->createTexture(); |
| 376 framebuffer_ = context_->createFramebuffer(); | 369 framebuffer_ = context_->createFramebuffer(); |
| 377 | 370 |
| 378 context_->viewport(0, 0, rect_.width, rect_.height); | 371 gl_->Viewport(0, 0, rect_.width, rect_.height); |
| 379 gl_->Disable(GL_DEPTH_TEST); | 372 gl_->Disable(GL_DEPTH_TEST); |
| 380 gl_->Disable(GL_SCISSOR_TEST); | 373 gl_->Disable(GL_SCISSOR_TEST); |
| 381 | 374 |
| 382 gl_->ClearColor(color[0], color[1], color[2], color[3]); | 375 gl_->ClearColor(color[0], color[1], color[2], color[3]); |
| 383 | 376 |
| 384 gl_->Enable(GL_BLEND); | 377 gl_->Enable(GL_BLEND); |
| 385 gl_->BlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); | 378 gl_->BlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); |
| 386 | 379 |
| 387 return scene_.primitive != PrimitiveNone ? InitProgram() && InitPrimitive() | 380 return scene_.primitive != PrimitiveNone ? InitProgram() && InitPrimitive() |
| 388 : true; | 381 : true; |
| 389 } | 382 } |
| 390 | 383 |
| 391 void TestPlugin::DrawSceneGL() { | 384 void TestPlugin::DrawSceneGL() { |
| 392 context_->viewport(0, 0, rect_.width, rect_.height); | 385 gl_->Viewport(0, 0, rect_.width, rect_.height); |
| 393 gl_->Clear(GL_COLOR_BUFFER_BIT); | 386 gl_->Clear(GL_COLOR_BUFFER_BIT); |
| 394 | 387 |
| 395 if (scene_.primitive != PrimitiveNone) | 388 if (scene_.primitive != PrimitiveNone) |
| 396 DrawPrimitive(); | 389 DrawPrimitive(); |
| 397 } | 390 } |
| 398 | 391 |
| 399 void TestPlugin::DrawSceneSoftware(void* memory) { | 392 void TestPlugin::DrawSceneSoftware(void* memory) { |
| 400 SkColor background_color = SkColorSetARGB( | 393 SkColor background_color = SkColorSetARGB( |
| 401 static_cast<uint8_t>(scene_.opacity * 255), scene_.background_color[0], | 394 static_cast<uint8_t>(scene_.opacity * 255), scene_.background_color[0], |
| 402 scene_.background_color[1], scene_.background_color[2]); | 395 scene_.background_color[1], scene_.background_color[2]); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 419 triangle_path.lineTo(0.9f * rect_.width, 0.1f * rect_.height); | 412 triangle_path.lineTo(0.9f * rect_.width, 0.1f * rect_.height); |
| 420 SkPaint paint; | 413 SkPaint paint; |
| 421 paint.setColor(foreground_color); | 414 paint.setColor(foreground_color); |
| 422 paint.setStyle(SkPaint::kFill_Style); | 415 paint.setStyle(SkPaint::kFill_Style); |
| 423 canvas.drawPath(triangle_path, paint); | 416 canvas.drawPath(triangle_path, paint); |
| 424 } | 417 } |
| 425 } | 418 } |
| 426 | 419 |
| 427 void TestPlugin::DestroyScene() { | 420 void TestPlugin::DestroyScene() { |
| 428 if (scene_.program) { | 421 if (scene_.program) { |
| 429 context_->deleteProgram(scene_.program); | 422 gl_->DeleteProgram(scene_.program); |
| 430 scene_.program = 0; | 423 scene_.program = 0; |
| 431 } | 424 } |
| 432 if (scene_.vbo) { | 425 if (scene_.vbo) { |
| 433 context_->deleteBuffer(scene_.vbo); | 426 context_->deleteBuffer(scene_.vbo); |
| 434 scene_.vbo = 0; | 427 scene_.vbo = 0; |
| 435 } | 428 } |
| 436 | 429 |
| 437 if (framebuffer_) { | 430 if (framebuffer_) { |
| 438 context_->deleteFramebuffer(framebuffer_); | 431 context_->deleteFramebuffer(framebuffer_); |
| 439 framebuffer_ = 0; | 432 framebuffer_ = 0; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 gl_->BufferData(GL_ARRAY_BUFFER, sizeof(vertices), 0, GL_STATIC_DRAW); | 474 gl_->BufferData(GL_ARRAY_BUFFER, sizeof(vertices), 0, GL_STATIC_DRAW); |
| 482 gl_->BufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices); | 475 gl_->BufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices); |
| 483 return true; | 476 return true; |
| 484 } | 477 } |
| 485 | 478 |
| 486 void TestPlugin::DrawPrimitive() { | 479 void TestPlugin::DrawPrimitive() { |
| 487 DCHECK_EQ(scene_.primitive, PrimitiveTriangle); | 480 DCHECK_EQ(scene_.primitive, PrimitiveTriangle); |
| 488 DCHECK(scene_.vbo); | 481 DCHECK(scene_.vbo); |
| 489 DCHECK(scene_.program); | 482 DCHECK(scene_.program); |
| 490 | 483 |
| 491 context_->useProgram(scene_.program); | 484 gl_->UseProgram(scene_.program); |
| 492 | 485 |
| 493 // Bind primitive color. | 486 // Bind primitive color. |
| 494 float color[4]; | 487 float color[4]; |
| 495 PremultiplyAlpha(scene_.primitive_color, scene_.opacity, color); | 488 PremultiplyAlpha(scene_.primitive_color, scene_.opacity, color); |
| 496 context_->uniform4f( | 489 gl_->Uniform4f(scene_.color_location, color[0], color[1], color[2], color[3]); |
| 497 scene_.color_location, color[0], color[1], color[2], color[3]); | |
| 498 | 490 |
| 499 // Bind primitive vertices. | 491 // Bind primitive vertices. |
| 500 gl_->BindBuffer(GL_ARRAY_BUFFER, scene_.vbo); | 492 gl_->BindBuffer(GL_ARRAY_BUFFER, scene_.vbo); |
| 501 gl_->EnableVertexAttribArray(scene_.position_location); | 493 gl_->EnableVertexAttribArray(scene_.position_location); |
| 502 context_->vertexAttribPointer( | 494 context_->vertexAttribPointer( |
| 503 scene_.position_location, 3, GL_FLOAT, GL_FALSE, 0, 0); | 495 scene_.position_location, 3, GL_FLOAT, GL_FALSE, 0, 0); |
| 504 gl_->DrawArrays(GL_TRIANGLES, 0, 3); | 496 gl_->DrawArrays(GL_TRIANGLES, 0, 3); |
| 505 } | 497 } |
| 506 | 498 |
| 507 unsigned TestPlugin::LoadShader(unsigned type, const std::string& source) { | 499 unsigned TestPlugin::LoadShader(unsigned type, const std::string& source) { |
| 508 unsigned shader = context_->createShader(type); | 500 unsigned shader = gl_->CreateShader(type); |
| 509 if (shader) { | 501 if (shader) { |
| 510 context_->shaderSource(shader, source.data()); | 502 context_->shaderSource(shader, source.data()); |
| 511 gl_->CompileShader(shader); | 503 gl_->CompileShader(shader); |
| 512 | 504 |
| 513 int compiled = 0; | 505 int compiled = 0; |
| 514 gl_->GetShaderiv(shader, GL_COMPILE_STATUS, &compiled); | 506 gl_->GetShaderiv(shader, GL_COMPILE_STATUS, &compiled); |
| 515 if (!compiled) { | 507 if (!compiled) { |
| 516 context_->deleteShader(shader); | 508 gl_->DeleteShader(shader); |
| 517 shader = 0; | 509 shader = 0; |
| 518 } | 510 } |
| 519 } | 511 } |
| 520 return shader; | 512 return shader; |
| 521 } | 513 } |
| 522 | 514 |
| 523 unsigned TestPlugin::LoadProgram(const std::string& vertex_source, | 515 unsigned TestPlugin::LoadProgram(const std::string& vertex_source, |
| 524 const std::string& fragment_source) { | 516 const std::string& fragment_source) { |
| 525 unsigned vertex_shader = LoadShader(GL_VERTEX_SHADER, vertex_source); | 517 unsigned vertex_shader = LoadShader(GL_VERTEX_SHADER, vertex_source); |
| 526 unsigned fragment_shader = LoadShader(GL_FRAGMENT_SHADER, fragment_source); | 518 unsigned fragment_shader = LoadShader(GL_FRAGMENT_SHADER, fragment_source); |
| 527 unsigned program = context_->createProgram(); | 519 unsigned program = gl_->CreateProgram(); |
| 528 if (vertex_shader && fragment_shader && program) { | 520 if (vertex_shader && fragment_shader && program) { |
| 529 gl_->AttachShader(program, vertex_shader); | 521 gl_->AttachShader(program, vertex_shader); |
| 530 gl_->AttachShader(program, fragment_shader); | 522 gl_->AttachShader(program, fragment_shader); |
| 531 gl_->LinkProgram(program); | 523 gl_->LinkProgram(program); |
| 532 | 524 |
| 533 int linked = 0; | 525 int linked = 0; |
| 534 gl_->GetProgramiv(program, GL_LINK_STATUS, &linked); | 526 gl_->GetProgramiv(program, GL_LINK_STATUS, &linked); |
| 535 if (!linked) { | 527 if (!linked) { |
| 536 context_->deleteProgram(program); | 528 gl_->DeleteProgram(program); |
| 537 program = 0; | 529 program = 0; |
| 538 } | 530 } |
| 539 } | 531 } |
| 540 if (vertex_shader) | 532 if (vertex_shader) |
| 541 context_->deleteShader(vertex_shader); | 533 gl_->DeleteShader(vertex_shader); |
| 542 if (fragment_shader) | 534 if (fragment_shader) |
| 543 context_->deleteShader(fragment_shader); | 535 gl_->DeleteShader(fragment_shader); |
| 544 | 536 |
| 545 return program; | 537 return program; |
| 546 } | 538 } |
| 547 | 539 |
| 548 blink::WebInputEventResult TestPlugin::handleInputEvent( | 540 blink::WebInputEventResult TestPlugin::handleInputEvent( |
| 549 const blink::WebInputEvent& event, | 541 const blink::WebInputEvent& event, |
| 550 blink::WebCursorInfo& info) { | 542 blink::WebCursorInfo& info) { |
| 551 const char* event_name = 0; | 543 const char* event_name = 0; |
| 552 switch (event.type) { | 544 switch (event.type) { |
| 553 case blink::WebInputEvent::Undefined: | 545 case blink::WebInputEvent::Undefined: |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 731 return kPluginPersistsMimeType; | 723 return kPluginPersistsMimeType; |
| 732 } | 724 } |
| 733 | 725 |
| 734 bool TestPlugin::IsSupportedMimeType(const blink::WebString& mime_type) { | 726 bool TestPlugin::IsSupportedMimeType(const blink::WebString& mime_type) { |
| 735 return mime_type == TestPlugin::MimeType() || | 727 return mime_type == TestPlugin::MimeType() || |
| 736 mime_type == PluginPersistsMimeType() || | 728 mime_type == PluginPersistsMimeType() || |
| 737 mime_type == CanCreateWithoutRendererMimeType(); | 729 mime_type == CanCreateWithoutRendererMimeType(); |
| 738 } | 730 } |
| 739 | 731 |
| 740 } // namespace test_runner | 732 } // namespace test_runner |
| OLD | NEW |