| 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 "content/shell/renderer/test_runner/TestPlugin.h" | 5 #include "content/shell/renderer/test_runner/TestPlugin.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/shared_memory.h" | 10 #include "base/memory/shared_memory.h" |
| 11 #include "content/public/renderer/render_thread.h" | 11 #include "content/public/renderer/render_thread.h" |
| 12 #include "content/shell/renderer/test_runner/TestCommon.h" | 12 #include "content/shell/renderer/test_runner/TestCommon.h" |
| 13 #include "content/shell/renderer/test_runner/WebTestDelegate.h" | 13 #include "content/shell/renderer/test_runner/WebTestDelegate.h" |
| 14 #include "third_party/skia/include/core/SkBitmap.h" | 14 #include "third_party/skia/include/core/SkBitmap.h" |
| 15 #include "third_party/skia/include/core/SkCanvas.h" | 15 #include "third_party/skia/include/core/SkCanvas.h" |
| 16 #include "third_party/skia/include/core/SkColor.h" | 16 #include "third_party/skia/include/core/SkColor.h" |
| 17 #include "third_party/WebKit/public/platform/Platform.h" | 17 #include "third_party/WebKit/public/platform/Platform.h" |
| 18 #include "third_party/WebKit/public/platform/WebCompositorSupport.h" | 18 #include "third_party/WebKit/public/platform/WebCompositorSupport.h" |
| 19 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" | 19 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" |
| 20 #include "third_party/WebKit/public/web/WebFrame.h" | 20 #include "third_party/WebKit/public/web/WebFrame.h" |
| 21 #include "third_party/WebKit/public/web/WebInputEvent.h" | 21 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 22 #include "third_party/WebKit/public/web/WebKit.h" | 22 #include "third_party/WebKit/public/web/WebKit.h" |
| 23 #include "third_party/WebKit/public/web/WebPluginParams.h" | 23 #include "third_party/WebKit/public/web/WebPluginParams.h" |
| 24 #include "third_party/WebKit/public/web/WebTouchPoint.h" | 24 #include "third_party/WebKit/public/web/WebTouchPoint.h" |
| 25 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" | 25 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" |
| 26 | 26 |
| 27 using namespace blink; | 27 using namespace blink; |
| 28 using namespace std; | |
| 29 | 28 |
| 30 namespace content { | 29 namespace content { |
| 31 | 30 |
| 32 namespace { | 31 namespace { |
| 33 | 32 |
| 34 // GLenum values copied from gl2.h. | 33 // GLenum values copied from gl2.h. |
| 35 #define GL_FALSE 0 | 34 #define GL_FALSE 0 |
| 36 #define GL_TRUE 1 | 35 #define GL_TRUE 1 |
| 37 #define GL_ONE 1 | 36 #define GL_ONE 1 |
| 38 #define GL_TRIANGLES 0x0004 | 37 #define GL_TRIANGLES 0x0004 |
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 } | 469 } |
| 471 | 470 |
| 472 if (m_colorTexture) { | 471 if (m_colorTexture) { |
| 473 m_context->deleteTexture(m_colorTexture); | 472 m_context->deleteTexture(m_colorTexture); |
| 474 m_colorTexture = 0; | 473 m_colorTexture = 0; |
| 475 } | 474 } |
| 476 } | 475 } |
| 477 | 476 |
| 478 bool TestPlugin::initProgram() | 477 bool TestPlugin::initProgram() |
| 479 { | 478 { |
| 480 const string vertexSource( | 479 const std::string vertexSource( |
| 481 "attribute vec4 position; \n" | 480 "attribute vec4 position; \n" |
| 482 "void main() { \n" | 481 "void main() { \n" |
| 483 " gl_Position = position; \n" | 482 " gl_Position = position; \n" |
| 484 "} \n" | 483 "} \n" |
| 485 ); | 484 ); |
| 486 | 485 |
| 487 const string fragmentSource( | 486 const std::string fragmentSource( |
| 488 "precision mediump float; \n" | 487 "precision mediump float; \n" |
| 489 "uniform vec4 color; \n" | 488 "uniform vec4 color; \n" |
| 490 "void main() { \n" | 489 "void main() { \n" |
| 491 " gl_FragColor = color; \n" | 490 " gl_FragColor = color; \n" |
| 492 "} \n" | 491 "} \n" |
| 493 ); | 492 ); |
| 494 | 493 |
| 495 m_scene.program = loadProgram(vertexSource, fragmentSource); | 494 m_scene.program = loadProgram(vertexSource, fragmentSource); |
| 496 if (!m_scene.program) | 495 if (!m_scene.program) |
| 497 return false; | 496 return false; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 premultiplyAlpha(m_scene.primitiveColor, m_scene.opacity, color); | 531 premultiplyAlpha(m_scene.primitiveColor, m_scene.opacity, color); |
| 533 m_context->uniform4f(m_scene.colorLocation, color[0], color[1], color[2], co
lor[3]); | 532 m_context->uniform4f(m_scene.colorLocation, color[0], color[1], color[2], co
lor[3]); |
| 534 | 533 |
| 535 // Bind primitive vertices. | 534 // Bind primitive vertices. |
| 536 m_context->bindBuffer(GL_ARRAY_BUFFER, m_scene.vbo); | 535 m_context->bindBuffer(GL_ARRAY_BUFFER, m_scene.vbo); |
| 537 m_context->enableVertexAttribArray(m_scene.positionLocation); | 536 m_context->enableVertexAttribArray(m_scene.positionLocation); |
| 538 m_context->vertexAttribPointer(m_scene.positionLocation, 3, GL_FLOAT, GL_FAL
SE, 0, 0); | 537 m_context->vertexAttribPointer(m_scene.positionLocation, 3, GL_FLOAT, GL_FAL
SE, 0, 0); |
| 539 m_context->drawArrays(GL_TRIANGLES, 0, 3); | 538 m_context->drawArrays(GL_TRIANGLES, 0, 3); |
| 540 } | 539 } |
| 541 | 540 |
| 542 unsigned TestPlugin::loadShader(unsigned type, const string& source) | 541 unsigned TestPlugin::loadShader(unsigned type, const std::string& source) |
| 543 { | 542 { |
| 544 unsigned shader = m_context->createShader(type); | 543 unsigned shader = m_context->createShader(type); |
| 545 if (shader) { | 544 if (shader) { |
| 546 m_context->shaderSource(shader, source.data()); | 545 m_context->shaderSource(shader, source.data()); |
| 547 m_context->compileShader(shader); | 546 m_context->compileShader(shader); |
| 548 | 547 |
| 549 int compiled = 0; | 548 int compiled = 0; |
| 550 m_context->getShaderiv(shader, GL_COMPILE_STATUS, &compiled); | 549 m_context->getShaderiv(shader, GL_COMPILE_STATUS, &compiled); |
| 551 if (!compiled) { | 550 if (!compiled) { |
| 552 m_context->deleteShader(shader); | 551 m_context->deleteShader(shader); |
| 553 shader = 0; | 552 shader = 0; |
| 554 } | 553 } |
| 555 } | 554 } |
| 556 return shader; | 555 return shader; |
| 557 } | 556 } |
| 558 | 557 |
| 559 unsigned TestPlugin::loadProgram(const string& vertexSource, const string& fragm
entSource) | 558 unsigned TestPlugin::loadProgram(const std::string& vertexSource, const std::str
ing& fragmentSource) |
| 560 { | 559 { |
| 561 unsigned vertexShader = loadShader(GL_VERTEX_SHADER, vertexSource); | 560 unsigned vertexShader = loadShader(GL_VERTEX_SHADER, vertexSource); |
| 562 unsigned fragmentShader = loadShader(GL_FRAGMENT_SHADER, fragmentSource); | 561 unsigned fragmentShader = loadShader(GL_FRAGMENT_SHADER, fragmentSource); |
| 563 unsigned program = m_context->createProgram(); | 562 unsigned program = m_context->createProgram(); |
| 564 if (vertexShader && fragmentShader && program) { | 563 if (vertexShader && fragmentShader && program) { |
| 565 m_context->attachShader(program, vertexShader); | 564 m_context->attachShader(program, vertexShader); |
| 566 m_context->attachShader(program, fragmentShader); | 565 m_context->attachShader(program, fragmentShader); |
| 567 m_context->linkProgram(program); | 566 m_context->linkProgram(program); |
| 568 | 567 |
| 569 int linked = 0; | 568 int linked = 0; |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 684 } | 683 } |
| 685 | 684 |
| 686 bool TestPlugin::isSupportedMimeType(const WebString& mimeType) | 685 bool TestPlugin::isSupportedMimeType(const WebString& mimeType) |
| 687 { | 686 { |
| 688 return mimeType == TestPlugin::mimeType() | 687 return mimeType == TestPlugin::mimeType() |
| 689 || mimeType == pluginPersistsMimeType() | 688 || mimeType == pluginPersistsMimeType() |
| 690 || mimeType == canCreateWithoutRendererMimeType(); | 689 || mimeType == canCreateWithoutRendererMimeType(); |
| 691 } | 690 } |
| 692 | 691 |
| 693 } // namespace content | 692 } // namespace content |
| OLD | NEW |