Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <android/native_window.h> | |
| 6 #include <android/native_window_jni.h> | |
| 7 | |
| 8 #include "base/android/jni_android.h" | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | |
| 10 #include "ui/gfx/buffer_format_util.h" | |
| 11 #include "ui/gl/android/scoped_java_surface.h" | |
| 12 #include "ui/gl/android/surface_texture.h" | |
| 13 #include "ui/gl/gl_image_surface_texture.h" | |
| 14 #include "ui/gl/test/gl_image_test_template.h" | |
| 15 | |
| 16 namespace gfx { | |
|
Daniele Castagna
2015/12/05 23:43:57
This should be gl.
reveman
2015/12/05 23:54:07
Done.
| |
| 17 namespace { | |
| 18 | |
| 19 class GLImageSurfaceTextureTestDelegate { | |
| 20 public: | |
| 21 scoped_refptr<gl::GLImage> CreateSolidColorImage( | |
| 22 const Size& size, | |
| 23 const uint8_t color[4]) const { | |
| 24 scoped_refptr<gl::GLImageSurfaceTexture> image( | |
| 25 new gl::GLImageSurfaceTexture(size)); | |
| 26 | |
| 27 GLuint texture_id = 0; | |
| 28 glGenTextures(1, &texture_id); | |
| 29 scoped_refptr<gfx::SurfaceTexture> surface_texture = | |
| 30 gfx::SurfaceTexture::Create(texture_id); | |
| 31 gfx::ScopedJavaSurface surface(surface_texture.get()); | |
| 32 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 33 ANativeWindow* native_window = | |
| 34 ANativeWindow_fromSurface(env, surface.j_surface().obj()); | |
| 35 ANativeWindow_setBuffersGeometry(native_window, size.width(), size.height(), | |
| 36 WINDOW_FORMAT_RGBA_8888); | |
| 37 ANativeWindow_Buffer buffer; | |
| 38 bool rv = ANativeWindow_lock(native_window, &buffer, nullptr); | |
| 39 EXPECT_TRUE(rv); | |
| 40 GLImageTestSupport::SetBufferDataToColor( | |
| 41 size.width(), size.height(), buffer.stride * 4, 0, | |
| 42 BufferFormat::RGBA_8888, color, static_cast<uint8_t*>(buffer.bits)); | |
| 43 ANativeWindow_unlockAndPost(native_window); | |
| 44 | |
| 45 rv = image->Initialize(surface_texture.get()); | |
| 46 EXPECT_TRUE(rv); | |
| 47 | |
| 48 return image; | |
| 49 } | |
| 50 }; | |
| 51 | |
| 52 INSTANTIATE_TYPED_TEST_CASE_P(GLImageSurfaceTexture, | |
| 53 GLImageTest, | |
| 54 GLImageSurfaceTextureTestDelegate); | |
| 55 | |
| 56 INSTANTIATE_TYPED_TEST_CASE_P(GLImageSurfaceTexture, | |
| 57 GLImageCopyTest, | |
| 58 GLImageSurfaceTextureTestDelegate); | |
| 59 | |
| 60 } // namespace | |
| 61 } // namespace gfx | |
| OLD | NEW |