Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Unified Diff: ui/gl/gl_surface_ozone.cc

Issue 938873002: Add a new API to create a surfaceless GLSurface for Ozone (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove deps, add some missing EXTs Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gl/gl_surface.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gl/gl_surface_ozone.cc
diff --git a/ui/gl/gl_surface_ozone.cc b/ui/gl/gl_surface_ozone.cc
index cba706bda4e030b6daa599525846ebebbc847640..60b7e14ea4f919d5648706582580a7719f00adf5 100644
--- a/ui/gl/gl_surface_ozone.cc
+++ b/ui/gl/gl_surface_ozone.cc
@@ -9,11 +9,13 @@
#include "ui/gfx/native_widget_types.h"
#include "ui/gl/gl_context.h"
#include "ui/gl/gl_image.h"
+#include "ui/gl/gl_image_egl.h"
#include "ui/gl/gl_implementation.h"
#include "ui/gl/gl_surface_egl.h"
#include "ui/gl/gl_surface_osmesa.h"
#include "ui/gl/gl_surface_stub.h"
#include "ui/gl/scoped_make_current.h"
+#include "ui/ozone/public/native_pixmap.h"
#include "ui/ozone/public/surface_factory_ozone.h"
#include "ui/ozone/public/surface_ozone_egl.h"
@@ -157,7 +159,7 @@ class GL_EXPORT GLSurfaceOzoneSurfaceless : public SurfacelessEGL {
return SwapBuffersAsync(callback);
}
- private:
+ protected:
~GLSurfaceOzoneSurfaceless() override {
Destroy(); // EGL surface must be destroyed before SurfaceOzone
}
@@ -194,6 +196,99 @@ class GL_EXPORT GLSurfaceOzoneSurfaceless : public SurfacelessEGL {
DISALLOW_COPY_AND_ASSIGN(GLSurfaceOzoneSurfaceless);
};
+// This provides surface-like semantics implemented through surfaceless.
+// A framebuffer is bound automatically and re-bound at each swap.
+class GL_EXPORT GLSurfaceOzoneSurfacelessSurfaceImpl
+ : public GLSurfaceOzoneSurfaceless {
+ public:
+ GLSurfaceOzoneSurfacelessSurfaceImpl(
+ scoped_ptr<ui::SurfaceOzoneEGL> ozone_surface,
+ AcceleratedWidget widget)
+ : GLSurfaceOzoneSurfaceless(ozone_surface.Pass(), widget),
+ fbo_(0),
+ current_surface_(0) {
+ textures_[0] = 0;
+ textures_[1] = 0;
+ }
+
+ unsigned int GetBackingFrameBufferObject() override { return fbo_; }
+
+ bool OnMakeCurrent(GLContext* context) override {
+ if (!fbo_) {
+ glGenFramebuffersEXT(1, &fbo_);
+ if (!fbo_)
+ return false;
+ glGenTextures(2, textures_);
+ // Create and bind our pixmaps.
+ if (!ResizePixmaps())
+ return false;
+ }
+ BindFramebuffer();
+ return SurfacelessEGL::OnMakeCurrent(context);
+ }
+
+ bool Resize(const gfx::Size& size) override {
+ return GLSurfaceOzoneSurfaceless::Resize(size) && ResizePixmaps();
+ }
+
+ bool SupportsPostSubBuffer() override { return false; }
+
+ bool SwapBuffers() override {
+ bool ret = images_[current_surface_]->ScheduleOverlayPlane(
+ widget_, 0, OverlayTransform::OVERLAY_TRANSFORM_NONE,
+ gfx::Rect(GetSize()), gfx::RectF(1, 1)) &&
+ GLSurfaceOzoneSurfaceless::SwapBuffers();
+ current_surface_ ^= 1;
+ BindFramebuffer();
+ return ret;
+ }
+
+ private:
+ ~GLSurfaceOzoneSurfacelessSurfaceImpl() override {
+ glBindFramebufferEXT(GL_FRAMEBUFFER, 0);
piman 2015/02/19 23:21:19 This is too late to do GL calls, the context is no
achaulk 2015/02/23 20:43:09 Done.
+ glDeleteTextures(2, textures_);
+ glDeleteFramebuffersEXT(1, &fbo_);
+ }
+
+ void BindFramebuffer() {
+ glBindFramebufferEXT(GL_FRAMEBUFFER, fbo_);
+ glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
+ GL_TEXTURE_2D, textures_[current_surface_], 0);
+ }
+
+ bool ResizePixmaps() {
+ if (!fbo_)
+ return true;
+ for (int i = 0; i < 2; i++) {
+ scoped_refptr<ui::NativePixmap> pixmap =
+ ui::SurfaceFactoryOzone::GetInstance()->CreateNativePixmap(
+ widget_, GetSize(), ui::SurfaceFactoryOzone::RGBA_8888,
+ ui::SurfaceFactoryOzone::SCANOUT);
+ if (!pixmap)
+ return false;
+ scoped_refptr<GLImageEGL> image = new GLImageEGL(GetSize());
+ EGLint attrs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE};
+ if (!image->Initialize(EGL_NATIVE_PIXMAP_KHR,
+ pixmap->GetEGLClientBuffer(), attrs))
+ return false;
+ images_[i] = image;
+ pixmaps_[i] = pixmap;
+ // Bind image to texture.
+ glBindTexture(GL_TEXTURE_EXTERNAL_OES, textures_[i]);
+ if (!images_[i]->BindTexImage(GL_TEXTURE_EXTERNAL_OES))
+ return false;
+ }
+ return true;
+ }
+
+ GLuint fbo_;
+ GLuint textures_[2];
+ scoped_refptr<GLImage> images_[2];
+ scoped_refptr<ui::NativePixmap> pixmaps_[2];
+ int current_surface_;
+ DISALLOW_COPY_AND_ASSIGN(GLSurfaceOzoneSurfacelessSurfaceImpl);
+};
+
} // namespace
// static
@@ -215,6 +310,27 @@ bool GLSurface::InitializeOneOffInternal() {
}
// static
+scoped_refptr<GLSurface> GLSurface::CreateSurfacelessViewGLSurface(
+ gfx::AcceleratedWidget window) {
+ if (GetGLImplementation() == kGLImplementationEGLGLES2 &&
+ window != kNullAcceleratedWidget &&
+ GLSurfaceEGL::IsEGLSurfacelessContextSupported() &&
+ ui::SurfaceFactoryOzone::GetInstance()->CanShowPrimaryPlaneAsOverlay()) {
+ scoped_ptr<ui::SurfaceOzoneEGL> surface_ozone =
+ ui::SurfaceFactoryOzone::GetInstance()
+ ->CreateSurfacelessEGLSurfaceForWidget(window);
+ if (!surface_ozone)
+ return NULL;
piman 2015/02/19 23:21:19 nit: nullptr for consistency
achaulk 2015/02/23 20:43:09 Done.
+ scoped_refptr<GLSurface> surface;
+ surface = new GLSurfaceOzoneSurfaceless(surface_ozone.Pass(), window);
+ if (surface->Initialize())
+ return surface;
+ }
+
+ return nullptr;
+}
+
+// static
scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface(
gfx::AcceleratedWidget window) {
if (GetGLImplementation() == kGLImplementationOSMesaGL) {
@@ -234,7 +350,8 @@ scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface(
->CreateSurfacelessEGLSurfaceForWidget(window);
if (!surface_ozone)
return NULL;
- surface = new GLSurfaceOzoneSurfaceless(surface_ozone.Pass(), window);
+ surface = new GLSurfaceOzoneSurfacelessSurfaceImpl(surface_ozone.Pass(),
+ window);
} else {
scoped_ptr<ui::SurfaceOzoneEGL> surface_ozone =
ui::SurfaceFactoryOzone::GetInstance()->CreateEGLSurfaceForWidget(
« no previous file with comments | « ui/gl/gl_surface.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698