Index: ui/gl/gl_image_surface_texture_unittest.cc |
diff --git a/ui/gl/gl_image_surface_texture_unittest.cc b/ui/gl/gl_image_surface_texture_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..4f43ddc3af88af1b0bd742191b48d5488beae399 |
--- /dev/null |
+++ b/ui/gl/gl_image_surface_texture_unittest.cc |
@@ -0,0 +1,60 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include <android/native_window.h> |
+#include <android/native_window_jni.h> |
+ |
+#include "base/android/jni_android.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+#include "ui/gfx/buffer_format_util.h" |
+#include "ui/gl/android/scoped_java_surface.h" |
+#include "ui/gl/android/surface_texture.h" |
+#include "ui/gl/gl_image_surface_texture.h" |
+#include "ui/gl/test/gl_image_test_template.h" |
+ |
+namespace gl { |
+namespace { |
+ |
+class GLImageSurfaceTextureTestDelegate { |
+ public: |
+ scoped_refptr<GLImage> CreateSolidColorImage(const gfx::Size& size, |
+ const uint8_t color[4]) const { |
+ scoped_refptr<GLImageSurfaceTexture> image(new GLImageSurfaceTexture(size)); |
+ |
+ GLuint texture_id = 0; |
+ glGenTextures(1, &texture_id); |
+ scoped_refptr<gfx::SurfaceTexture> surface_texture = |
+ gfx::SurfaceTexture::Create(texture_id); |
+ gfx::ScopedJavaSurface surface(surface_texture.get()); |
+ JNIEnv* env = base::android::AttachCurrentThread(); |
+ ANativeWindow* native_window = |
+ ANativeWindow_fromSurface(env, surface.j_surface().obj()); |
+ ANativeWindow_setBuffersGeometry(native_window, size.width(), size.height(), |
+ WINDOW_FORMAT_RGBA_8888); |
+ ANativeWindow_Buffer buffer; |
+ bool rv = ANativeWindow_lock(native_window, &buffer, nullptr); |
+ EXPECT_TRUE(rv); |
+ GLImageTestSupport::SetBufferDataToColor( |
+ size.width(), size.height(), buffer.stride * 4, 0, |
+ gfx::BufferFormat::RGBA_8888, color, |
+ static_cast<uint8_t*>(buffer.bits)); |
+ ANativeWindow_unlockAndPost(native_window); |
+ |
+ rv = image->Initialize(surface_texture.get()); |
+ EXPECT_TRUE(rv); |
+ |
+ return image; |
+ } |
+}; |
+ |
+INSTANTIATE_TYPED_TEST_CASE_P(GLImageSurfaceTexture, |
+ GLImageTest, |
+ GLImageSurfaceTextureTestDelegate); |
+ |
+INSTANTIATE_TYPED_TEST_CASE_P(GLImageSurfaceTexture, |
+ GLImageCopyTest, |
+ GLImageSurfaceTextureTestDelegate); |
+ |
+} // namespace |
+} // namespace gl |