Commit f1b2cd0e authored by dnicoara@chromium.org's avatar dnicoara@chromium.org

Adding Wayland support for ui/gfx

* Added GL surface and context support for Wayland.
* Updated ui/gfx files to allow Wayland support
* All Wayland code is behind the use_wayland gyp flag

This CL depends on http://codereview.chromium.org/7457023

BUG=
TEST=Compiled Chrome with use_wayland disabled to verify that
the changes didn't break anything


Review URL: http://codereview.chromium.org/7467007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@96192 0039d316-1c4b-4281-b951-d872f2087c98
parent 11edb87b
...@@ -988,6 +988,13 @@ ...@@ -988,6 +988,13 @@
['exclude', '(^|/)(gtk|x11)_[^/]*\\.(h|cc)$'], ['exclude', '(^|/)(gtk|x11)_[^/]*\\.(h|cc)$'],
], ],
}], }],
['use_wayland!=1', {
'sources/': [
['exclude', '_(wayland)(_unittest)?\\.(h|cc)$'],
['exclude', '(^|/)wayland/'],
['exclude', '(^|/)(wayland)_[^/]*\\.(h|cc)$'],
],
}],
['OS!="linux"', { ['OS!="linux"', {
'sources/': [ 'sources/': [
['exclude', '_linux(_unittest)?\\.(h|cc)$'], ['exclude', '_linux(_unittest)?\\.(h|cc)$'],
......
...@@ -45,17 +45,20 @@ void UpdateCairoFontOptions() { ...@@ -45,17 +45,20 @@ void UpdateCairoFontOptions() {
if (!cairo_font_options) if (!cairo_font_options)
cairo_font_options = cairo_font_options_create(); cairo_font_options = cairo_font_options_create();
GtkSettings* gtk_settings = gtk_settings_get_default();
gint antialias = 0; gint antialias = 0;
gint hinting = 0; gint hinting = 0;
gchar* hint_style = NULL; gchar* hint_style = NULL;
gchar* rgba_style = NULL; gchar* rgba_style = NULL;
#if !defined(USE_WAYLAND)
GtkSettings* gtk_settings = gtk_settings_get_default();
g_object_get(gtk_settings, g_object_get(gtk_settings,
"gtk-xft-antialias", &antialias, "gtk-xft-antialias", &antialias,
"gtk-xft-hinting", &hinting, "gtk-xft-hinting", &hinting,
"gtk-xft-hintstyle", &hint_style, "gtk-xft-hintstyle", &hint_style,
"gtk-xft-rgba", &rgba_style, "gtk-xft-rgba", &rgba_style,
NULL); NULL);
#endif
// g_object_get() doesn't tell us whether the properties were present or not, // g_object_get() doesn't tell us whether the properties were present or not,
// but if they aren't (because gnome-settings-daemon isn't running), we'll get // but if they aren't (because gnome-settings-daemon isn't running), we'll get
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#include "ui/gfx/gl/egl_util.h" #include "ui/gfx/gl/egl_util.h"
#include "third_party/angle/include/EGL/egl.h" #include "third_party/angle/include/EGL/egl.h"
// This needs to be after the EGL includes
#include "ui/gfx/gl/gl_bindings.h" #include "ui/gfx/gl/gl_bindings.h"
namespace gfx { namespace gfx {
......
...@@ -58,6 +58,7 @@ ...@@ -58,6 +58,7 @@
'gl_surface_mac.cc', 'gl_surface_mac.cc',
'gl_surface_stub.cc', 'gl_surface_stub.cc',
'gl_surface_stub.h', 'gl_surface_stub.h',
'gl_surface_wayland.cc',
'gl_surface_win.cc', 'gl_surface_win.cc',
'gl_surface_osmesa.cc', 'gl_surface_osmesa.cc',
'gl_surface_osmesa.h', 'gl_surface_osmesa.h',
...@@ -116,7 +117,12 @@ ...@@ -116,7 +117,12 @@
'<(DEPTH)/third_party/angle/include', '<(DEPTH)/third_party/angle/include',
], ],
}], }],
['use_x11 == 1', { ['use_wayland == 1', {
'sources!': [
'gl_surface_linux.cc',
],
}],
['use_x11 == 1 and use_wayland != 1', {
'sources': [ 'sources': [
'gl_context_glx.cc', 'gl_context_glx.cc',
'gl_context_glx.h', 'gl_context_glx.h',
......
...@@ -64,6 +64,10 @@ typedef void* GLeglImageOES; ...@@ -64,6 +64,10 @@ typedef void* GLeglImageOES;
typedef HDC EGLNativeDisplayType; typedef HDC EGLNativeDisplayType;
typedef HBITMAP EGLNativePixmapType; typedef HBITMAP EGLNativePixmapType;
typedef HWND EGLNativeWindowType; typedef HWND EGLNativeWindowType;
#elif defined(USE_WAYLAND)
typedef struct wl_display *EGLNativeDisplayType;
typedef struct wl_egl_pixmap *EGLNativePixmapType;
typedef struct wl_egl_window *EGLNativeWindowType;
#else #else
typedef Display *EGLNativeDisplayType; typedef Display *EGLNativeDisplayType;
typedef Pixmap EGLNativePixmapType; typedef Pixmap EGLNativePixmapType;
......
...@@ -26,6 +26,7 @@ scoped_refptr<GLContext> GLContext::CreateGLContext( ...@@ -26,6 +26,7 @@ scoped_refptr<GLContext> GLContext::CreateGLContext(
GLShareGroup* share_group, GLShareGroup* share_group,
GLSurface* compatible_surface) { GLSurface* compatible_surface) {
switch (GetGLImplementation()) { switch (GetGLImplementation()) {
#if !defined(USE_WAYLAND)
case kGLImplementationOSMesaGL: { case kGLImplementationOSMesaGL: {
scoped_refptr<GLContext> context(new GLContextOSMesa(share_group)); scoped_refptr<GLContext> context(new GLContextOSMesa(share_group));
if (!context->Initialize(compatible_surface)) if (!context->Initialize(compatible_surface))
...@@ -33,15 +34,16 @@ scoped_refptr<GLContext> GLContext::CreateGLContext( ...@@ -33,15 +34,16 @@ scoped_refptr<GLContext> GLContext::CreateGLContext(
return context; return context;
} }
case kGLImplementationEGLGLES2: { case kGLImplementationDesktopGL: {
scoped_refptr<GLContext> context(new GLContextEGL(share_group)); scoped_refptr<GLContext> context(new GLContextGLX(share_group));
if (!context->Initialize(compatible_surface)) if (!context->Initialize(compatible_surface))
return NULL; return NULL;
return context; return context;
} }
case kGLImplementationDesktopGL: { #endif
scoped_refptr<GLContext> context(new GLContextGLX(share_group)); case kGLImplementationEGLGLES2: {
scoped_refptr<GLContext> context(new GLContextEGL(share_group));
if (!context->Initialize(compatible_surface)) if (!context->Initialize(compatible_surface))
return NULL; return NULL;
......
...@@ -53,6 +53,7 @@ bool InitializeGLBindings(GLImplementation implementation) { ...@@ -53,6 +53,7 @@ bool InitializeGLBindings(GLImplementation implementation) {
return true; return true;
switch (implementation) { switch (implementation) {
#if !defined(USE_WAYLAND)
case kGLImplementationOSMesaGL: { case kGLImplementationOSMesaGL: {
FilePath module_path; FilePath module_path;
if (!PathService::Get(base::DIR_MODULE, &module_path)) { if (!PathService::Get(base::DIR_MODULE, &module_path)) {
...@@ -106,6 +107,7 @@ bool InitializeGLBindings(GLImplementation implementation) { ...@@ -106,6 +107,7 @@ bool InitializeGLBindings(GLImplementation implementation) {
InitializeGLBindingsGLX(); InitializeGLBindingsGLX();
break; break;
} }
#endif // !defined(USE_WAYLAND)
case kGLImplementationEGLGLES2: { case kGLImplementationEGLGLES2: {
base::NativeLibrary gles_library = LoadLibrary("libGLESv2.so"); base::NativeLibrary gles_library = LoadLibrary("libGLESv2.so");
if (!gles_library) if (!gles_library)
...@@ -158,8 +160,10 @@ bool InitializeGLBindings(GLImplementation implementation) { ...@@ -158,8 +160,10 @@ bool InitializeGLBindings(GLImplementation implementation) {
void InitializeDebugGLBindings() { void InitializeDebugGLBindings() {
InitializeDebugGLBindingsEGL(); InitializeDebugGLBindingsEGL();
InitializeDebugGLBindingsGL(); InitializeDebugGLBindingsGL();
#if !defined(USE_WAYLAND)
InitializeDebugGLBindingsGLX(); InitializeDebugGLBindingsGLX();
InitializeDebugGLBindingsOSMESA(); InitializeDebugGLBindingsOSMESA();
#endif
} }
} // namespace gfx } // namespace gfx
...@@ -15,12 +15,16 @@ ...@@ -15,12 +15,16 @@
// it brings in #defines that cause conflicts. // it brings in #defines that cause conflicts.
#include "ui/gfx/gl/gl_bindings.h" #include "ui/gfx/gl/gl_bindings.h"
#if defined(USE_X11) #if defined(USE_X11) && !defined(USE_WAYLAND)
extern "C" { extern "C" {
#include <X11/Xlib.h> #include <X11/Xlib.h>
} }
#endif #endif
#if defined(USE_WAYLAND)
#include "ui/wayland/wayland_display.h"
#endif
namespace gfx { namespace gfx {
namespace { namespace {
...@@ -43,7 +47,9 @@ bool GLSurfaceEGL::InitializeOneOff() { ...@@ -43,7 +47,9 @@ bool GLSurfaceEGL::InitializeOneOff() {
if (initialized) if (initialized)
return true; return true;
#if defined(USE_X11) #if defined(USE_WAYLAND)
g_native_display = ui::WaylandDisplay::Connect(NULL)->display();
#elif defined(USE_X11)
g_native_display = XOpenDisplay(NULL); g_native_display = XOpenDisplay(NULL);
#else #else
g_native_display = EGL_DEFAULT_DISPLAY; g_native_display = EGL_DEFAULT_DISPLAY;
...@@ -67,7 +73,12 @@ bool GLSurfaceEGL::InitializeOneOff() { ...@@ -67,7 +73,12 @@ bool GLSurfaceEGL::InitializeOneOff() {
EGL_GREEN_SIZE, 8, EGL_GREEN_SIZE, 8,
EGL_RED_SIZE, 8, EGL_RED_SIZE, 8,
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT, EGL_SURFACE_TYPE, EGL_WINDOW_BIT
#if defined(USE_WAYLAND)
| EGL_PIXMAP_BIT,
#else
| EGL_PBUFFER_BIT,
#endif
EGL_NONE EGL_NONE
}; };
......
...@@ -20,6 +20,8 @@ typedef void* EGLSurface; ...@@ -20,6 +20,8 @@ typedef void* EGLSurface;
#if defined(OS_WIN) #if defined(OS_WIN)
typedef HDC EGLNativeDisplayType; typedef HDC EGLNativeDisplayType;
#elif defined(USE_WAYLAND)
typedef struct wl_display* EGLNativeDisplayType;
#else #else
typedef struct _XDisplay* EGLNativeDisplayType; typedef struct _XDisplay* EGLNativeDisplayType;
#endif #endif
......
// Copyright (c) 2011 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 "ui/gfx/gl/gl_surface.h"
#include <wayland-egl.h>
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "ui/gfx/gl/egl_util.h"
#include "ui/gfx/gl/gl_bindings.h"
#include "ui/gfx/gl/gl_implementation.h"
#include "ui/gfx/gl/gl_surface_egl.h"
#include "ui/wayland/wayland_display.h"
namespace {
// Encapsulates a pixmap EGL surface.
class PixmapGLSurfaceEGL : public gfx::GLSurfaceEGL {
public:
explicit PixmapGLSurfaceEGL(bool software, const gfx::Size& size);
virtual ~PixmapGLSurfaceEGL();
// Implement GLSurface.
virtual bool Initialize();
virtual void Destroy();
virtual bool IsOffscreen();
virtual bool SwapBuffers();
virtual gfx::Size GetSize();
virtual EGLSurface GetHandle();
private:
gfx::Size size_;
EGLSurface surface_;
EGLNativePixmapType pixmap_;
DISALLOW_COPY_AND_ASSIGN(PixmapGLSurfaceEGL);
};
PixmapGLSurfaceEGL::PixmapGLSurfaceEGL(bool software, const gfx::Size& size)
: size_(size),
surface_(NULL),
pixmap_(NULL) {
software_ = software;
}
PixmapGLSurfaceEGL::~PixmapGLSurfaceEGL() {
Destroy();
}
bool PixmapGLSurfaceEGL::Initialize() {
DCHECK(!surface_);
DCHECK(!pixmap_);
pixmap_ = wl_egl_pixmap_create(
size_.width(),
size_.height(),
ui::WaylandDisplay::GetDisplay(
GLSurfaceEGL::GetNativeDisplay())->visual(),
0);
surface_ = eglCreatePixmapSurface(gfx::GLSurfaceEGL::GetDisplay(),
gfx::GLSurfaceEGL::GetConfig(),
pixmap_,
NULL);
if (!surface_) {
LOG(ERROR) << "eglCreatePixmapSurface failed with error "
<< gfx::GetLastEGLErrorString();
Destroy();
return false;
}
return true;
}
void PixmapGLSurfaceEGL::Destroy() {
if (surface_) {
if (!eglDestroySurface(gfx::GLSurfaceEGL::GetDisplay(), surface_)) {
LOG(ERROR) << "eglDestroySurface failed with error "
<< gfx::GetLastEGLErrorString();
}
surface_ = NULL;
}
if (pixmap_) {
wl_egl_pixmap_destroy(pixmap_);
pixmap_ = NULL;
}
}
bool PixmapGLSurfaceEGL::IsOffscreen() {
return true;
}
bool PixmapGLSurfaceEGL::SwapBuffers() {
NOTREACHED() << "Attempted to call SwapBuffers on a PixmapGLSurfaceEGL.";
return false;
}
gfx::Size PixmapGLSurfaceEGL::GetSize() {
return size_;
}
EGLSurface PixmapGLSurfaceEGL::GetHandle() {
return surface_;
}
}
namespace gfx {
bool GLSurface::InitializeOneOff() {
static bool initialized = false;
if (initialized)
return true;
static const GLImplementation kAllowedGLImplementations[] = {
kGLImplementationEGLGLES2
};
if (!InitializeRequestedGLBindings(
kAllowedGLImplementations,
kAllowedGLImplementations + arraysize(kAllowedGLImplementations),
kGLImplementationEGLGLES2)) {
LOG(ERROR) << "InitializeRequestedGLBindings failed.";
return false;
}
if (!GLSurfaceEGL::InitializeOneOff()) {
LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed.";
return false;
}
initialized = true;
return true;
}
scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface(
bool software,
gfx::PluginWindowHandle window) {
if (software)
return NULL;
scoped_refptr<GLSurface> surface(
new NativeViewGLSurfaceEGL(software, window));
if (!surface->Initialize())
return NULL;
return surface;
}
scoped_refptr<GLSurface> GLSurface::CreateOffscreenGLSurface(
bool software,
const gfx::Size& size) {
if (software)
return NULL;
scoped_refptr<GLSurface> surface(new PixmapGLSurfaceEGL(software, size));
if (!surface->Initialize())
return NULL;
return surface;
}
} // namespace gfx
...@@ -164,12 +164,22 @@ void SubtractRectanglesFromRegion(GdkRegion* region, ...@@ -164,12 +164,22 @@ void SubtractRectanglesFromRegion(GdkRegion* region,
} }
} }
PangoContext* GetPangoContext() {
#if defined(USE_WAYLAND)
PangoFontMap* font_map = pango_cairo_font_map_get_default();
PangoContext* default_context = pango_font_map_create_context(font_map);
#else
PangoContext* default_context = gdk_pango_context_get();
#endif
return default_context;
}
double GetPangoResolution() { double GetPangoResolution() {
static double resolution; static double resolution;
static bool determined_resolution = false; static bool determined_resolution = false;
if (!determined_resolution) { if (!determined_resolution) {
determined_resolution = true; determined_resolution = true;
PangoContext* default_context = gdk_pango_context_get(); PangoContext* default_context = GetPangoContext();
resolution = pango_cairo_context_get_resolution(default_context); resolution = pango_cairo_context_get_resolution(default_context);
g_object_unref(default_context); g_object_unref(default_context);
} }
......
...@@ -19,6 +19,8 @@ typedef struct _GdkPixbuf GdkPixbuf; ...@@ -19,6 +19,8 @@ typedef struct _GdkPixbuf GdkPixbuf;
typedef struct _GdkRegion GdkRegion; typedef struct _GdkRegion GdkRegion;
typedef struct _GdkCursor GdkCursor; typedef struct _GdkCursor GdkCursor;
typedef struct _PangoContext PangoContext;
class CommandLine; class CommandLine;
class SkBitmap; class SkBitmap;
...@@ -40,6 +42,9 @@ UI_EXPORT GdkPixbuf* GdkPixbufFromSkBitmap(const SkBitmap* bitmap); ...@@ -40,6 +42,9 @@ UI_EXPORT GdkPixbuf* GdkPixbufFromSkBitmap(const SkBitmap* bitmap);
UI_EXPORT void SubtractRectanglesFromRegion(GdkRegion* region, UI_EXPORT void SubtractRectanglesFromRegion(GdkRegion* region,
const std::vector<Rect>& cutouts); const std::vector<Rect>& cutouts);
// Creates and returns a PangoContext. The caller owns the context.
PangoContext* GetPangoContext();
// Returns the resolution (DPI) used by pango. A negative values means the // Returns the resolution (DPI) used by pango. A negative values means the
// resolution hasn't been set. // resolution hasn't been set.
double GetPangoResolution(); double GetPangoResolution();
......
...@@ -55,6 +55,18 @@ class NSView; ...@@ -55,6 +55,18 @@ class NSView;
class NSWindow; class NSWindow;
class NSTextField; class NSTextField;
#endif // __OBJC__ #endif // __OBJC__
#elif defined(USE_WAYLAND)
typedef struct _PangoFontDescription PangoFontDescription;
typedef struct _cairo cairo_t;
typedef struct _GdkPixbuf GdkPixbuf;
struct wl_egl_window;
namespace ui {
class WaylandWindow;
class WaylandCursor;
}
typedef struct _GdkRegion GdkRegion;
#elif defined(TOOLKIT_USES_GTK) #elif defined(TOOLKIT_USES_GTK)
typedef struct _PangoFontDescription PangoFontDescription; typedef struct _PangoFontDescription PangoFontDescription;
typedef struct _GdkCursor GdkCursor; typedef struct _GdkCursor GdkCursor;
...@@ -87,6 +99,18 @@ typedef CGContext* NativeDrawingContext; ...@@ -87,6 +99,18 @@ typedef CGContext* NativeDrawingContext;
typedef void* NativeCursor; typedef void* NativeCursor;
typedef void* NativeMenu; typedef void* NativeMenu;
typedef void* NativeViewAccessible; typedef void* NativeViewAccessible;
#elif defined(USE_WAYLAND)
typedef PangoFontDescription* NativeFont;
typedef ui::WaylandWindow* NativeView;
typedef ui::WaylandWindow* NativeWindow;
typedef void* NativeEditView;
typedef cairo_t* NativeDrawingContext;
typedef void* NativeCursor;
typedef void* NativeMenu;
// TODO(dnicoara) This should be replaced with a cairo region or maybe
// a Wayland specific region
typedef GdkRegion* NativeRegion;
typedef void* NativeViewAccessible;
#elif defined(USE_X11) #elif defined(USE_X11)
typedef PangoFontDescription* NativeFont; typedef PangoFontDescription* NativeFont;
typedef GtkWidget* NativeView; typedef GtkWidget* NativeView;
...@@ -141,7 +165,7 @@ static inline NativeView NativeViewFromIdInBrowser(NativeViewId id) { ...@@ -141,7 +165,7 @@ static inline NativeView NativeViewFromIdInBrowser(NativeViewId id) {
// Convert a NativeView to a NativeViewId. See the comments at the top of // Convert a NativeView to a NativeViewId. See the comments at the top of
// this file. // this file.
#if defined(OS_WIN) || defined(OS_MACOSX) #if defined(OS_WIN) || defined(OS_MACOSX) || defined(USE_WAYLAND)
static inline NativeViewId IdFromNativeView(NativeView view) { static inline NativeViewId IdFromNativeView(NativeView view) {
return reinterpret_cast<NativeViewId>(view); return reinterpret_cast<NativeViewId>(view);
} }
...@@ -157,6 +181,9 @@ UI_EXPORT NativeViewId IdFromNativeView(NativeView view); ...@@ -157,6 +181,9 @@ UI_EXPORT NativeViewId IdFromNativeView(NativeView view);
#if defined(OS_WIN) #if defined(OS_WIN)
typedef HWND PluginWindowHandle; typedef HWND PluginWindowHandle;
const PluginWindowHandle kNullPluginWindow = NULL; const PluginWindowHandle kNullPluginWindow = NULL;
#elif defined(USE_WAYLAND)
typedef struct wl_egl_window* PluginWindowHandle;
const PluginWindowHandle kNullPluginWindow = NULL;
#elif defined(USE_X11) #elif defined(USE_X11)
typedef unsigned long PluginWindowHandle; typedef unsigned long PluginWindowHandle;
const PluginWindowHandle kNullPluginWindow = 0; const PluginWindowHandle kNullPluginWindow = 0;
...@@ -179,6 +206,9 @@ UI_EXPORT NativeViewId IdFromNativeView(NativeView view); ...@@ -179,6 +206,9 @@ UI_EXPORT NativeViewId IdFromNativeView(NativeView view);
#if defined(OS_WIN) #if defined(OS_WIN)
typedef HWND AcceleratedWidget; typedef HWND AcceleratedWidget;
const AcceleratedWidget kNullAcceleratedWidget = NULL; const AcceleratedWidget kNullAcceleratedWidget = NULL;
#elif defined(USE_WAYLAND)
typedef struct wl_egl_window* AcceleratedWidget;
const AcceleratedWidget kNullAcceleratedWidget = NULL;
#elif defined(USE_X11) #elif defined(USE_X11)
typedef unsigned long AcceleratedWidget; typedef unsigned long AcceleratedWidget;
const AcceleratedWidget kNullAcceleratedWidget = 0; const AcceleratedWidget kNullAcceleratedWidget = 0;
......
...@@ -6,10 +6,9 @@ ...@@ -6,10 +6,9 @@
#include <algorithm> #include <algorithm>
#include <fontconfig/fontconfig.h> #include <fontconfig/fontconfig.h>
#include <gdk/gdk.h>
#include <gtk/gtk.h>
#include <map> #include <map>
#include <pango/pango.h> #include <pango/pango.h>
#include <string>
#include "base/logging.h" #include "base/logging.h"
#include "base/string_piece.h" #include "base/string_piece.h"
...@@ -20,6 +19,11 @@ ...@@ -20,6 +19,11 @@
#include "ui/gfx/font.h" #include "ui/gfx/font.h"
#include "ui/gfx/gtk_util.h" #include "ui/gfx/gtk_util.h"
#if !defined(USE_WAYLAND)
#include <gdk/gdk.h>
#include <gtk/gtk.h>
#endif
namespace { namespace {
// The font family name which is used when a user's application font for // The font family name which is used when a user's application font for
...@@ -56,7 +60,7 @@ PangoFontMetrics* GetPangoFontMetrics(PangoFontDescription* desc) { ...@@ -56,7 +60,7 @@ PangoFontMetrics* GetPangoFontMetrics(PangoFontDescription* desc) {
static PangoContext* context = NULL; static PangoContext* context = NULL;
if (!context) { if (!context) {
context = gdk_pango_context_get_for_screen(gdk_screen_get_default()); context = gfx::GetPangoContext();
pango_context_set_language(context, pango_language_get_default()); pango_context_set_language(context, pango_language_get_default());
} }
...@@ -109,6 +113,25 @@ string16 FindBestMatchFontFamilyName(const char* family_name) { ...@@ -109,6 +113,25 @@ string16 FindBestMatchFontFamilyName(const char* family_name) {
return font_family; return font_family;
} }
std::string GetDefaultFont() {
#if defined(USE_WAYLAND)
return "sans 10";
#else
GtkSettings* settings = gtk_settings_get_default();
gchar* font_name = NULL;
g_object_get(settings, "gtk-font-name", &font_name, NULL);
// Temporary CHECK for helping track down
// http://code.google.com/p/chromium/issues/detail?id=12530
CHECK(font_name) << " Unable to get gtk-font-name for default font.";
std::string default_font = std::string(font_name);
g_free(font_name);
return default_font;
#endif
}
} // namespace } // namespace
namespace gfx { namespace gfx {
...@@ -120,20 +143,12 @@ Font* PlatformFontGtk::default_font_ = NULL; ...@@ -120,20 +143,12 @@ Font* PlatformFontGtk::default_font_ = NULL;
PlatformFontGtk::PlatformFontGtk() { PlatformFontGtk::PlatformFontGtk() {
if (default_font_ == NULL) { if (default_font_ == NULL) {
GtkSettings* settings = gtk_settings_get_default(); std::string font_name = GetDefaultFont();
gchar* font_name = NULL;
g_object_get(settings, "gtk-font-name", &font_name, NULL);
// Temporary CHECK for helping track down
// http://code.google.com/p/chromium/issues/detail?id=12530
CHECK(font_name) << " Unable to get gtk-font-name for default font.";
PangoFontDescription* desc = PangoFontDescription* desc =
pango_font_description_from_string(font_name); pango_font_description_from_string(font_name.c_str());
default_font_ = new Font(desc); default_font_ = new Font(desc);
pango_font_description_free(desc); pango_font_description_free(desc);
g_free(font_name);
DCHECK(default_font_); DCHECK(default_font_);
} }
......
// Copyright (c) 2011 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 "ui/gfx/screen.h"
#include "base/logging.h"
#include "ui/gfx/gl/gl_surface_egl.h"
#include "ui/wayland/wayland_display.h"
#include "ui/wayland/wayland_screen.h"
namespace gfx {
// static
gfx::Point Screen::GetCursorScreenPoint() {
NOTIMPLEMENTED();
return gfx::Point();
}
gfx::Rect static GetPrimaryMonitorBounds() {
ui::WaylandDisplay* display = ui::WaylandDisplay::GetDisplay(
gfx::GLSurfaceEGL::GetNativeDisplay());
std::list<ui::WaylandScreen*> screens = display->GetScreenList();
return screens.empty() ? gfx::Rect() : screens.front()->GetAllocation();
}
// static
gfx::Rect Screen::GetMonitorWorkAreaNearestWindow(gfx::NativeView view) {
// TODO(dnicoara): use |view|.
return GetPrimaryMonitorBounds();
}
// static
gfx::Rect Screen::GetMonitorAreaNearestWindow(gfx::NativeView view) {
NOTIMPLEMENTED();
return gfx::Rect();
}
// static
gfx::Rect Screen::GetMonitorWorkAreaNearestPoint(const gfx::Point& point) {
return GetMonitorAreaNearestPoint(point);
}
// static
gfx::Rect Screen::GetMonitorAreaNearestPoint(const gfx::Point& point) {
NOTIMPLEMENTED();
return gfx::Rect();
}
gfx::NativeWindow Screen::GetWindowAtCursorScreenPoint() {
NOTIMPLEMENTED();
return NULL;
}
} // namespace gfx
// Copyright (c) 2011 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 "ui/gfx/surface/accelerated_surface_wayland.h"
#include <wayland-egl.h>
#include "third_party/angle/include/EGL/egl.h"
#include "third_party/angle/include/EGL/eglext.h"
#include "ui/gfx/gl/gl_bindings.h"
#include "ui/gfx/gl/gl_surface_egl.h"
#include "ui/wayland/wayland_display.h"
AcceleratedSurface::AcceleratedSurface(const gfx::Size& size)
: size_(size),
image_(NULL),
pixmap_(NULL),
texture_(0) {
ui::WaylandDisplay* dpy = ui::WaylandDisplay::GetDisplay(
gfx::GLSurfaceEGL::GetNativeDisplay());
EGLDisplay edpy = gfx::GLSurfaceEGL::GetHardwareDisplay();
pixmap_ = wl_egl_pixmap_create(size_.width(),
size_.height(),
dpy->visual(),
0);
image_ = eglCreateImageKHR(
edpy, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, (void*) pixmap_, NULL);
glGenTextures(1, &texture_);
GLint current_texture = 0;
glGetIntegerv(GL_TEXTURE_BINDING_2D, &current_texture);
glBindTexture(GL_TEXTURE_2D, texture_);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_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);
glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image_);
glBindTexture(GL_TEXTURE_2D, current_texture);
}
AcceleratedSurface::~AcceleratedSurface() {
glDeleteTextures(1, &texture_);
eglDestroyImageKHR(gfx::GLSurfaceEGL::GetHardwareDisplay(), image_);
wl_egl_pixmap_destroy(pixmap_);
}
// Copyright (c) 2011 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.
#ifndef UI_GFX_SURFACE_ACCELERATED_SURFACE_LINUX_H_
#define UI_GFX_SURFACE_ACCELERATED_SURFACE_LINUX_H_
#pragma once
#include "base/memory/ref_counted.h"
#include "ui/gfx/size.h"
struct wl_egl_pixmap;
// The GL context associated with the surface must be current when
// an instance is created or destroyed.
class AcceleratedSurface : public base::RefCounted<AcceleratedSurface> {
public:
AcceleratedSurface(const gfx::Size& size);
const gfx::Size& size() const { return size_; }
// The pointer returned is owned by this object
wl_egl_pixmap* pixmap() const { return pixmap_; }
uint32 texture() const { return texture_; }
private:
friend class base::RefCounted<AcceleratedSurface>;
~AcceleratedSurface();
gfx::Size size_;
void* image_;
wl_egl_pixmap* pixmap_;
uint32 texture_;
DISALLOW_COPY_AND_ASSIGN(AcceleratedSurface);
};
#endif // UI_GFX_SURFACE_ACCELERATED_SURFACE_LINUX_H_
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
'target_defaults': { 'target_defaults': {
'conditions': [ 'conditions': [
['toolkit_uses_gtk == 1', { ['toolkit_uses_gtk == 1 or use_wayland == 1', {
'include_dirs': [ 'include_dirs': [
'<(DEPTH)/third_party/angle/include', '<(DEPTH)/third_party/angle/include',
], ],
...@@ -31,6 +31,8 @@ ...@@ -31,6 +31,8 @@
'accelerated_surface_linux.h', 'accelerated_surface_linux.h',
'accelerated_surface_mac.cc', 'accelerated_surface_mac.cc',
'accelerated_surface_mac.h', 'accelerated_surface_mac.h',
'accelerated_surface_wayland.cc',
'accelerated_surface_wayland.h',
'io_surface_support_mac.cc', 'io_surface_support_mac.cc',
'io_surface_support_mac.h', 'io_surface_support_mac.h',
'transport_dib.h', 'transport_dib.h',
...@@ -38,6 +40,14 @@ ...@@ -38,6 +40,14 @@
'transport_dib_mac.cc', 'transport_dib_mac.cc',
'transport_dib_win.cc', 'transport_dib_win.cc',
], ],
'conditions': [
['use_wayland == 1', {
'sources/': [
['exclude', 'accelerated_surface_linux.cc'],
['exclude', 'accelerated_surface_linux.h'],
],
}],
],
}, },
], ],
} }
...@@ -259,6 +259,7 @@ ...@@ -259,6 +259,7 @@
'gfx/render_text_win.h', 'gfx/render_text_win.h',
'gfx/screen.h', 'gfx/screen.h',
'gfx/screen_gtk.cc', 'gfx/screen_gtk.cc',
'gfx/screen_wayland.cc',
'gfx/screen_win.cc', 'gfx/screen_win.cc',
'gfx/scoped_cg_context_save_gstate_mac.h', 'gfx/scoped_cg_context_save_gstate_mac.h',
'gfx/scoped_ns_graphics_context_save_gstate_mac.h', 'gfx/scoped_ns_graphics_context_save_gstate_mac.h',
...@@ -322,6 +323,25 @@ ...@@ -322,6 +323,25 @@
}], }],
], ],
}], }],
['use_wayland == 1', {
'sources/': [
['exclude', '_(gtk|x)\\.cc$'],
['exclude', '/(gtk|x11)_[^/]*\\.cc$'],
['include', 'base/dragdrop/gtk_dnd_util.cc'],
['include', 'base/dragdrop/gtk_dnd_util.h'],
['include', 'base/dragdrop/os_exchange_data_provider_gtk.cc'],
['include', 'base/dragdrop/os_exchange_data_provider_gtk.h'],
['include', 'base/keycodes/keyboard_code_conversion_x.cc'],
['include', 'base/keycodes/keyboard_code_conversion_x.h'],
['include', 'base/view_prop.cc'],
['include', 'base/view_prop.h'],
['include', 'gfx/gtk_util.cc'],
['include', 'gfx/gtk_util.h'],
['include', 'gfx/path_gtk.cc'],
['include', 'gfx/platform_font_gtk.cc'],
['include', 'gfx/platform_font_gtk.h'],
],
}],
['OS=="win"', { ['OS=="win"', {
'sources': [ 'sources': [
'gfx/canvas_direct2d.cc', 'gfx/canvas_direct2d.cc',
......
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