| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "GLBench.h" | 8 #include "GLBench.h" |
| 9 | 9 |
| 10 #if SK_SUPPORT_GPU | 10 #if SK_SUPPORT_GPU |
| 11 #include "GrTest.h" | 11 #include "GrTest.h" |
| 12 #include <stdio.h> | 12 #include <stdio.h> |
| 13 | 13 |
| 14 const GrGLContext* GLBench::getGLContext(SkCanvas* canvas) { | 14 const GrGLContext* GLBench::getGLContext(SkCanvas* canvas) { |
| 15 // This bench exclusively tests GL calls directly | 15 // This bench exclusively tests GL calls directly |
| 16 if (NULL == canvas->getGrContext()) { | 16 if (nullptr == canvas->getGrContext()) { |
| 17 return NULL; | 17 return nullptr; |
| 18 } | 18 } |
| 19 GrContext* context = canvas->getGrContext(); | 19 GrContext* context = canvas->getGrContext(); |
| 20 GrGpu* gpu = context->getGpu(); | 20 GrGpu* gpu = context->getGpu(); |
| 21 if (!gpu) { | 21 if (!gpu) { |
| 22 SkDebugf("Couldn't get Gr gpu."); | 22 SkDebugf("Couldn't get Gr gpu."); |
| 23 return NULL; | 23 return nullptr; |
| 24 } | 24 } |
| 25 | 25 |
| 26 const GrGLContext* ctx = gpu->glContextForTesting(); | 26 const GrGLContext* ctx = gpu->glContextForTesting(); |
| 27 if (!ctx) { | 27 if (!ctx) { |
| 28 SkDebugf("Couldn't get an interface\n"); | 28 SkDebugf("Couldn't get an interface\n"); |
| 29 return NULL; | 29 return nullptr; |
| 30 } | 30 } |
| 31 | 31 |
| 32 return this->onGetGLContext(ctx); | 32 return this->onGetGLContext(ctx); |
| 33 } | 33 } |
| 34 | 34 |
| 35 void GLBench::onPerCanvasPreDraw(SkCanvas* canvas) { | 35 void GLBench::onPerCanvasPreDraw(SkCanvas* canvas) { |
| 36 // This bench exclusively tests GL calls directly | 36 // This bench exclusively tests GL calls directly |
| 37 const GrGLContext* ctx = this->getGLContext(canvas); | 37 const GrGLContext* ctx = this->getGLContext(canvas); |
| 38 if (!ctx) { | 38 if (!ctx) { |
| 39 return; | 39 return; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 57 } | 57 } |
| 58 this->glDraw(loops, ctx); | 58 this->glDraw(loops, ctx); |
| 59 } | 59 } |
| 60 | 60 |
| 61 GrGLuint GLBench::CompileShader(const GrGLInterface* gl, const char* shaderSrc,
GrGLenum type) { | 61 GrGLuint GLBench::CompileShader(const GrGLInterface* gl, const char* shaderSrc,
GrGLenum type) { |
| 62 GrGLuint shader; | 62 GrGLuint shader; |
| 63 // Create the shader object | 63 // Create the shader object |
| 64 GR_GL_CALL_RET(gl, shader, CreateShader(type)); | 64 GR_GL_CALL_RET(gl, shader, CreateShader(type)); |
| 65 | 65 |
| 66 // Load the shader source | 66 // Load the shader source |
| 67 GR_GL_CALL(gl, ShaderSource(shader, 1, &shaderSrc, NULL)); | 67 GR_GL_CALL(gl, ShaderSource(shader, 1, &shaderSrc, nullptr)); |
| 68 | 68 |
| 69 // Compile the shader | 69 // Compile the shader |
| 70 GR_GL_CALL(gl, CompileShader(shader)); | 70 GR_GL_CALL(gl, CompileShader(shader)); |
| 71 | 71 |
| 72 // Check for compile time errors | 72 // Check for compile time errors |
| 73 GrGLint success; | 73 GrGLint success; |
| 74 GrGLchar infoLog[512]; | 74 GrGLchar infoLog[512]; |
| 75 GR_GL_CALL(gl, GetShaderiv(shader, GR_GL_COMPILE_STATUS, &success)); | 75 GR_GL_CALL(gl, GetShaderiv(shader, GR_GL_COMPILE_STATUS, &success)); |
| 76 if (!success) { | 76 if (!success) { |
| 77 GR_GL_CALL(gl, GetShaderInfoLog(shader, 512, NULL, infoLog)); | 77 GR_GL_CALL(gl, GetShaderInfoLog(shader, 512, nullptr, infoLog)); |
| 78 SkDebugf("ERROR::SHADER::COMPLIATION_FAILED: %s\n", infoLog); | 78 SkDebugf("ERROR::SHADER::COMPLIATION_FAILED: %s\n", infoLog); |
| 79 } | 79 } |
| 80 | 80 |
| 81 return shader; | 81 return shader; |
| 82 } | 82 } |
| 83 | 83 |
| 84 GrGLuint GLBench::CreateProgram(const GrGLInterface* gl, const char* vshader, co
nst char* fshader) { | 84 GrGLuint GLBench::CreateProgram(const GrGLInterface* gl, const char* vshader, co
nst char* fshader) { |
| 85 | 85 |
| 86 GrGLuint vertexShader = CompileShader(gl, vshader, GR_GL_VERTEX_SHADER); | 86 GrGLuint vertexShader = CompileShader(gl, vshader, GR_GL_VERTEX_SHADER); |
| 87 GrGLuint fragmentShader = CompileShader(gl, fshader, GR_GL_FRAGMENT_SHADER); | 87 GrGLuint fragmentShader = CompileShader(gl, fshader, GR_GL_FRAGMENT_SHADER); |
| 88 | 88 |
| 89 GrGLuint shaderProgram; | 89 GrGLuint shaderProgram; |
| 90 GR_GL_CALL_RET(gl, shaderProgram, CreateProgram()); | 90 GR_GL_CALL_RET(gl, shaderProgram, CreateProgram()); |
| 91 GR_GL_CALL(gl, AttachShader(shaderProgram, vertexShader)); | 91 GR_GL_CALL(gl, AttachShader(shaderProgram, vertexShader)); |
| 92 GR_GL_CALL(gl, AttachShader(shaderProgram, fragmentShader)); | 92 GR_GL_CALL(gl, AttachShader(shaderProgram, fragmentShader)); |
| 93 GR_GL_CALL(gl, LinkProgram(shaderProgram)); | 93 GR_GL_CALL(gl, LinkProgram(shaderProgram)); |
| 94 | 94 |
| 95 // Check for linking errors | 95 // Check for linking errors |
| 96 GrGLint success; | 96 GrGLint success; |
| 97 GrGLchar infoLog[512]; | 97 GrGLchar infoLog[512]; |
| 98 GR_GL_CALL(gl, GetProgramiv(shaderProgram, GR_GL_LINK_STATUS, &success)); | 98 GR_GL_CALL(gl, GetProgramiv(shaderProgram, GR_GL_LINK_STATUS, &success)); |
| 99 if (!success) { | 99 if (!success) { |
| 100 GR_GL_CALL(gl, GetProgramInfoLog(shaderProgram, 512, NULL, infoLog)); | 100 GR_GL_CALL(gl, GetProgramInfoLog(shaderProgram, 512, nullptr, infoLog)); |
| 101 SkDebugf("Linker Error: %s\n", infoLog); | 101 SkDebugf("Linker Error: %s\n", infoLog); |
| 102 } | 102 } |
| 103 GR_GL_CALL(gl, DeleteShader(vertexShader)); | 103 GR_GL_CALL(gl, DeleteShader(vertexShader)); |
| 104 GR_GL_CALL(gl, DeleteShader(fragmentShader)); | 104 GR_GL_CALL(gl, DeleteShader(fragmentShader)); |
| 105 | 105 |
| 106 return shaderProgram; | 106 return shaderProgram; |
| 107 } | 107 } |
| 108 | 108 |
| 109 GrGLuint GLBench::SetupFramebuffer(const GrGLInterface* gl, int screenWidth, int
screenHeight) { | 109 GrGLuint GLBench::SetupFramebuffer(const GrGLInterface* gl, int screenWidth, int
screenHeight) { |
| 110 //Setup framebuffer | 110 //Setup framebuffer |
| 111 GrGLuint texture; | 111 GrGLuint texture; |
| 112 GR_GL_CALL(gl, GenTextures(1, &texture)); | 112 GR_GL_CALL(gl, GenTextures(1, &texture)); |
| 113 GR_GL_CALL(gl, ActiveTexture(GR_GL_TEXTURE15)); | 113 GR_GL_CALL(gl, ActiveTexture(GR_GL_TEXTURE15)); |
| 114 GR_GL_CALL(gl, BindTexture(GR_GL_TEXTURE_2D, texture)); | 114 GR_GL_CALL(gl, BindTexture(GR_GL_TEXTURE_2D, texture)); |
| 115 GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_MAG_FILTER, GR_
GL_NEAREST)); | 115 GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_MAG_FILTER, GR_
GL_NEAREST)); |
| 116 GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_MIN_FILTER, GR_
GL_NEAREST)); | 116 GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_MIN_FILTER, GR_
GL_NEAREST)); |
| 117 GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_WRAP_S, GR_GL_C
LAMP_TO_EDGE)); | 117 GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_WRAP_S, GR_GL_C
LAMP_TO_EDGE)); |
| 118 GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_WRAP_T, GR_GL_C
LAMP_TO_EDGE)); | 118 GR_GL_CALL(gl, TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_WRAP_T, GR_GL_C
LAMP_TO_EDGE)); |
| 119 GR_GL_CALL(gl, TexImage2D(GR_GL_TEXTURE_2D, | 119 GR_GL_CALL(gl, TexImage2D(GR_GL_TEXTURE_2D, |
| 120 0, //level | 120 0, //level |
| 121 GR_GL_RGBA, //internal format | 121 GR_GL_RGBA, //internal format |
| 122 screenWidth, // width | 122 screenWidth, // width |
| 123 screenHeight, // height | 123 screenHeight, // height |
| 124 0, //border | 124 0, //border |
| 125 GR_GL_RGBA, //format | 125 GR_GL_RGBA, //format |
| 126 GR_GL_UNSIGNED_BYTE, // type | 126 GR_GL_UNSIGNED_BYTE, // type |
| 127 NULL)); | 127 nullptr)); |
| 128 | 128 |
| 129 // bind framebuffer | 129 // bind framebuffer |
| 130 GrGLuint framebuffer; | 130 GrGLuint framebuffer; |
| 131 GR_GL_CALL(gl, BindTexture(GR_GL_TEXTURE_2D, 0)); | 131 GR_GL_CALL(gl, BindTexture(GR_GL_TEXTURE_2D, 0)); |
| 132 GR_GL_CALL(gl, GenFramebuffers(1, &framebuffer)); | 132 GR_GL_CALL(gl, GenFramebuffers(1, &framebuffer)); |
| 133 GR_GL_CALL(gl, BindFramebuffer(GR_GL_FRAMEBUFFER, framebuffer)); | 133 GR_GL_CALL(gl, BindFramebuffer(GR_GL_FRAMEBUFFER, framebuffer)); |
| 134 GR_GL_CALL(gl, FramebufferTexture2D(GR_GL_FRAMEBUFFER, | 134 GR_GL_CALL(gl, FramebufferTexture2D(GR_GL_FRAMEBUFFER, |
| 135 GR_GL_COLOR_ATTACHMENT0, | 135 GR_GL_COLOR_ATTACHMENT0, |
| 136 GR_GL_TEXTURE_2D, | 136 GR_GL_TEXTURE_2D, |
| 137 texture, 0)); | 137 texture, 0)); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 163 bm.setPixels(readback.get()); | 163 bm.setPixels(readback.get()); |
| 164 | 164 |
| 165 if (!SkImageEncoder::EncodeFile(filename, bm, SkImageEncoder::kPNG_Type, 100
)) { | 165 if (!SkImageEncoder::EncodeFile(filename, bm, SkImageEncoder::kPNG_Type, 100
)) { |
| 166 SkDebugf("------ failed to encode %s\n", filename); | 166 SkDebugf("------ failed to encode %s\n", filename); |
| 167 remove(filename); // remove any partial file | 167 remove(filename); // remove any partial file |
| 168 return; | 168 return; |
| 169 } | 169 } |
| 170 } | 170 } |
| 171 | 171 |
| 172 #endif | 172 #endif |
| OLD | NEW |