Commit fd6c15f0 authored by Julien Isorce's avatar Julien Isorce Committed by Commit Bot

Add a gpu command buffer test for GL_OES_EGL_image extension

Also add some helpers to allow running the gl_tests with EGL / GLES2.

BUG=584248
TEST=gl_tests --gtest_filter=*GpuOESEGLImageTest.EGLImageToTexture*

Cq-Include-Trybots: master.tryserver.chromium.android:android_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel
Change-Id: I5177062eb7c28b59fc2684ef7fc665271b53c12d
Reviewed-on: https://chromium-review.googlesource.com/958908Reviewed-by: default avatarAntoine Labour <piman@chromium.org>
Reviewed-by: default avatarMiguel Casas <mcasas@chromium.org>
Commit-Queue: Miguel Casas <mcasas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543403}
parent b6e03254
...@@ -196,6 +196,7 @@ test("gl_tests") { ...@@ -196,6 +196,7 @@ test("gl_tests") {
"command_buffer/tests/gl_map_buffer_range_unittest.cc", "command_buffer/tests/gl_map_buffer_range_unittest.cc",
"command_buffer/tests/gl_native_gmb_backbuffer_unittest.cc", "command_buffer/tests/gl_native_gmb_backbuffer_unittest.cc",
"command_buffer/tests/gl_object_bindings_unittest.cc", "command_buffer/tests/gl_object_bindings_unittest.cc",
"command_buffer/tests/gl_oes_egl_image_unittest.cc",
"command_buffer/tests/gl_offscreen_surface_unittest.cc", "command_buffer/tests/gl_offscreen_surface_unittest.cc",
"command_buffer/tests/gl_oob_attrib_unittest.cc", "command_buffer/tests/gl_oob_attrib_unittest.cc",
"command_buffer/tests/gl_pointcoord_unittest.cc", "command_buffer/tests/gl_pointcoord_unittest.cc",
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "gpu/command_buffer/common/context_result.h" #include "gpu/command_buffer/common/context_result.h"
#include "gpu/command_buffer/service/async_api_interface.h" #include "gpu/command_buffer/service/async_api_interface.h"
#include "gpu/gpu_gles2_export.h" #include "gpu/gpu_gles2_export.h"
#include "ui/gfx/geometry/rect.h"
namespace gl { namespace gl {
class GLContext; class GLContext;
...@@ -149,6 +150,15 @@ class GPU_GLES2_EXPORT DecoderContext : public AsyncAPIInterface { ...@@ -149,6 +150,15 @@ class GPU_GLES2_EXPORT DecoderContext : public AsyncAPIInterface {
// Gets the texture object associated with the client ID. null is returned on // Gets the texture object associated with the client ID. null is returned on
// failure or if the texture has not been bound yet. // failure or if the texture has not been bound yet.
virtual TextureBase* GetTextureBase(uint32_t client_id) = 0; virtual TextureBase* GetTextureBase(uint32_t client_id) = 0;
virtual void SetLevelInfo(uint32_t client_id,
int level,
unsigned internal_format,
unsigned width,
unsigned height,
unsigned depth,
unsigned format,
unsigned type,
const gfx::Rect& cleared_rect) = 0;
virtual void BindImage(uint32_t client_texture_id, virtual void BindImage(uint32_t client_texture_id,
uint32_t texture_target, uint32_t texture_target,
gl::GLImage* image, gl::GLImage* image,
......
...@@ -546,6 +546,16 @@ TextureBase* GLES2Decoder::GetTextureBase(uint32_t client_id) { ...@@ -546,6 +546,16 @@ TextureBase* GLES2Decoder::GetTextureBase(uint32_t client_id) {
return nullptr; return nullptr;
} }
void GLES2Decoder::SetLevelInfo(uint32_t client_id,
int level,
unsigned internal_format,
unsigned width,
unsigned height,
unsigned depth,
unsigned format,
unsigned type,
const gfx::Rect& cleared_rect) {}
void GLES2Decoder::BeginDecoding() {} void GLES2Decoder::BeginDecoding() {}
void GLES2Decoder::EndDecoding() {} void GLES2Decoder::EndDecoding() {}
...@@ -681,6 +691,15 @@ class GLES2DecoderImpl : public GLES2Decoder, public ErrorStateClient { ...@@ -681,6 +691,15 @@ class GLES2DecoderImpl : public GLES2Decoder, public ErrorStateClient {
bool GetServiceTextureId(uint32_t client_texture_id, bool GetServiceTextureId(uint32_t client_texture_id,
uint32_t* service_texture_id) override; uint32_t* service_texture_id) override;
TextureBase* GetTextureBase(uint32_t client_id) override; TextureBase* GetTextureBase(uint32_t client_id) override;
void SetLevelInfo(uint32_t client_id,
int level,
unsigned internal_format,
unsigned width,
unsigned height,
unsigned depth,
unsigned format,
unsigned type,
const gfx::Rect& cleared_rect) override;
// Restores the current state to the user's settings. // Restores the current state to the user's settings.
void RestoreCurrentFramebufferBindings(); void RestoreCurrentFramebufferBindings();
...@@ -4970,6 +4989,21 @@ TextureBase* GLES2DecoderImpl::GetTextureBase(uint32_t client_id) { ...@@ -4970,6 +4989,21 @@ TextureBase* GLES2DecoderImpl::GetTextureBase(uint32_t client_id) {
return texture_ref ? texture_ref->texture() : nullptr; return texture_ref ? texture_ref->texture() : nullptr;
} }
void GLES2DecoderImpl::SetLevelInfo(uint32_t client_id,
int level,
unsigned internal_format,
unsigned width,
unsigned height,
unsigned depth,
unsigned format,
unsigned type,
const gfx::Rect& cleared_rect) {
TextureRef* texture_ref = texture_manager()->GetTexture(client_id);
texture_manager()->SetLevelInfo(texture_ref, texture_ref->texture()->target(),
level, internal_format, width, height, depth,
0 /* border */, format, type, cleared_rect);
}
void GLES2DecoderImpl::Destroy(bool have_context) { void GLES2DecoderImpl::Destroy(bool have_context) {
if (!initialized()) if (!initialized())
return; return;
......
...@@ -99,6 +99,15 @@ class GPU_GLES2_EXPORT GLES2Decoder : public CommonDecoder, ...@@ -99,6 +99,15 @@ class GPU_GLES2_EXPORT GLES2Decoder : public CommonDecoder,
// DecoderContext implementation. // DecoderContext implementation.
bool initialized() const override; bool initialized() const override;
TextureBase* GetTextureBase(uint32_t client_id) override; TextureBase* GetTextureBase(uint32_t client_id) override;
void SetLevelInfo(uint32_t client_id,
int level,
unsigned internal_format,
unsigned width,
unsigned height,
unsigned depth,
unsigned format,
unsigned type,
const gfx::Rect& cleared_rect) override;
void BeginDecoding() override; void BeginDecoding() override;
void EndDecoding() override; void EndDecoding() override;
base::StringPiece GetLogPrefix() override; base::StringPiece GetLogPrefix() override;
......
...@@ -100,6 +100,15 @@ class RasterDecoderImpl : public RasterDecoder, public gles2::ErrorStateClient { ...@@ -100,6 +100,15 @@ class RasterDecoderImpl : public RasterDecoder, public gles2::ErrorStateClient {
bool HasPollingWork() const override; bool HasPollingWork() const override;
void PerformPollingWork() override; void PerformPollingWork() override;
TextureBase* GetTextureBase(uint32_t client_id) override; TextureBase* GetTextureBase(uint32_t client_id) override;
void SetLevelInfo(uint32_t client_id,
int level,
unsigned internal_format,
unsigned width,
unsigned height,
unsigned depth,
unsigned format,
unsigned type,
const gfx::Rect& cleared_rect) override;
bool WasContextLost() const override; bool WasContextLost() const override;
bool WasContextLostByRobustnessExtension() const override; bool WasContextLostByRobustnessExtension() const override;
void MarkContextLost(error::ContextLostReason reason) override; void MarkContextLost(error::ContextLostReason reason) override;
...@@ -402,6 +411,16 @@ TextureBase* RasterDecoder::GetTextureBase(uint32_t client_id) { ...@@ -402,6 +411,16 @@ TextureBase* RasterDecoder::GetTextureBase(uint32_t client_id) {
return nullptr; return nullptr;
} }
void RasterDecoder::SetLevelInfo(uint32_t client_id,
int level,
unsigned internal_format,
unsigned width,
unsigned height,
unsigned depth,
unsigned format,
unsigned type,
const gfx::Rect& cleared_rect) {}
void RasterDecoder::BeginDecoding() {} void RasterDecoder::BeginDecoding() {}
void RasterDecoder::EndDecoding() {} void RasterDecoder::EndDecoding() {}
...@@ -643,6 +662,18 @@ TextureBase* RasterDecoderImpl::GetTextureBase(uint32_t client_id) { ...@@ -643,6 +662,18 @@ TextureBase* RasterDecoderImpl::GetTextureBase(uint32_t client_id) {
return nullptr; return nullptr;
} }
void RasterDecoderImpl::SetLevelInfo(uint32_t client_id,
int level,
unsigned internal_format,
unsigned width,
unsigned height,
unsigned depth,
unsigned format,
unsigned type,
const gfx::Rect& cleared_rect) {
NOTIMPLEMENTED();
}
bool RasterDecoderImpl::WasContextLost() const { bool RasterDecoderImpl::WasContextLost() const {
return false; return false;
} }
......
...@@ -37,6 +37,15 @@ class GPU_GLES2_EXPORT RasterDecoder : public DecoderContext, ...@@ -37,6 +37,15 @@ class GPU_GLES2_EXPORT RasterDecoder : public DecoderContext,
// DecoderContext implementation. // DecoderContext implementation.
bool initialized() const override; bool initialized() const override;
TextureBase* GetTextureBase(uint32_t client_id) override; TextureBase* GetTextureBase(uint32_t client_id) override;
void SetLevelInfo(uint32_t client_id,
int level,
unsigned internal_format,
unsigned width,
unsigned height,
unsigned depth,
unsigned format,
unsigned type,
const gfx::Rect& cleared_rect) override;
void BeginDecoding() override; void BeginDecoding() override;
void EndDecoding() override; void EndDecoding() override;
base::StringPiece GetLogPrefix() override; base::StringPiece GetLogPrefix() override;
......
...@@ -461,6 +461,7 @@ void GLManager::Destroy() { ...@@ -461,6 +461,7 @@ void GLManager::Destroy() {
decoder_->Destroy(have_context); decoder_->Destroy(have_context);
decoder_.reset(); decoder_.reset();
} }
context_ = nullptr;
} }
const GpuDriverBugWorkarounds& GLManager::workarounds() const { const GpuDriverBugWorkarounds& GLManager::workarounds() const {
......
// Copyright 2018 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 <GLES2/gl2.h>
#include "build/build_config.h"
#include "gpu/command_buffer/client/gles2_implementation.h"
#include "gpu/command_buffer/tests/gl_test_utils.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/buffer_format_util.h"
#include "ui/gl/gl_image.h"
#include "ui/gl/init/gl_factory.h"
#if defined(OS_LINUX)
#include "ui/gl/gl_image_native_pixmap.h"
#endif
#define SKIP_TEST_IF(cmd) \
do { \
if (cmd) { \
LOG(INFO) << "Skip test because " << #cmd; \
return; \
} \
} while (false)
namespace {
static const int kImageWidth = 64;
static const int kImageHeight = 64;
class GpuOESEGLImageTest : public testing::Test,
public gpu::GpuCommandBufferTestEGL {
protected:
void SetUp() override {
egl_gles2_initialized_ = InitializeEGLGLES2(kImageWidth, kImageHeight);
}
void TearDown() override { RestoreGLDefault(); }
bool egl_gles2_initialized_;
};
#if defined(OS_LINUX)
#define SHADER(Src) #Src
// clang-format off
const char kVertexShader[] =
SHADER(
attribute vec4 a_position;
varying vec2 v_texCoord;
void main() {
gl_Position = a_position;
v_texCoord = vec2((a_position.x + 1.0) * 0.5, (a_position.y + 1.0) * 0.5);
}
);
const char* kFragmentShader =
SHADER(
precision mediump float;
uniform sampler2D a_texture;
varying vec2 v_texCoord;
void main() {
gl_FragColor = texture2D(a_texture, v_texCoord);
}
);
// clang-format on
// The test verifies that the content of an EGLImage can be drawn. Indeed the
// test upload some colored pixels into a GL texture. Then it creates an
// EGLImage from this texture and binds this image to draw it into another
// GL texture. At the end the test downloads the pixels from the final GL
// texture and verifies that the colors match with the pixels uploaded into
// the initial GL texture.
TEST_F(GpuOESEGLImageTest, EGLImageToTexture) {
SKIP_TEST_IF(!egl_gles2_initialized_);
// This extension is required for creating an EGLImage from a GL texture.
SKIP_TEST_IF(!HasEGLExtension("EGL_KHR_image_base"));
// This extension is required to render an EGLImage into a GL texture.
SKIP_TEST_IF(!HasGLExtension("GL_OES_EGL_image"));
gfx::BufferFormat format = gfx::BufferFormat::RGBX_8888;
gfx::Size size(kImageWidth, kImageHeight);
size_t buffer_size = gfx::BufferSizeForBufferFormat(size, format);
uint8_t pixel[] = {128u, 92u, 45u, 255u};
size_t plane = 0;
uint32_t stride = gfx::RowSizeForBufferFormat(size.width(), format, plane);
std::unique_ptr<uint8_t[]> pixels(new uint8_t[buffer_size]);
// Assign a value to each pixel.
for (int y = 0; y < size.height(); ++y) {
uint8_t* line = static_cast<uint8_t*>(pixels.get()) + y * stride;
for (int x = 0; x < size.width() * 4; x += 4) {
line[x + 0] = pixel[0];
line[x + 1] = pixel[1];
line[x + 2] = pixel[2];
line[x + 3] = pixel[3];
}
}
// Create an EGLImage from a GL texture.
scoped_refptr<gl::GLImageNativePixmap> image =
CreateGLImageNativePixmap(format, size, pixels.get());
EXPECT_TRUE(image);
EXPECT_EQ(size, image->GetSize());
// Need a texture to bind the image.
GLuint texture_id = 0;
glGenTextures(1, &texture_id);
ASSERT_NE(0u, texture_id);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture_id);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
// Make sure the texture exists in the service side.
glFinish();
// Bind the image.
EXPECT_TRUE(image->BindTexImage(GL_TEXTURE_2D));
unsigned internal_format = image->GetInternalFormat();
gl_.decoder()->SetLevelInfo(
texture_id, 0 /* level */, internal_format, size.width(), size.height(),
1 /* depth */, internal_format, GL_UNSIGNED_BYTE, gfx::Rect(size));
gl_.decoder()->BindImage(texture_id, GL_TEXTURE_2D, image.get(),
true /* can_bind_to_sampler */);
// Build program, buffers and draw the texture.
GLuint vertex_shader =
gpu::GLTestHelper::LoadShader(GL_VERTEX_SHADER, kVertexShader);
GLuint fragment_shader =
gpu::GLTestHelper::LoadShader(GL_FRAGMENT_SHADER, kFragmentShader);
GLuint program =
gpu::GLTestHelper::SetupProgram(vertex_shader, fragment_shader);
ASSERT_NE(0u, program);
glUseProgram(program);
GLint sampler_location = glGetUniformLocation(program, "a_texture");
ASSERT_NE(-1, sampler_location);
glUniform1i(sampler_location, 0);
GLuint vbo = gpu::GLTestHelper::SetupUnitQuad(
glGetAttribLocation(program, "a_position"));
ASSERT_NE(0u, vbo);
glViewport(0, 0, kImageWidth, kImageHeight);
// Render the EGLImage into the GL texture.
glDrawArrays(GL_TRIANGLES, 0, 6);
ASSERT_TRUE(glGetError() == GL_NO_ERROR);
// Check if pixels match the values that were assigned to the mapped buffer.
gpu::GLTestHelper::CheckPixels(0, 0, kImageWidth, kImageHeight, 0, pixel,
nullptr);
EXPECT_TRUE(GL_NO_ERROR == glGetError());
// Release the image.
gl_.decoder()->BindImage(texture_id, GL_TEXTURE_2D, image.get(),
false /* can_bind_to_sampler */);
image->ReleaseTexImage(GL_TEXTURE_2D);
// Clean up.
glDeleteProgram(program);
glDeleteShader(vertex_shader);
glDeleteShader(fragment_shader);
glDeleteBuffers(1, &vbo);
glDeleteTextures(1, &texture_id);
}
#endif // defined(OS_LINUX)
} // namespace
...@@ -11,15 +11,63 @@ ...@@ -11,15 +11,63 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include "base/command_line.h"
#include "gpu/command_buffer/common/gles2_cmd_utils.h" #include "gpu/command_buffer/common/gles2_cmd_utils.h"
#include "gpu/config/gpu_driver_bug_workarounds.h"
#include "gpu/config/gpu_info_collector.h"
#include "gpu/config/gpu_util.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
#include "ui/gl/init/gl_factory.h"
#if defined(OS_LINUX)
#include "ui/gl/gl_image_native_pixmap.h"
#endif
namespace gpu {
// GCC requires these declarations, but MSVC requires they not be present. // GCC requires these declarations, but MSVC requires they not be present.
#ifndef COMPILER_MSVC #ifndef COMPILER_MSVC
const uint8_t GLTestHelper::kCheckClearValue; const uint8_t GLTestHelper::kCheckClearValue;
#endif #endif
bool GLTestHelper::InitializeGL(gl::GLImplementation gl_impl) {
if (gl_impl == gl::GLImplementation::kGLImplementationNone) {
if (!gl::init::InitializeGLNoExtensionsOneOff())
return false;
} else {
if (!gl::init::InitializeGLOneOffImplementation(
gl_impl,
false, // fallback_to_software_gl
false, // gpu_service_logging
false, // disable_gl_drawing
false // init_extensions
)) {
return false;
}
}
gpu::GPUInfo gpu_info;
gpu::CollectGraphicsInfoForTesting(&gpu_info);
gpu::GLManager::g_gpu_feature_info =
gpu::ComputeGpuFeatureInfo(gpu_info,
false, // ignore_gpu_blacklist
false, // disable_gpu_driver_bug_workarounds
false, // log_gpu_control_list_decisions
base::CommandLine::ForCurrentProcess(),
nullptr // needs_more_info
);
gl::init::SetDisabledExtensionsPlatform(
gpu::GLManager::g_gpu_feature_info.disabled_extensions);
return gl::init::InitializeExtensionSettingsOneOffPlatform();
}
bool GLTestHelper::InitializeGLDefault() {
return GLTestHelper::InitializeGL(
gl::GLImplementation::kGLImplementationNone);
}
bool GLTestHelper::HasExtension(const char* extension) { bool GLTestHelper::HasExtension(const char* extension) {
// Pad with an extra space to ensure that |extension| is not a substring of // Pad with an extra space to ensure that |extension| is not a substring of
// another extension. // another extension.
...@@ -311,3 +359,105 @@ void GLTestHelper::DrawTextureQuad(const GLenum texture_target, ...@@ -311,3 +359,105 @@ void GLTestHelper::DrawTextureQuad(const GLenum texture_target,
glDeleteProgram(program); glDeleteProgram(program);
glDeleteBuffers(1, &vertex_buffer); glDeleteBuffers(1, &vertex_buffer);
} }
GpuCommandBufferTestEGL::GpuCommandBufferTestEGL() : gl_reinitialized_(false) {}
GpuCommandBufferTestEGL::~GpuCommandBufferTestEGL() {}
bool GpuCommandBufferTestEGL::InitializeEGLGLES2(int width, int height) {
if (gl::GetGLImplementation() !=
gl::GLImplementation::kGLImplementationEGLGLES2) {
const auto impls = gl::init::GetAllowedGLImplementations();
if (std::find(impls.begin(), impls.end(),
gl::GLImplementation::kGLImplementationEGLGLES2) ==
impls.end()) {
LOG(INFO) << "Skip test, implementation EGLGLES2 is not available";
return false;
}
gl_reinitialized_ = true;
gl::init::ShutdownGL(false /* due_to_fallback */);
if (!GLTestHelper::InitializeGL(
gl::GLImplementation::kGLImplementationEGLGLES2)) {
LOG(INFO) << "Skip test, failed to initialize EGLGLES2";
return false;
}
}
DCHECK_EQ(gl::GLImplementation::kGLImplementationEGLGLES2,
gl::GetGLImplementation());
// Make the GL context current now to get all extensions.
GLManager::Options options;
options.size = gfx::Size(width, height);
gl_.Initialize(options);
gl_.MakeCurrent();
bool result =
gl::init::GetGLWindowSystemBindingInfo(&window_system_binding_info_);
DCHECK(result);
egl_extensions_ =
gl::MakeExtensionSet(window_system_binding_info_.extensions);
gl_extensions_ =
gl::MakeExtensionSet(gl::GetGLExtensionsFromCurrentContext());
return true;
}
void GpuCommandBufferTestEGL::RestoreGLDefault() {
gl_.Destroy();
if (gl_reinitialized_) {
gl::init::ShutdownGL(false /* due_to_fallback */);
GLTestHelper::InitializeGLDefault();
}
gl_reinitialized_ = false;
gl_extensions_.clear();
egl_extensions_.clear();
window_system_binding_info_ = gl::GLWindowSystemBindingInfo();
}
#if defined(OS_LINUX)
scoped_refptr<gl::GLImageNativePixmap>
GpuCommandBufferTestEGL::CreateGLImageNativePixmap(gfx::BufferFormat format,
gfx::Size size,
uint8_t* pixels) const {
// Upload raw pixels to a new GL texture.
GLuint tex_client_id = 0;
glGenTextures(1, &tex_client_id);
DCHECK_NE(0u, tex_client_id);
glBindTexture(GL_TEXTURE_2D, tex_client_id);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size.width(), size.height(), 0,
GL_RGBA, GL_UNSIGNED_BYTE, pixels);
// Make sure the texture exists in the service side.
glFinish();
// This works because the test run in a similar mode as In-Process-GPU.
unsigned int tex_service_id = 0;
gl_.decoder()->GetServiceTextureId(tex_client_id, &tex_service_id);
EXPECT_NE(0u, tex_service_id);
// Create an EGLImage from the real texture id.
scoped_refptr<gl::GLImageNativePixmap> image(new gl::GLImageNativePixmap(
size, gl::GLImageNativePixmap::GetInternalFormatForTesting(format)));
bool result = image->InitializeFromTexture(tex_service_id);
DCHECK(result);
// The test will own the EGLImage no need to keep a reference on the GL
// texture after returning from this function. This is covered by the
// EGL_KHR_image_base.txt specification, i.e. the underlying memory remains
// allocated as long as there is at least one sibling (like ref count).
glDeleteTextures(1, &tex_client_id);
return image;
}
#endif
} // namespace gpu
...@@ -12,10 +12,23 @@ ...@@ -12,10 +12,23 @@
#include <vector> #include <vector>
#include "build/build_config.h"
#include "gpu/command_buffer/tests/gl_manager.h"
#include "ui/gl/gl_implementation.h"
namespace gl {
class GLImageNativePixmap;
}
namespace gpu {
class GLTestHelper { class GLTestHelper {
public: public:
static const uint8_t kCheckClearValue = 123u; static const uint8_t kCheckClearValue = 123u;
static bool InitializeGL(gl::GLImplementation gl_impl);
static bool InitializeGLDefault();
static bool HasExtension(const char* extension); static bool HasExtension(const char* extension);
static bool CheckGLError(const char* msg, int line); static bool CheckGLError(const char* msg, int line);
...@@ -76,4 +89,45 @@ class GLTestHelper { ...@@ -76,4 +89,45 @@ class GLTestHelper {
const char* face_name); const char* face_name);
}; };
class GpuCommandBufferTestEGL {
public:
GpuCommandBufferTestEGL();
~GpuCommandBufferTestEGL();
// Reinitialize GL to the EGLGLES2 implementation if it is available and not
// the current initialized GL implementation. Return true on sucess, false
// otherwise.
bool InitializeEGLGLES2(int width, int height);
// Restore the default GL implementation.
void RestoreGLDefault();
// Returns whether the current context supports the named EGL extension.
bool HasEGLExtension(const base::StringPiece& extension) {
return gl::HasExtension(egl_extensions_, extension);
}
// Returns whether the current context supports the named GL extension.
bool HasGLExtension(const base::StringPiece& extension) {
return gl::HasExtension(gl_extensions_, extension);
}
#if defined(OS_LINUX)
// Create GLImageNativePixmap filled in with the given pixels.
scoped_refptr<gl::GLImageNativePixmap> CreateGLImageNativePixmap(
gfx::BufferFormat format,
gfx::Size size,
uint8_t* pixels) const;
#endif
protected:
bool gl_reinitialized_;
GLManager gl_;
gl::GLWindowSystemBindingInfo window_system_binding_info_;
gl::ExtensionSet egl_extensions_;
gl::ExtensionSet gl_extensions_;
};
} // namespace gpu
#endif // GPU_COMMAND_BUFFER_TESTS_GL_TEST_UTILS_H_ #endif // GPU_COMMAND_BUFFER_TESTS_GL_TEST_UTILS_H_
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
#include "base/at_exit.h" #include "base/at_exit.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/command_line.h"
#include "base/feature_list.h" #include "base/feature_list.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
...@@ -13,12 +12,8 @@ ...@@ -13,12 +12,8 @@
#include "base/test/launcher/unit_test_launcher.h" #include "base/test/launcher/unit_test_launcher.h"
#include "base/test/test_suite.h" #include "base/test/test_suite.h"
#include "gpu/command_buffer/client/gles2_lib.h" #include "gpu/command_buffer/client/gles2_lib.h"
#include "gpu/command_buffer/tests/gl_manager.h" #include "gpu/command_buffer/tests/gl_test_utils.h"
#include "gpu/config/gpu_driver_bug_workarounds.h"
#include "gpu/config/gpu_info_collector.h"
#include "gpu/config/gpu_util.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "ui/gl/init/gl_factory.h"
namespace { namespace {
...@@ -29,18 +24,7 @@ int RunHelper(base::TestSuite* testSuite) { ...@@ -29,18 +24,7 @@ int RunHelper(base::TestSuite* testSuite) {
base::MessageLoopForIO message_loop; base::MessageLoopForIO message_loop;
#endif #endif
base::FeatureList::InitializeInstance(std::string(), std::string()); base::FeatureList::InitializeInstance(std::string(), std::string());
gl::init::InitializeGLNoExtensionsOneOff(); gpu::GLTestHelper::InitializeGLDefault();
gpu::GPUInfo gpu_info;
gpu::CollectGraphicsInfoForTesting(&gpu_info);
gpu::GLManager::g_gpu_feature_info = gpu::ComputeGpuFeatureInfo(
gpu_info,
false, // ignore_gpu_blacklist
false, // disable_gpu_driver_bug_workarounds
false, // log_gpu_control_list_decisions
base::CommandLine::ForCurrentProcess(), nullptr);
gl::init::SetDisabledExtensionsPlatform(
gpu::GLManager::g_gpu_feature_info.disabled_extensions);
gl::init::InitializeExtensionSettingsOneOffPlatform();
::gles2::Initialize(); ::gles2::Initialize();
return testSuite->Run(); return testSuite->Run();
} }
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "ui/gfx/buffer_format_util.h" #include "ui/gfx/buffer_format_util.h"
#include "ui/gfx/client_native_pixmap.h" #include "ui/gfx/client_native_pixmap.h"
#include "ui/gfx/native_pixmap.h" #include "ui/gfx/native_pixmap.h"
#include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_image_native_pixmap.h" #include "ui/gl/gl_image_native_pixmap.h"
#if defined(USE_OZONE) #if defined(USE_OZONE)
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "ui/gfx/gpu_memory_buffer.h" #include "ui/gfx/gpu_memory_buffer.h"
#include "ui/gfx/linux/native_pixmap_dmabuf.h" #include "ui/gfx/linux/native_pixmap_dmabuf.h"
#include "ui/gfx/native_pixmap.h" #include "ui/gfx/native_pixmap.h"
#include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_image_native_pixmap.h" #include "ui/gl/gl_image_native_pixmap.h"
namespace media { namespace media {
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define UI_GL_GL_IMAGE_AHARDWAREBUFFER_H_ #define UI_GL_GL_IMAGE_AHARDWAREBUFFER_H_
#include "base/macros.h" #include "base/macros.h"
#include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_export.h" #include "ui/gl/gl_export.h"
#include "ui/gl/gl_image_egl.h" #include "ui/gl/gl_image_egl.h"
......
...@@ -5,9 +5,10 @@ ...@@ -5,9 +5,10 @@
#ifndef UI_GL_GL_IMAGE_EGL_H_ #ifndef UI_GL_GL_IMAGE_EGL_H_
#define UI_GL_GL_IMAGE_EGL_H_ #define UI_GL_GL_IMAGE_EGL_H_
#include <EGL/eglplatform.h>
#include "base/macros.h" #include "base/macros.h"
#include "base/threading/thread_checker.h" #include "base/threading/thread_checker.h"
#include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_export.h" #include "ui/gl/gl_export.h"
#include "ui/gl/gl_image.h" #include "ui/gl/gl_image.h"
...@@ -35,12 +36,12 @@ class GL_EXPORT GLImageEGL : public GLImage { ...@@ -35,12 +36,12 @@ class GL_EXPORT GLImageEGL : public GLImage {
// it is required to pass EGL_NO_CONTEXT. This allows to create an EGLImage // it is required to pass EGL_NO_CONTEXT. This allows to create an EGLImage
// from an external resource. Then this EGLImage can be converted to a GL // from an external resource. Then this EGLImage can be converted to a GL
// texture. // texture.
bool Initialize(EGLContext context, bool Initialize(void* context /* EGLContext */,
EGLenum target, unsigned target /* EGLenum */,
EGLClientBuffer buffer, void* buffer /* EGLClientBuffer */,
const EGLint* attrs); const EGLint* attrs);
EGLImageKHR egl_image_; void* egl_image_ /* EGLImageKHR */;
const gfx::Size size_; const gfx::Size size_;
base::ThreadChecker thread_checker_; base::ThreadChecker thread_checker_;
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "ui/gl/gl_image_native_pixmap.h" #include "ui/gl/gl_image_native_pixmap.h"
#include "ui/gl/gl_bindings.h"
#include "ui/gl/test/gl_image_test_template.h" #include "ui/gl/test/gl_image_test_template.h"
namespace gl { namespace gl {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment