| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "chrome/browser/android/vr_shell/mailbox_to_surface_bridge.h" | 5 #include "chrome/browser/android/vr_shell/mailbox_to_surface_bridge.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "services/ui/public/cpp/gpu/context_provider_command_buffer.h" | 21 #include "services/ui/public/cpp/gpu/context_provider_command_buffer.h" |
| 22 #include "ui/gl/android/surface_texture.h" | 22 #include "ui/gl/android/surface_texture.h" |
| 23 | 23 |
| 24 #include <android/native_window_jni.h> | 24 #include <android/native_window_jni.h> |
| 25 | 25 |
| 26 #define VOID_OFFSET(x) reinterpret_cast<void*>(x) | 26 #define VOID_OFFSET(x) reinterpret_cast<void*>(x) |
| 27 #define SHADER(Src) #Src | 27 #define SHADER(Src) #Src |
| 28 | 28 |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 /* clang-format off */ |
| 31 const char kQuadCopyVertex[] = SHADER( | 32 const char kQuadCopyVertex[] = SHADER( |
| 32 /* clang-format off */ | |
| 33 attribute vec4 a_Position; | 33 attribute vec4 a_Position; |
| 34 attribute vec2 a_TexCoordinate; | 34 attribute vec2 a_TexCoordinate; |
| 35 varying vec2 v_TexCoordinate; | 35 varying vec2 v_TexCoordinate; |
| 36 void main() { | 36 void main() { |
| 37 v_TexCoordinate = a_TexCoordinate; | 37 v_TexCoordinate = a_TexCoordinate; |
| 38 gl_Position = a_Position; | 38 gl_Position = a_Position; |
| 39 } | 39 } |
| 40 ); /* clang-format on */ | 40 ); |
| 41 | 41 |
| 42 const char kQuadCopyFragment[] = SHADER( | 42 const char kQuadCopyFragment[] = SHADER( |
| 43 /* clang-format off */ | |
| 44 precision highp float; | 43 precision highp float; |
| 45 uniform sampler2D u_Texture; | 44 uniform sampler2D u_Texture; |
| 46 varying vec2 v_TexCoordinate; | 45 varying vec2 v_TexCoordinate; |
| 47 void main() { | 46 void main() { |
| 48 gl_FragColor = texture2D(u_Texture, v_TexCoordinate); | 47 gl_FragColor = texture2D(u_Texture, v_TexCoordinate); |
| 49 } | 48 } |
| 50 ); /* clang-format on */ | 49 ); |
| 51 | 50 |
| 52 const float kQuadVertices[] = { | 51 const float kQuadVertices[] = { |
| 53 // clang-format off | |
| 54 // x y u, v | 52 // x y u, v |
| 55 -1.f, 1.f, 0.f, 1.f, | 53 -1.f, 1.f, 0.f, 1.f, |
| 56 -1.f, -1.f, 0.f, 0.f, | 54 -1.f, -1.f, 0.f, 0.f, |
| 57 1.f, -1.f, 1.f, 0.f, | 55 1.f, -1.f, 1.f, 0.f, |
| 58 1.f, 1.f, 1.f, 1.f}; | 56 1.f, 1.f, 1.f, 1.f}; |
| 57 /* clang-format on */ |
| 58 |
| 59 static constexpr int kQuadVerticesSize = sizeof(kQuadVertices); | 59 static constexpr int kQuadVerticesSize = sizeof(kQuadVertices); |
| 60 | 60 |
| 61 GLuint CompileShader(gpu::gles2::GLES2Interface* gl, | 61 GLuint CompileShader(gpu::gles2::GLES2Interface* gl, |
| 62 GLenum shader_type, | 62 GLenum shader_type, |
| 63 const GLchar* shader_source) { | 63 const GLchar* shader_source) { |
| 64 GLuint shader_handle = gl->CreateShader(shader_type); | 64 GLuint shader_handle = gl->CreateShader(shader_type); |
| 65 if (shader_handle != 0) { | 65 if (shader_handle != 0) { |
| 66 // Pass in the shader source. | 66 // Pass in the shader source. |
| 67 GLint len = strlen(shader_source); | 67 GLint len = strlen(shader_source); |
| 68 gl->ShaderSource(shader_handle, 1, &shader_source, &len); | 68 gl->ShaderSource(shader_handle, 1, &shader_source, &len); |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 return false; | 232 return false; |
| 233 } | 233 } |
| 234 | 234 |
| 235 if (needs_resize_) { | 235 if (needs_resize_) { |
| 236 ResizeSurface(resize_width_, resize_height_); | 236 ResizeSurface(resize_width_, resize_height_); |
| 237 needs_resize_ = false; | 237 needs_resize_ = false; |
| 238 } | 238 } |
| 239 | 239 |
| 240 GLuint sourceTexture = ConsumeTexture(gl_, mailbox); | 240 GLuint sourceTexture = ConsumeTexture(gl_, mailbox); |
| 241 DrawQuad(sourceTexture); | 241 DrawQuad(sourceTexture); |
| 242 gl_->DeleteTextures(1, &sourceTexture); |
| 242 gl_->SwapBuffers(); | 243 gl_->SwapBuffers(); |
| 243 return true; | 244 return true; |
| 244 } | 245 } |
| 245 | 246 |
| 246 void MailboxToSurfaceBridge::DestroyContext() { | 247 void MailboxToSurfaceBridge::DestroyContext() { |
| 247 gl_ = nullptr; | 248 gl_ = nullptr; |
| 248 context_provider_ = nullptr; | 249 context_provider_ = nullptr; |
| 249 } | 250 } |
| 250 | 251 |
| 251 void MailboxToSurfaceBridge::InitializeRenderer() { | 252 void MailboxToSurfaceBridge::InitializeRenderer() { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 // GL_NEAREST. | 337 // GL_NEAREST. |
| 337 gl_->BindTexture(GL_TEXTURE_2D, texture_handle); | 338 gl_->BindTexture(GL_TEXTURE_2D, texture_handle); |
| 338 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 339 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 339 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 340 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 340 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 341 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 341 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 342 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 342 gl_->DrawArrays(GL_TRIANGLE_FAN, 0, 4); | 343 gl_->DrawArrays(GL_TRIANGLE_FAN, 0, 4); |
| 343 } | 344 } |
| 344 | 345 |
| 345 } // namespace vr_shell | 346 } // namespace vr_shell |
| OLD | NEW |