summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorreveman <reveman@chromium.org>2015-10-22 09:43:06 -0700
committerCommit bot <commit-bot@chromium.org>2015-10-22 16:44:02 +0000
commitaa9e9d966688a7ef90fb12259b8e70ac7b6648d6 (patch)
tree68d1f5ae92f4c8b46e2af2a2432efdb952f878f9 /ui
parentc6da2801d9e36a9f2bb5acf4e3c492c8f0680ad4 (diff)
downloadchromium_src-aa9e9d966688a7ef90fb12259b8e70ac7b6648d6.zip
chromium_src-aa9e9d966688a7ef90fb12259b8e70ac7b6648d6.tar.gz
chromium_src-aa9e9d966688a7ef90fb12259b8e70ac7b6648d6.tar.bz2
Re-land: ui: Move GLImage::BindTexImage fallback from GLImage implementations to GLES2CmdDecoder.
This allows the GPU service to properly track the memory usage image backed textures. It also reduces the complexity of GLImage implementations significantly and makes it easier to support format and buffer types that require a copy or conversion of data to be used for sampling. This change also includes a few minor GLImage cleanups such as removing gfx:: namespace prefix in places where it's not needed and making the CopyTexImage GLImage test not part of the core GLImage tests as it's optional to support that function. BUG=526298 TEST=gl_tests --gtest_filter=GpuMemoryBuffer*, gpu_unittests, gl_unittests --gtest_filter=GLImage* Review URL: https://codereview.chromium.org/1401423003 Cr-Commit-Position: refs/heads/master@{#355552}
Diffstat (limited to 'ui')
-rw-r--r--ui/gl/BUILD.gn1
-rw-r--r--ui/gl/gl_image.h32
-rw-r--r--ui/gl/gl_image_egl.cc15
-rw-r--r--ui/gl/gl_image_egl.h13
-rw-r--r--ui/gl/gl_image_glx.cc52
-rw-r--r--ui/gl/gl_image_glx.h13
-rw-r--r--ui/gl/gl_image_io_surface.h23
-rw-r--r--ui/gl/gl_image_io_surface.mm28
-rw-r--r--ui/gl/gl_image_memory.cc224
-rw-r--r--ui/gl/gl_image_memory.h29
-rw-r--r--ui/gl/gl_image_ozone_native_pixmap.cc23
-rw-r--r--ui/gl/gl_image_ozone_native_pixmap.h2
-rw-r--r--ui/gl/gl_image_ref_counted_memory.cc15
-rw-r--r--ui/gl/gl_image_ref_counted_memory.h4
-rw-r--r--ui/gl/gl_image_ref_counted_memory_unittest.cc4
-rw-r--r--ui/gl/gl_image_shared_memory.cc29
-rw-r--r--ui/gl/gl_image_shared_memory.h9
-rw-r--r--ui/gl/gl_image_shared_memory_unittest.cc4
-rw-r--r--ui/gl/gl_image_stub.cc10
-rw-r--r--ui/gl/gl_image_stub.h9
-rw-r--r--ui/gl/gl_image_surface_texture.cc15
-rw-r--r--ui/gl/gl_image_surface_texture.h13
-rw-r--r--ui/gl/gl_tests.gyp1
-rw-r--r--ui/gl/test/gl_image_test_template.h62
24 files changed, 246 insertions, 384 deletions
diff --git a/ui/gl/BUILD.gn b/ui/gl/BUILD.gn
index bfd095b..2e04ee0 100644
--- a/ui/gl/BUILD.gn
+++ b/ui/gl/BUILD.gn
@@ -356,6 +356,7 @@ test("gl_unittests") {
"//testing/gmock",
"//testing/gtest",
"//ui/gfx",
+ "//ui/gfx/geometry",
]
data_deps = [
diff --git a/ui/gl/gl_image.h b/ui/gl/gl_image.h
index a236699..aba2651 100644
--- a/ui/gl/gl_image.h
+++ b/ui/gl/gl_image.h
@@ -5,6 +5,8 @@
#ifndef UI_GL_GL_IMAGE_H_
#define UI_GL_GL_IMAGE_H_
+#include <string>
+
#include "base/memory/ref_counted.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.h"
@@ -22,8 +24,8 @@ class ProcessMemoryDump;
namespace gfx {
-// Encapsulates an image that can be bound to a texture, hiding platform
-// specific management.
+// Encapsulates an image that can be bound and/or copied to a texture, hiding
+// platform specific management.
class GL_EXPORT GLImage : public base::RefCounted<GLImage> {
public:
GLImage() {}
@@ -32,36 +34,32 @@ class GL_EXPORT GLImage : public base::RefCounted<GLImage> {
virtual void Destroy(bool have_context) = 0;
// Get the size of the image.
- virtual gfx::Size GetSize() = 0;
+ virtual Size GetSize() = 0;
// Get the internal format of the image.
virtual unsigned GetInternalFormat() = 0;
- // Bind image to texture currently bound to |target|.
+ // Bind image to texture currently bound to |target|. Returns true on success.
+ // It is valid for an implementation to always return false.
virtual bool BindTexImage(unsigned target) = 0;
// Release image from texture currently bound to |target|.
virtual void ReleaseTexImage(unsigned target) = 0;
+ // Define texture currently bound to |target| by copying image into it.
+ // Returns true on success. It is valid for an implementation to always
+ // return false.
+ virtual bool CopyTexImage(unsigned target) = 0;
+
// Copy |rect| of image to |offset| in texture currently bound to |target|.
+ // Returns true on success. It is valid for an implementation to always
+ // return false.
virtual bool CopyTexSubImage(unsigned target,
const Point& offset,
const Rect& rect) = 0;
- // Called before the texture is used for drawing.
- virtual void WillUseTexImage() = 0;
-
- // Called after the texture has been used for drawing.
- virtual void DidUseTexImage() = 0;
-
- // Called before the texture image data will be modified.
- virtual void WillModifyTexImage() = 0;
-
- // Called after the texture image data has been modified.
- virtual void DidModifyTexImage() = 0;
-
// Schedule image as an overlay plane to be shown at swap time for |widget|.
- virtual bool ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
+ virtual bool ScheduleOverlayPlane(AcceleratedWidget widget,
int z_order,
OverlayTransform transform,
const Rect& bounds_rect,
diff --git a/ui/gl/gl_image_egl.cc b/ui/gl/gl_image_egl.cc
index 0ebd7cc..6f72c4f 100644
--- a/ui/gl/gl_image_egl.cc
+++ b/ui/gl/gl_image_egl.cc
@@ -9,9 +9,8 @@
namespace gfx {
-GLImageEGL::GLImageEGL(const gfx::Size& size)
- : egl_image_(EGL_NO_IMAGE_KHR), size_(size) {
-}
+GLImageEGL::GLImageEGL(const Size& size)
+ : egl_image_(EGL_NO_IMAGE_KHR), size_(size) {}
GLImageEGL::~GLImageEGL() {
DCHECK(thread_checker_.CalledOnValidThread());
@@ -49,7 +48,9 @@ void GLImageEGL::Destroy(bool have_context) {
}
}
-gfx::Size GLImageEGL::GetSize() { return size_; }
+Size GLImageEGL::GetSize() {
+ return size_;
+}
unsigned GLImageEGL::GetInternalFormat() { return GL_RGBA; }
@@ -61,13 +62,17 @@ bool GLImageEGL::BindTexImage(unsigned target) {
return true;
}
+bool GLImageEGL::CopyTexImage(unsigned target) {
+ return false;
+}
+
bool GLImageEGL::CopyTexSubImage(unsigned target,
const Point& offset,
const Rect& rect) {
return false;
}
-bool GLImageEGL::ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
+bool GLImageEGL::ScheduleOverlayPlane(AcceleratedWidget widget,
int z_order,
OverlayTransform transform,
const Rect& bounds_rect,
diff --git a/ui/gl/gl_image_egl.h b/ui/gl/gl_image_egl.h
index 14cc40b..4110fd0d 100644
--- a/ui/gl/gl_image_egl.h
+++ b/ui/gl/gl_image_egl.h
@@ -13,24 +13,21 @@ namespace gfx {
class GL_EXPORT GLImageEGL : public GLImage {
public:
- explicit GLImageEGL(const gfx::Size& size);
+ explicit GLImageEGL(const Size& size);
bool Initialize(EGLenum target, EGLClientBuffer buffer, const EGLint* attrs);
// Overridden from GLImage:
void Destroy(bool have_context) override;
- gfx::Size GetSize() override;
+ Size GetSize() override;
unsigned GetInternalFormat() override;
bool BindTexImage(unsigned target) override;
void ReleaseTexImage(unsigned target) override {}
+ bool CopyTexImage(unsigned target) override;
bool CopyTexSubImage(unsigned target,
const Point& offset,
const Rect& rect) override;
- void WillUseTexImage() override {}
- void DidUseTexImage() override {}
- void WillModifyTexImage() override {}
- void DidModifyTexImage() override {}
- bool ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
+ bool ScheduleOverlayPlane(AcceleratedWidget widget,
int z_order,
OverlayTransform transform,
const Rect& bounds_rect,
@@ -40,7 +37,7 @@ class GL_EXPORT GLImageEGL : public GLImage {
~GLImageEGL() override;
EGLImageKHR egl_image_;
- const gfx::Size size_;
+ const Size size_;
base::ThreadChecker thread_checker_;
private:
diff --git a/ui/gl/gl_image_glx.cc b/ui/gl/gl_image_glx.cc
index 496cf44..f2eddf9 100644
--- a/ui/gl/gl_image_glx.cc
+++ b/ui/gl/gl_image_glx.cc
@@ -13,7 +13,6 @@ extern "C" {
#include "ui/gl/gl_surface_glx.h"
namespace gfx {
-
namespace {
bool ValidFormat(unsigned internalformat) {
@@ -62,7 +61,7 @@ unsigned PixmapDepth(unsigned internalformat) {
}
}
-bool ActualPixmapGeometry(XID pixmap, gfx::Size* size, unsigned* depth) {
+bool ActualPixmapGeometry(XID pixmap, Size* size, unsigned* depth) {
XID root_return;
int x_return;
int y_return;
@@ -70,19 +69,13 @@ bool ActualPixmapGeometry(XID pixmap, gfx::Size* size, unsigned* depth) {
unsigned height_return;
unsigned border_width_return;
unsigned depth_return;
- if (!XGetGeometry(gfx::GetXDisplay(),
- pixmap,
- &root_return,
- &x_return,
- &y_return,
- &width_return,
- &height_return,
- &border_width_return,
+ if (!XGetGeometry(GetXDisplay(), pixmap, &root_return, &x_return, &y_return,
+ &width_return, &height_return, &border_width_return,
&depth_return))
return false;
if (size)
- *size = gfx::Size(width_return, height_return);
+ *size = Size(width_return, height_return);
if (depth)
*depth = depth_return;
return true;
@@ -96,19 +89,18 @@ unsigned ActualPixmapDepth(XID pixmap) {
return depth;
}
-gfx::Size ActualPixmapSize(XID pixmap) {
- gfx::Size size;
+Size ActualPixmapSize(XID pixmap) {
+ Size size;
if (!ActualPixmapGeometry(pixmap, &size, NULL))
- return gfx::Size();
+ return Size();
return size;
}
-} // namespace anonymous
+} // namespace
-GLImageGLX::GLImageGLX(const gfx::Size& size, unsigned internalformat)
- : glx_pixmap_(0), size_(size), internalformat_(internalformat) {
-}
+GLImageGLX::GLImageGLX(const Size& size, unsigned internalformat)
+ : glx_pixmap_(0), size_(size), internalformat_(internalformat) {}
GLImageGLX::~GLImageGLX() {
DCHECK_EQ(0u, glx_pixmap_);
@@ -134,8 +126,8 @@ bool GLImageGLX::Initialize(XID pixmap) {
BindToTextureFormat(internalformat_), GL_TRUE,
0};
int num_elements = 0;
- gfx::XScopedPtr<GLXFBConfig> config(
- glXChooseFBConfig(gfx::GetXDisplay(), DefaultScreen(gfx::GetXDisplay()),
+ XScopedPtr<GLXFBConfig> config(
+ glXChooseFBConfig(GetXDisplay(), DefaultScreen(GetXDisplay()),
config_attribs, &num_elements));
if (!config.get()) {
DVLOG(0) << "glXChooseFBConfig failed.";
@@ -149,8 +141,8 @@ bool GLImageGLX::Initialize(XID pixmap) {
int pixmap_attribs[] = {GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT,
GLX_TEXTURE_FORMAT_EXT,
TextureFormat(internalformat_), 0};
- glx_pixmap_ = glXCreatePixmap(
- gfx::GetXDisplay(), *config.get(), pixmap, pixmap_attribs);
+ glx_pixmap_ =
+ glXCreatePixmap(GetXDisplay(), *config.get(), pixmap, pixmap_attribs);
if (!glx_pixmap_) {
DVLOG(0) << "glXCreatePixmap failed.";
return false;
@@ -161,12 +153,14 @@ bool GLImageGLX::Initialize(XID pixmap) {
void GLImageGLX::Destroy(bool have_context) {
if (glx_pixmap_) {
- glXDestroyGLXPixmap(gfx::GetXDisplay(), glx_pixmap_);
+ glXDestroyGLXPixmap(GetXDisplay(), glx_pixmap_);
glx_pixmap_ = 0;
}
}
-gfx::Size GLImageGLX::GetSize() { return size_; }
+Size GLImageGLX::GetSize() {
+ return size_;
+}
unsigned GLImageGLX::GetInternalFormat() { return internalformat_; }
@@ -178,7 +172,7 @@ bool GLImageGLX::BindTexImage(unsigned target) {
if (target != GL_TEXTURE_2D)
return false;
- glXBindTexImageEXT(gfx::GetXDisplay(), glx_pixmap_, GLX_FRONT_LEFT_EXT, 0);
+ glXBindTexImageEXT(GetXDisplay(), glx_pixmap_, GLX_FRONT_LEFT_EXT, 0);
return true;
}
@@ -186,7 +180,11 @@ void GLImageGLX::ReleaseTexImage(unsigned target) {
DCHECK_NE(0u, glx_pixmap_);
DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), target);
- glXReleaseTexImageEXT(gfx::GetXDisplay(), glx_pixmap_, GLX_FRONT_LEFT_EXT);
+ glXReleaseTexImageEXT(GetXDisplay(), glx_pixmap_, GLX_FRONT_LEFT_EXT);
+}
+
+bool GLImageGLX::CopyTexImage(unsigned target) {
+ return false;
}
bool GLImageGLX::CopyTexSubImage(unsigned target,
@@ -195,7 +193,7 @@ bool GLImageGLX::CopyTexSubImage(unsigned target,
return false;
}
-bool GLImageGLX::ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
+bool GLImageGLX::ScheduleOverlayPlane(AcceleratedWidget widget,
int z_order,
OverlayTransform transform,
const Rect& bounds_rect,
diff --git a/ui/gl/gl_image_glx.h b/ui/gl/gl_image_glx.h
index 5de1d0d..e22512e 100644
--- a/ui/gl/gl_image_glx.h
+++ b/ui/gl/gl_image_glx.h
@@ -14,24 +14,21 @@ namespace gfx {
class GL_EXPORT GLImageGLX : public GLImage {
public:
- GLImageGLX(const gfx::Size& size, unsigned internalformat);
+ GLImageGLX(const Size& size, unsigned internalformat);
bool Initialize(XID pixmap);
// Overridden from GLImage:
void Destroy(bool have_context) override;
- gfx::Size GetSize() override;
+ Size GetSize() override;
unsigned GetInternalFormat() override;
bool BindTexImage(unsigned target) override;
void ReleaseTexImage(unsigned target) override;
+ bool CopyTexImage(unsigned target) override;
bool CopyTexSubImage(unsigned target,
const Point& offset,
const Rect& rect) override;
- void WillUseTexImage() override {}
- void DidUseTexImage() override {}
- void WillModifyTexImage() override {}
- void DidModifyTexImage() override {}
- bool ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
+ bool ScheduleOverlayPlane(AcceleratedWidget widget,
int z_order,
OverlayTransform transform,
const Rect& bounds_rect,
@@ -45,7 +42,7 @@ class GL_EXPORT GLImageGLX : public GLImage {
private:
XID glx_pixmap_;
- const gfx::Size size_;
+ const Size size_;
unsigned internalformat_;
DISALLOW_COPY_AND_ASSIGN(GLImageGLX);
diff --git a/ui/gl/gl_image_io_surface.h b/ui/gl/gl_image_io_surface.h
index 56b4478..45bd3ac 100644
--- a/ui/gl/gl_image_io_surface.h
+++ b/ui/gl/gl_image_io_surface.h
@@ -9,7 +9,8 @@
#include "base/mac/scoped_cftyperef.h"
#include "base/threading/thread_checker.h"
-#include "ui/gfx/gpu_memory_buffer.h"
+#include "ui/gfx/buffer_types.h"
+#include "ui/gfx/generic_shared_memory_id.h"
#include "ui/gl/gl_image.h"
#if defined(__OBJC__)
@@ -22,26 +23,23 @@ namespace gfx {
class GL_EXPORT GLImageIOSurface : public GLImage {
public:
- GLImageIOSurface(const gfx::Size& size, unsigned internalformat);
+ GLImageIOSurface(const Size& size, unsigned internalformat);
bool Initialize(IOSurfaceRef io_surface,
- gfx::GenericSharedMemoryId io_surface_id,
+ GenericSharedMemoryId io_surface_id,
BufferFormat format);
// Overridden from GLImage:
void Destroy(bool have_context) override;
- gfx::Size GetSize() override;
+ Size GetSize() override;
unsigned GetInternalFormat() override;
bool BindTexImage(unsigned target) override;
void ReleaseTexImage(unsigned target) override {}
+ bool CopyTexImage(unsigned target) override;
bool CopyTexSubImage(unsigned target,
const Point& offset,
const Rect& rect) override;
- void WillUseTexImage() override {}
- void DidUseTexImage() override {}
- void WillModifyTexImage() override {}
- void DidModifyTexImage() override {}
- bool ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
+ bool ScheduleOverlayPlane(AcceleratedWidget widget,
int z_order,
OverlayTransform transform,
const Rect& bounds_rect,
@@ -52,18 +50,17 @@ class GL_EXPORT GLImageIOSurface : public GLImage {
base::ScopedCFTypeRef<IOSurfaceRef> io_surface();
- static void SetLayerForWidget(gfx::AcceleratedWidget widget,
- CALayer* layer);
+ static void SetLayerForWidget(AcceleratedWidget widget, CALayer* layer);
protected:
~GLImageIOSurface() override;
private:
- const gfx::Size size_;
+ const Size size_;
const unsigned internalformat_;
BufferFormat format_;
base::ScopedCFTypeRef<IOSurfaceRef> io_surface_;
- gfx::GenericSharedMemoryId io_surface_id_;
+ GenericSharedMemoryId io_surface_id_;
base::ThreadChecker thread_checker_;
DISALLOW_COPY_AND_ASSIGN(GLImageIOSurface);
diff --git a/ui/gl/gl_image_io_surface.mm b/ui/gl/gl_image_io_surface.mm
index 3f4964e..4294298 100644
--- a/ui/gl/gl_image_io_surface.mm
+++ b/ui/gl/gl_image_io_surface.mm
@@ -8,6 +8,9 @@
#include "base/lazy_instance.h"
#include "base/mac/foundation_util.h"
+#include "base/trace_event/memory_allocator_dump.h"
+#include "base/trace_event/memory_dump_manager.h"
+#include "base/trace_event/process_memory_dump.h"
#include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_context.h"
@@ -18,7 +21,7 @@
namespace gfx {
namespace {
-typedef std::map<gfx::AcceleratedWidget,CALayer*> WidgetToLayerMap;
+using WidgetToLayerMap = std::map<AcceleratedWidget, CALayer*>;
base::LazyInstance<WidgetToLayerMap> g_widget_to_layer_map;
bool ValidInternalFormat(unsigned internalformat) {
@@ -138,8 +141,7 @@ GLenum DataType(BufferFormat format) {
} // namespace
-GLImageIOSurface::GLImageIOSurface(const gfx::Size& size,
- unsigned internalformat)
+GLImageIOSurface::GLImageIOSurface(const Size& size, unsigned internalformat)
: size_(size),
internalformat_(internalformat),
format_(BufferFormat::RGBA_8888) {}
@@ -150,7 +152,7 @@ GLImageIOSurface::~GLImageIOSurface() {
}
bool GLImageIOSurface::Initialize(IOSurfaceRef io_surface,
- gfx::GenericSharedMemoryId io_surface_id,
+ GenericSharedMemoryId io_surface_id,
BufferFormat format) {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(!io_surface_);
@@ -176,7 +178,9 @@ void GLImageIOSurface::Destroy(bool have_context) {
io_surface_.reset();
}
-gfx::Size GLImageIOSurface::GetSize() { return size_; }
+Size GLImageIOSurface::GetSize() {
+ return size_;
+}
unsigned GLImageIOSurface::GetInternalFormat() { return internalformat_; }
@@ -205,13 +209,17 @@ bool GLImageIOSurface::BindTexImage(unsigned target) {
return true;
}
+bool GLImageIOSurface::CopyTexImage(unsigned target) {
+ return false;
+}
+
bool GLImageIOSurface::CopyTexSubImage(unsigned target,
const Point& offset,
const Rect& rect) {
return false;
}
-bool GLImageIOSurface::ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
+bool GLImageIOSurface::ScheduleOverlayPlane(AcceleratedWidget widget,
int z_order,
OverlayTransform transform,
const Rect& bounds_rect,
@@ -233,8 +241,8 @@ void GLImageIOSurface::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd,
base::trace_event::MemoryAllocatorDump::kUnitsBytes,
static_cast<uint64_t>(size_bytes));
- auto guid = gfx::GetGenericSharedMemoryGUIDForTracing(process_tracing_id,
- io_surface_id_);
+ auto guid =
+ GetGenericSharedMemoryGUIDForTracing(process_tracing_id, io_surface_id_);
pmd->CreateSharedGlobalAllocatorDump(guid);
pmd->AddOwnershipEdge(dump->guid(), guid);
}
@@ -244,8 +252,8 @@ base::ScopedCFTypeRef<IOSurfaceRef> GLImageIOSurface::io_surface() {
}
// static
-void GLImageIOSurface::SetLayerForWidget(
- gfx::AcceleratedWidget widget, CALayer* layer) {
+void GLImageIOSurface::SetLayerForWidget(AcceleratedWidget widget,
+ CALayer* layer) {
if (layer)
g_widget_to_layer_map.Pointer()->insert(std::make_pair(widget, layer));
else
diff --git a/ui/gl/gl_image_memory.cc b/ui/gl/gl_image_memory.cc
index c91ad56..045c50c 100644
--- a/ui/gl/gl_image_memory.cc
+++ b/ui/gl/gl_image_memory.cc
@@ -7,12 +7,6 @@
#include "base/logging.h"
#include "base/trace_event/trace_event.h"
#include "ui/gl/gl_bindings.h"
-#include "ui/gl/scoped_binders.h"
-
-#if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \
- defined(USE_OZONE)
-#include "ui/gl/gl_surface_egl.h"
-#endif
namespace gfx {
namespace {
@@ -152,26 +146,11 @@ GLsizei SizeInBytes(const Size& size, BufferFormat format) {
GLImageMemory::GLImageMemory(const Size& size, unsigned internalformat)
: size_(size),
internalformat_(internalformat),
- memory_(NULL),
- format_(BufferFormat::RGBA_8888),
- in_use_(false),
- target_(0),
- need_do_bind_tex_image_(false)
-#if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \
- defined(USE_OZONE)
- ,
- egl_texture_id_(0u),
- egl_image_(EGL_NO_IMAGE_KHR)
-#endif
-{
-}
+ memory_(nullptr),
+ format_(BufferFormat::RGBA_8888) {}
GLImageMemory::~GLImageMemory() {
-#if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \
- defined(USE_OZONE)
- DCHECK_EQ(EGL_NO_IMAGE_KHR, egl_image_);
- DCHECK_EQ(0u, egl_texture_id_);
-#endif
+ DCHECK(!memory_);
}
// static
@@ -243,20 +222,7 @@ bool GLImageMemory::Initialize(const unsigned char* memory,
}
void GLImageMemory::Destroy(bool have_context) {
-#if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \
- defined(USE_OZONE)
- if (egl_image_ != EGL_NO_IMAGE_KHR) {
- eglDestroyImageKHR(GLSurfaceEGL::GetHardwareDisplay(), egl_image_);
- egl_image_ = EGL_NO_IMAGE_KHR;
- }
-
- if (egl_texture_id_) {
- if (have_context)
- glDeleteTextures(1, &egl_texture_id_);
- egl_texture_id_ = 0u;
- }
-#endif
- memory_ = NULL;
+ memory_ = nullptr;
}
Size GLImageMemory::GetSize() {
@@ -268,19 +234,27 @@ unsigned GLImageMemory::GetInternalFormat() {
}
bool GLImageMemory::BindTexImage(unsigned target) {
- if (target_ && target_ != target) {
- LOG(ERROR) << "GLImage can only be bound to one target";
+ return false;
+}
+
+bool GLImageMemory::CopyTexImage(unsigned target) {
+ TRACE_EVENT2("gpu", "GLImageMemory::CopyTexImage", "width", size_.width(),
+ "height", size_.height());
+
+ // GL_TEXTURE_EXTERNAL_OES is not a supported target.
+ if (target == GL_TEXTURE_EXTERNAL_OES)
return false;
- }
- target_ = target;
- // Defer DoBindTexImage if not currently in use.
- if (!in_use_) {
- need_do_bind_tex_image_ = true;
- return true;
+ if (IsCompressedFormat(format_)) {
+ glCompressedTexImage2D(target, 0, TextureFormat(format_), size_.width(),
+ size_.height(), 0, SizeInBytes(size_, format_),
+ memory_);
+ } else {
+ glTexImage2D(target, 0, TextureFormat(format_), size_.width(),
+ size_.height(), 0, DataFormat(format_), DataType(format_),
+ memory_);
}
- DoBindTexImage(target);
return true;
}
@@ -290,7 +264,7 @@ bool GLImageMemory::CopyTexSubImage(unsigned target,
TRACE_EVENT2("gpu", "GLImageMemory::CopyTexSubImage", "width", rect.width(),
"height", rect.height());
- // GL_TEXTURE_EXTERNAL_OES is not a supported CopyTexSubImage target.
+ // GL_TEXTURE_EXTERNAL_OES is not a supported target.
if (target == GL_TEXTURE_EXTERNAL_OES)
return false;
@@ -308,36 +282,18 @@ bool GLImageMemory::CopyTexSubImage(unsigned target,
DCHECK(memory_);
const unsigned char* data = memory_ + rect.y() * stride_in_bytes;
if (IsCompressedFormat(format_)) {
- glCompressedTexSubImage2D(target,
- 0, // level
- offset.x(), offset.y(), rect.width(),
+ glCompressedTexSubImage2D(target, 0, offset.x(), offset.y(), rect.width(),
rect.height(), DataFormat(format_),
SizeInBytes(rect.size(), format_), data);
} else {
- glTexSubImage2D(target, 0, // level
- offset.x(), offset.y(), rect.width(), rect.height(),
- DataFormat(format_), DataType(format_), data);
+ glTexSubImage2D(target, 0, offset.x(), offset.y(), rect.width(),
+ rect.height(), DataFormat(format_), DataType(format_),
+ data);
}
return true;
}
-void GLImageMemory::WillUseTexImage() {
- DCHECK(!in_use_);
- in_use_ = true;
-
- if (!need_do_bind_tex_image_)
- return;
-
- DCHECK(target_);
- DoBindTexImage(target_);
-}
-
-void GLImageMemory::DidUseTexImage() {
- DCHECK(in_use_);
- in_use_ = false;
-}
-
bool GLImageMemory::ScheduleOverlayPlane(AcceleratedWidget widget,
int z_order,
OverlayTransform transform,
@@ -346,132 +302,4 @@ bool GLImageMemory::ScheduleOverlayPlane(AcceleratedWidget widget,
return false;
}
-void GLImageMemory::DoBindTexImage(unsigned target) {
- TRACE_EVENT0("gpu", "GLImageMemory::DoBindTexImage");
-
- DCHECK(need_do_bind_tex_image_);
- need_do_bind_tex_image_ = false;
-
- DCHECK(memory_);
-#if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \
- defined(USE_OZONE)
- if (target == GL_TEXTURE_EXTERNAL_OES) {
- if (egl_image_ == EGL_NO_IMAGE_KHR) {
- DCHECK_EQ(0u, egl_texture_id_);
- glGenTextures(1, &egl_texture_id_);
-
- {
- ScopedTextureBinder texture_binder(GL_TEXTURE_2D, egl_texture_id_);
-
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- if (IsCompressedFormat(format_)) {
- glCompressedTexImage2D(GL_TEXTURE_2D,
- 0, // mip level
- TextureFormat(format_), size_.width(),
- size_.height(),
- 0, // border
- SizeInBytes(size_, format_), memory_);
- } else {
- glTexImage2D(GL_TEXTURE_2D,
- 0, // mip level
- TextureFormat(format_),
- size_.width(),
- size_.height(),
- 0, // border
- DataFormat(format_),
- DataType(format_),
- memory_);
- }
- }
-
- EGLint attrs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE};
- // Need to pass current EGL rendering context to eglCreateImageKHR for
- // target type EGL_GL_TEXTURE_2D_KHR.
- egl_image_ =
- eglCreateImageKHR(GLSurfaceEGL::GetHardwareDisplay(),
- eglGetCurrentContext(),
- EGL_GL_TEXTURE_2D_KHR,
- reinterpret_cast<EGLClientBuffer>(egl_texture_id_),
- attrs);
- DCHECK_NE(EGL_NO_IMAGE_KHR, egl_image_)
- << "Error creating EGLImage: " << eglGetError();
- } else {
- ScopedTextureBinder texture_binder(GL_TEXTURE_2D, egl_texture_id_);
-
- if (IsCompressedFormat(format_)) {
- glCompressedTexSubImage2D(GL_TEXTURE_2D,
- 0, // mip level
- 0, // x-offset
- 0, // y-offset
- size_.width(), size_.height(),
- DataFormat(format_),
- SizeInBytes(size_, format_), memory_);
- } else {
- glTexSubImage2D(GL_TEXTURE_2D,
- 0, // mip level
- 0, // x-offset
- 0, // y-offset
- size_.width(),
- size_.height(),
- DataFormat(format_),
- DataType(format_),
- memory_);
- }
- }
-
- glEGLImageTargetTexture2DOES(target, egl_image_);
- DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
- return;
- }
-#endif
-
- DCHECK_NE(static_cast<GLenum>(GL_TEXTURE_EXTERNAL_OES), target);
- if (IsCompressedFormat(format_)) {
- glCompressedTexImage2D(target,
- 0, // mip level
- TextureFormat(format_), size_.width(),
- size_.height(),
- 0, // border
- SizeInBytes(size_, format_), memory_);
- } else {
- glTexImage2D(target,
- 0, // mip level
- TextureFormat(format_),
- size_.width(),
- size_.height(),
- 0, // border
- DataFormat(format_),
- DataType(format_),
- memory_);
- }
-}
-
-void GLImageMemory::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd,
- uint64_t process_tracing_id,
- const std::string& dump_name) {
- // Note that the following calculation does not consider whether this GLImage
- // has been un-bound from a texture. It also relies on this GLImage only ever
- // being bound to a single texture. We could check these conditions more
- // thoroughly, but at the cost of extra GL queries.
- bool is_bound_to_texture = target_ && !need_do_bind_tex_image_;
-
-#if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \
- defined(USE_OZONE)
- is_bound_to_texture |= !!egl_texture_id_;
-#endif
-
- size_t size_in_bytes = is_bound_to_texture ? SizeInBytes(size_, format_) : 0;
-
- base::trace_event::MemoryAllocatorDump* dump =
- pmd->CreateAllocatorDump(dump_name + "/texture_memory");
- dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
- base::trace_event::MemoryAllocatorDump::kUnitsBytes,
- static_cast<uint64_t>(size_in_bytes));
-
- // No need for a global shared edge here. This object in the GPU process is
- // the sole owner of this texture id.
-}
-
} // namespace gfx
diff --git a/ui/gl/gl_image_memory.h b/ui/gl/gl_image_memory.h
index 10b1a3b..4f1fe04 100644
--- a/ui/gl/gl_image_memory.h
+++ b/ui/gl/gl_image_memory.h
@@ -7,14 +7,8 @@
#include "ui/gl/gl_image.h"
-#if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \
- defined(USE_OZONE)
-#include <EGL/egl.h>
-#include <EGL/eglext.h>
-#endif
-
#include "base/numerics/safe_math.h"
-#include "ui/gfx/gpu_memory_buffer.h"
+#include "ui/gfx/buffer_types.h"
namespace gfx {
@@ -34,45 +28,26 @@ class GL_EXPORT GLImageMemory : public GLImage {
unsigned GetInternalFormat() override;
bool BindTexImage(unsigned target) override;
void ReleaseTexImage(unsigned target) override {}
+ bool CopyTexImage(unsigned target) override;
bool CopyTexSubImage(unsigned target,
const Point& offset,
const Rect& rect) override;
- void WillUseTexImage() override;
- void DidUseTexImage() override;
- void WillModifyTexImage() override {}
- void DidModifyTexImage() override {}
bool ScheduleOverlayPlane(AcceleratedWidget widget,
int z_order,
OverlayTransform transform,
const Rect& bounds_rect,
const RectF& crop_rect) override;
- // Only dumps the GLTexture portion of the memory usage. Subclasses are
- // responsible for dumping the CPU-side memory.
- void OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd,
- uint64_t process_tracing_id,
- const std::string& dump_name) override;
-
protected:
~GLImageMemory() override;
BufferFormat format() const { return format_; }
private:
- void DoBindTexImage(unsigned target);
-
const Size size_;
const unsigned internalformat_;
const unsigned char* memory_;
BufferFormat format_;
- bool in_use_;
- unsigned target_;
- bool need_do_bind_tex_image_;
-#if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \
- defined(USE_OZONE)
- unsigned egl_texture_id_;
- EGLImageKHR egl_image_;
-#endif
DISALLOW_COPY_AND_ASSIGN(GLImageMemory);
};
diff --git a/ui/gl/gl_image_ozone_native_pixmap.cc b/ui/gl/gl_image_ozone_native_pixmap.cc
index 3e0cfb5..e0d0e37 100644
--- a/ui/gl/gl_image_ozone_native_pixmap.cc
+++ b/ui/gl/gl_image_ozone_native_pixmap.cc
@@ -26,7 +26,7 @@ bool ValidInternalFormat(unsigned internalformat) {
}
}
-bool ValidFormat(gfx::BufferFormat format) {
+bool ValidFormat(BufferFormat format) {
switch (format) {
case BufferFormat::RGBA_8888:
case BufferFormat::BGRA_8888:
@@ -49,7 +49,7 @@ bool ValidFormat(gfx::BufferFormat format) {
return false;
}
-EGLint FourCC(gfx::BufferFormat format) {
+EGLint FourCC(BufferFormat format) {
switch (format) {
case BufferFormat::RGBA_8888:
return DRM_FORMAT_ABGR8888;
@@ -87,12 +87,12 @@ GLImageOzoneNativePixmap::~GLImageOzoneNativePixmap() {
bool GLImageOzoneNativePixmap::Initialize(ui::NativePixmap* pixmap,
BufferFormat format) {
DCHECK(!pixmap_);
-
- bool result = true;
if (pixmap->GetEGLClientBuffer()) {
EGLint attrs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE};
- result = GLImageEGL::Initialize(EGL_NATIVE_PIXMAP_KHR,
- pixmap->GetEGLClientBuffer(), attrs);
+ if (!GLImageEGL::Initialize(EGL_NATIVE_PIXMAP_KHR,
+ pixmap->GetEGLClientBuffer(), attrs)) {
+ return false;
+ }
} else if (pixmap->GetDmaBufFd() >= 0) {
if (!ValidInternalFormat(internalformat_)) {
LOG(ERROR) << "Invalid internalformat: " << internalformat_;
@@ -119,13 +119,14 @@ bool GLImageOzoneNativePixmap::Initialize(ui::NativePixmap* pixmap,
EGL_DMA_BUF_PLANE0_PITCH_EXT,
pixmap->GetDmaBufPitch(),
EGL_NONE};
- result = GLImageEGL::Initialize(
- EGL_LINUX_DMA_BUF_EXT, static_cast<EGLClientBuffer>(nullptr), attrs);
+ if (!GLImageEGL::Initialize(EGL_LINUX_DMA_BUF_EXT,
+ static_cast<EGLClientBuffer>(nullptr), attrs)) {
+ return false;
+ }
}
- if (result)
- pixmap_ = pixmap;
- return result;
+ pixmap_ = pixmap;
+ return true;
}
unsigned GLImageOzoneNativePixmap::GetInternalFormat() {
diff --git a/ui/gl/gl_image_ozone_native_pixmap.h b/ui/gl/gl_image_ozone_native_pixmap.h
index e164f39..6505299 100644
--- a/ui/gl/gl_image_ozone_native_pixmap.h
+++ b/ui/gl/gl_image_ozone_native_pixmap.h
@@ -5,7 +5,7 @@
#ifndef UI_GL_GL_IMAGE_OZONE_NATIVE_PIXMAP_H_
#define UI_GL_GL_IMAGE_OZONE_NATIVE_PIXMAP_H_
-#include "ui/gfx/gpu_memory_buffer.h"
+#include "ui/gfx/buffer_types.h"
#include "ui/gl/gl_image_egl.h"
#include "ui/ozone/public/native_pixmap.h"
diff --git a/ui/gl/gl_image_ref_counted_memory.cc b/ui/gl/gl_image_ref_counted_memory.cc
index 7aadd24..6533568 100644
--- a/ui/gl/gl_image_ref_counted_memory.cc
+++ b/ui/gl/gl_image_ref_counted_memory.cc
@@ -6,13 +6,15 @@
#include "base/logging.h"
#include "base/memory/ref_counted_memory.h"
+#include "base/trace_event/memory_allocator_dump.h"
+#include "base/trace_event/memory_dump_manager.h"
+#include "base/trace_event/process_memory_dump.h"
namespace gfx {
-GLImageRefCountedMemory::GLImageRefCountedMemory(const gfx::Size& size,
+GLImageRefCountedMemory::GLImageRefCountedMemory(const Size& size,
unsigned internalformat)
- : GLImageMemory(size, internalformat) {
-}
+ : GLImageMemory(size, internalformat) {}
GLImageRefCountedMemory::~GLImageRefCountedMemory() {
DCHECK(!ref_counted_memory_.get());
@@ -20,7 +22,7 @@ GLImageRefCountedMemory::~GLImageRefCountedMemory() {
bool GLImageRefCountedMemory::Initialize(
base::RefCountedMemory* ref_counted_memory,
- gfx::BufferFormat format) {
+ BufferFormat format) {
if (!GLImageMemory::Initialize(ref_counted_memory->front(), format))
return false;
@@ -31,7 +33,7 @@ bool GLImageRefCountedMemory::Initialize(
void GLImageRefCountedMemory::Destroy(bool have_context) {
GLImageMemory::Destroy(have_context);
- ref_counted_memory_ = NULL;
+ ref_counted_memory_ = nullptr;
}
void GLImageRefCountedMemory::OnMemoryDump(
@@ -52,9 +54,6 @@ void GLImageRefCountedMemory::OnMemoryDump(
pmd->AddSuballocation(dump->guid(),
base::trace_event::MemoryDumpManager::GetInstance()
->system_allocator_pool_name());
-
- // Also dump the base class's texture memory.
- GLImageMemory::OnMemoryDump(pmd, process_tracing_id, dump_name);
}
} // namespace gfx
diff --git a/ui/gl/gl_image_ref_counted_memory.h b/ui/gl/gl_image_ref_counted_memory.h
index db07954..f68acc5 100644
--- a/ui/gl/gl_image_ref_counted_memory.h
+++ b/ui/gl/gl_image_ref_counted_memory.h
@@ -16,10 +16,10 @@ namespace gfx {
class GL_EXPORT GLImageRefCountedMemory : public GLImageMemory {
public:
- GLImageRefCountedMemory(const gfx::Size& size, unsigned internalformat);
+ GLImageRefCountedMemory(const Size& size, unsigned internalformat);
bool Initialize(base::RefCountedMemory* ref_counted_memory,
- gfx::BufferFormat format);
+ BufferFormat format);
// Overridden from GLImage:
void Destroy(bool have_context) override;
diff --git a/ui/gl/gl_image_ref_counted_memory_unittest.cc b/ui/gl/gl_image_ref_counted_memory_unittest.cc
index 1edccf2..c3d77e2 100644
--- a/ui/gl/gl_image_ref_counted_memory_unittest.cc
+++ b/ui/gl/gl_image_ref_counted_memory_unittest.cc
@@ -37,5 +37,9 @@ INSTANTIATE_TYPED_TEST_CASE_P(GLImageRefCountedMemory,
GLImageTest,
GLImageRefCountedMemoryTestDelegate);
+INSTANTIATE_TYPED_TEST_CASE_P(GLImageRefCountedMemory,
+ GLImageCopyTest,
+ GLImageRefCountedMemoryTestDelegate);
+
} // namespace
} // namespace gfx
diff --git a/ui/gl/gl_image_shared_memory.cc b/ui/gl/gl_image_shared_memory.cc
index 16ec6cb..6ca7905 100644
--- a/ui/gl/gl_image_shared_memory.cc
+++ b/ui/gl/gl_image_shared_memory.cc
@@ -5,16 +5,18 @@
#include "ui/gl/gl_image_shared_memory.h"
#include "base/logging.h"
+#include "base/memory/shared_memory.h"
#include "base/numerics/safe_math.h"
#include "base/process/process_handle.h"
+#include "base/trace_event/memory_allocator_dump.h"
+#include "base/trace_event/memory_dump_manager.h"
+#include "base/trace_event/process_memory_dump.h"
namespace gfx {
namespace {
// Returns true if the size is valid and false otherwise.
-bool SizeInBytes(const gfx::Size& size,
- gfx::BufferFormat format,
- size_t* size_in_bytes) {
+bool SizeInBytes(const Size& size, BufferFormat format, size_t* size_in_bytes) {
if (size.IsEmpty())
return false;
@@ -31,19 +33,17 @@ bool SizeInBytes(const gfx::Size& size,
} // namespace
-GLImageSharedMemory::GLImageSharedMemory(const gfx::Size& size,
+GLImageSharedMemory::GLImageSharedMemory(const Size& size,
unsigned internalformat)
- : GLImageMemory(size, internalformat) {
-}
+ : GLImageMemory(size, internalformat) {}
GLImageSharedMemory::~GLImageSharedMemory() {
DCHECK(!shared_memory_);
}
-bool GLImageSharedMemory::Initialize(
- const base::SharedMemoryHandle& handle,
- gfx::GenericSharedMemoryId shared_memory_id,
- gfx::BufferFormat format) {
+bool GLImageSharedMemory::Initialize(const base::SharedMemoryHandle& handle,
+ GenericSharedMemoryId shared_memory_id,
+ BufferFormat format) {
size_t size_in_bytes;
if (!SizeInBytes(GetSize(), format, &size_in_bytes))
return false;
@@ -98,18 +98,15 @@ void GLImageSharedMemory::OnMemoryDump(
// Dump under "/shared_memory", as the base class may also dump to
// "/texture_memory".
base::trace_event::MemoryAllocatorDump* dump =
- pmd->CreateAllocatorDump(dump_name + "/private_memory");
+ pmd->CreateAllocatorDump(dump_name + "/shared_memory");
dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
base::trace_event::MemoryAllocatorDump::kUnitsBytes,
static_cast<uint64_t>(size_in_bytes));
- auto guid = gfx::GetGenericSharedMemoryGUIDForTracing(process_tracing_id,
- shared_memory_id_);
+ auto guid = GetGenericSharedMemoryGUIDForTracing(process_tracing_id,
+ shared_memory_id_);
pmd->CreateSharedGlobalAllocatorDump(guid);
pmd->AddOwnershipEdge(dump->guid(), guid);
-
- // Also dump the base class's texture memory.
- GLImageMemory::OnMemoryDump(pmd, process_tracing_id, dump_name);
}
} // namespace gfx
diff --git a/ui/gl/gl_image_shared_memory.h b/ui/gl/gl_image_shared_memory.h
index 622eb3d..2e6374b5 100644
--- a/ui/gl/gl_image_shared_memory.h
+++ b/ui/gl/gl_image_shared_memory.h
@@ -7,16 +7,21 @@
#include "base/memory/scoped_ptr.h"
#include "base/memory/shared_memory_handle.h"
+#include "ui/gfx/generic_shared_memory_id.h"
#include "ui/gl/gl_image_memory.h"
+namespace base {
+class SharedMemory;
+}
+
namespace gfx {
class GL_EXPORT GLImageSharedMemory : public GLImageMemory {
public:
- GLImageSharedMemory(const gfx::Size& size, unsigned internalformat);
+ GLImageSharedMemory(const Size& size, unsigned internalformat);
bool Initialize(const base::SharedMemoryHandle& handle,
- gfx::GenericSharedMemoryId shared_memory_id,
+ GenericSharedMemoryId shared_memory_id,
BufferFormat format);
// Overridden from GLImage:
diff --git a/ui/gl/gl_image_shared_memory_unittest.cc b/ui/gl/gl_image_shared_memory_unittest.cc
index 44c8e97..9c280f9 100644
--- a/ui/gl/gl_image_shared_memory_unittest.cc
+++ b/ui/gl/gl_image_shared_memory_unittest.cc
@@ -39,5 +39,9 @@ INSTANTIATE_TYPED_TEST_CASE_P(GLImageSharedMemory,
GLImageTest,
GLImageSharedMemoryTestDelegate);
+INSTANTIATE_TYPED_TEST_CASE_P(GLImageSharedMemory,
+ GLImageCopyTest,
+ GLImageSharedMemoryTestDelegate);
+
} // namespace
} // namespace gfx
diff --git a/ui/gl/gl_image_stub.cc b/ui/gl/gl_image_stub.cc
index afbf6e0..803a05f 100644
--- a/ui/gl/gl_image_stub.cc
+++ b/ui/gl/gl_image_stub.cc
@@ -12,19 +12,25 @@ GLImageStub::GLImageStub() {}
GLImageStub::~GLImageStub() {}
-gfx::Size GLImageStub::GetSize() { return gfx::Size(1, 1); }
+Size GLImageStub::GetSize() {
+ return Size(1, 1);
+}
unsigned GLImageStub::GetInternalFormat() { return GL_RGBA; }
bool GLImageStub::BindTexImage(unsigned target) { return true; }
+bool GLImageStub::CopyTexImage(unsigned target) {
+ return true;
+}
+
bool GLImageStub::CopyTexSubImage(unsigned target,
const Point& offset,
const Rect& rect) {
return true;
}
-bool GLImageStub::ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
+bool GLImageStub::ScheduleOverlayPlane(AcceleratedWidget widget,
int z_order,
OverlayTransform transform,
const Rect& bounds_rect,
diff --git a/ui/gl/gl_image_stub.h b/ui/gl/gl_image_stub.h
index be31bff..c95fda9 100644
--- a/ui/gl/gl_image_stub.h
+++ b/ui/gl/gl_image_stub.h
@@ -16,18 +16,15 @@ class GL_EXPORT GLImageStub : public GLImage {
// Overridden from GLImage:
void Destroy(bool have_context) override {}
- gfx::Size GetSize() override;
+ Size GetSize() override;
unsigned GetInternalFormat() override;
bool BindTexImage(unsigned target) override;
void ReleaseTexImage(unsigned target) override {}
+ bool CopyTexImage(unsigned target) override;
bool CopyTexSubImage(unsigned target,
const Point& offset,
const Rect& rect) override;
- void WillUseTexImage() override {}
- void DidUseTexImage() override {}
- void WillModifyTexImage() override {}
- void DidModifyTexImage() override {}
- bool ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
+ bool ScheduleOverlayPlane(AcceleratedWidget widget,
int z_order,
OverlayTransform transform,
const Rect& bounds_rect,
diff --git a/ui/gl/gl_image_surface_texture.cc b/ui/gl/gl_image_surface_texture.cc
index 910551d..6ad3667 100644
--- a/ui/gl/gl_image_surface_texture.cc
+++ b/ui/gl/gl_image_surface_texture.cc
@@ -9,9 +9,8 @@
namespace gfx {
-GLImageSurfaceTexture::GLImageSurfaceTexture(const gfx::Size& size)
- : size_(size), texture_id_(0) {
-}
+GLImageSurfaceTexture::GLImageSurfaceTexture(const Size& size)
+ : size_(size), texture_id_(0) {}
GLImageSurfaceTexture::~GLImageSurfaceTexture() {
DCHECK(thread_checker_.CalledOnValidThread());
@@ -32,7 +31,9 @@ void GLImageSurfaceTexture::Destroy(bool have_context) {
texture_id_ = 0;
}
-gfx::Size GLImageSurfaceTexture::GetSize() { return size_; }
+Size GLImageSurfaceTexture::GetSize() {
+ return size_;
+}
unsigned GLImageSurfaceTexture::GetInternalFormat() { return GL_RGBA; }
@@ -78,13 +79,17 @@ bool GLImageSurfaceTexture::BindTexImage(unsigned target) {
return true;
}
+bool GLImageSurfaceTexture::CopyTexImage(unsigned target) {
+ return false;
+}
+
bool GLImageSurfaceTexture::CopyTexSubImage(unsigned target,
const Point& offset,
const Rect& rect) {
return false;
}
-bool GLImageSurfaceTexture::ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
+bool GLImageSurfaceTexture::ScheduleOverlayPlane(AcceleratedWidget widget,
int z_order,
OverlayTransform transform,
const Rect& bounds_rect,
diff --git a/ui/gl/gl_image_surface_texture.h b/ui/gl/gl_image_surface_texture.h
index d8c4abb..f18eaa2 100644
--- a/ui/gl/gl_image_surface_texture.h
+++ b/ui/gl/gl_image_surface_texture.h
@@ -15,24 +15,21 @@ class SurfaceTexture;
class GL_EXPORT GLImageSurfaceTexture : public GLImage {
public:
- explicit GLImageSurfaceTexture(const gfx::Size& size);
+ explicit GLImageSurfaceTexture(const Size& size);
bool Initialize(SurfaceTexture* surface_texture);
// Overridden from GLImage:
void Destroy(bool have_context) override;
- gfx::Size GetSize() override;
+ Size GetSize() override;
unsigned GetInternalFormat() override;
bool BindTexImage(unsigned target) override;
void ReleaseTexImage(unsigned target) override {}
+ bool CopyTexImage(unsigned target) override;
bool CopyTexSubImage(unsigned target,
const Point& offset,
const Rect& rect) override;
- void WillUseTexImage() override {}
- void DidUseTexImage() override {}
- void WillModifyTexImage() override {}
- void DidModifyTexImage() override {}
- bool ScheduleOverlayPlane(gfx::AcceleratedWidget widget,
+ bool ScheduleOverlayPlane(AcceleratedWidget widget,
int z_order,
OverlayTransform transform,
const Rect& bounds_rect,
@@ -46,7 +43,7 @@ class GL_EXPORT GLImageSurfaceTexture : public GLImage {
private:
scoped_refptr<SurfaceTexture> surface_texture_;
- const gfx::Size size_;
+ const Size size_;
GLint texture_id_;
base::ThreadChecker thread_checker_;
diff --git a/ui/gl/gl_tests.gyp b/ui/gl/gl_tests.gyp
index 09821e7..eaf0df0 100644
--- a/ui/gl/gl_tests.gyp
+++ b/ui/gl/gl_tests.gyp
@@ -28,6 +28,7 @@
'<(DEPTH)/testing/gtest.gyp:gtest',
'<(DEPTH)/third_party/mesa/mesa.gyp:osmesa',
'<(DEPTH)/ui/gfx/gfx.gyp:gfx',
+ '<(DEPTH)/ui/gfx/gfx.gyp:gfx_geometry',
'<(DEPTH)/ui/gl/gl.gyp:gl',
'<(DEPTH)/ui/gl/gl.gyp:gl_test_support',
'<(DEPTH)/ui/gl/gl.gyp:gl_unittest_utils',
diff --git a/ui/gl/test/gl_image_test_template.h b/ui/gl/test/gl_image_test_template.h
index 8533ce2..e7b685d 100644
--- a/ui/gl/test/gl_image_test_template.h
+++ b/ui/gl/test/gl_image_test_template.h
@@ -51,9 +51,51 @@ class GLImageTest : public testing::Test {
TYPED_TEST_CASE_P(GLImageTest);
-// Copy image to texture. Support is optional. Texels should be updated if
-// supported, and left unchanged if not.
-TYPED_TEST_P(GLImageTest, CopyTexSubImage) {
+TYPED_TEST_P(GLImageTest, CreateAndDestroy) {
+ const Size small_image_size(4, 4);
+ const Size large_image_size(512, 512);
+ const uint8_t image_color[] = {0, 0xff, 0, 0xff};
+
+ // Create a small solid color green image of preferred format. This must
+ // succeed in order for a GLImage to be conformant.
+ scoped_refptr<GLImage> small_image = this->delegate_.CreateSolidColorImage(
+ small_image_size, GLImageTestSupport::GetPreferredInternalFormat(),
+ GLImageTestSupport::GetPreferredBufferFormat(), image_color);
+ ASSERT_TRUE(small_image);
+
+ // Create a large solid color green image of preferred format. This must
+ // succeed in order for a GLImage to be conformant.
+ scoped_refptr<GLImage> large_image = this->delegate_.CreateSolidColorImage(
+ large_image_size, GLImageTestSupport::GetPreferredInternalFormat(),
+ GLImageTestSupport::GetPreferredBufferFormat(), image_color);
+ ASSERT_TRUE(large_image);
+
+ // Verify that image size is correct.
+ EXPECT_EQ(small_image->GetSize().ToString(), small_image_size.ToString());
+ EXPECT_EQ(large_image->GetSize().ToString(), large_image_size.ToString());
+
+ // Verify that internal format is correct.
+ EXPECT_EQ(small_image->GetInternalFormat(),
+ GLImageTestSupport::GetPreferredInternalFormat());
+ EXPECT_EQ(large_image->GetInternalFormat(),
+ GLImageTestSupport::GetPreferredInternalFormat());
+
+ // Verify that destruction of images work correctly both when we have a
+ // context and when we don't.
+ small_image->Destroy(true /* have_context */);
+ large_image->Destroy(false /* have_context */);
+}
+
+// The GLImageTest test case verifies the behaviour that is expected from a
+// GLImage in order to be conformant.
+REGISTER_TYPED_TEST_CASE_P(GLImageTest, CreateAndDestroy);
+
+template <typename GLImageTestDelegate>
+class GLImageCopyTest : public GLImageTest<GLImageTestDelegate> {};
+
+TYPED_TEST_CASE_P(GLImageCopyTest);
+
+TYPED_TEST_P(GLImageCopyTest, CopyTexImage) {
const Size image_size(256, 256);
const uint8_t image_color[] = {0, 0xff, 0, 0xff};
const uint8_t texture_color[] = {0, 0, 0xff, 0xff};
@@ -91,9 +133,9 @@ TYPED_TEST_P(GLImageTest, CopyTexSubImage) {
GLImageTestSupport::GetPreferredInternalFormat(),
GL_UNSIGNED_BYTE, pixels.get());
- // Attempt to copy |image| to |texture|.
- // Returns true on success, false on failure.
- bool rv = image->CopyTexSubImage(GL_TEXTURE_2D, Point(), Rect(image_size));
+ // Copy |image| to |texture|.
+ bool rv = image->CopyTexImage(GL_TEXTURE_2D);
+ EXPECT_TRUE(rv);
// clang-format off
const char kVertexShader[] = STRINGIZE(
@@ -161,7 +203,7 @@ TYPED_TEST_P(GLImageTest, CopyTexSubImage) {
// Draw |texture| to viewport and read back pixels to check expectations.
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
GLTestHelper::CheckPixels(0, 0, image_size.width(), image_size.height(),
- rv ? image_color : texture_color);
+ image_color);
// Clean up.
glDeleteProgram(program);
@@ -173,9 +215,9 @@ TYPED_TEST_P(GLImageTest, CopyTexSubImage) {
image->Destroy(true);
}
-// The GLImageTest test case verifies behaviour that is expected from a
-// GLImage in order to be conformant.
-REGISTER_TYPED_TEST_CASE_P(GLImageTest, CopyTexSubImage);
+// The GLImageCopyTest test case verifies that the GLImage implementation
+// handles CopyTexImage correctly.
+REGISTER_TYPED_TEST_CASE_P(GLImageCopyTest, CopyTexImage);
} // namespace gfx