|
Lines 17-96
Source/WebCore/platform/gtk/GtkWidgetBackingStoreX11.cpp_sec1
|
| 17 |
*/ |
17 |
*/ |
| 18 |
|
18 |
|
| 19 |
#include "config.h" |
19 |
#include "config.h" |
| 20 |
#include "WidgetBackingStore.h" |
20 |
#include "GtkWidgetBackingStoreX11.h" |
| 21 |
|
21 |
|
| 22 |
#include "GtkVersioning.h" |
22 |
#include "GtkVersioning.h" |
| 23 |
#include "RefPtrCairo.h" |
23 |
#include "RefPtrCairo.h" |
| 24 |
#include <X11/Xlib.h> |
|
|
| 25 |
#include <cairo-xlib.h> |
24 |
#include <cairo-xlib.h> |
| 26 |
#include <cairo.h> |
25 |
#include <cairo.h> |
| 27 |
#include <gdk/gdkx.h> |
26 |
#include <gdk/gdkx.h> |
| 28 |
|
27 |
|
| 29 |
namespace WebCore { |
28 |
namespace WebCore { |
| 30 |
|
29 |
|
| 31 |
class WidgetBackingStorePrivate { |
30 |
PassOwnPtr<WidgetBackingStore> WidgetBackingStoreGtkX11::create(GtkWidget* widget, const IntSize& size) |
| 32 |
WTF_MAKE_NONCOPYABLE(WidgetBackingStorePrivate); |
|
|
| 33 |
WTF_MAKE_FAST_ALLOCATED; |
| 34 |
|
| 35 |
public: |
| 36 |
Display* m_display; |
| 37 |
Pixmap m_pixmap; |
| 38 |
GC m_gc; |
| 39 |
RefPtr<cairo_surface_t> m_surface; |
| 40 |
|
| 41 |
static PassOwnPtr<WidgetBackingStorePrivate> create(GtkWidget* widget, const IntSize& size) |
| 42 |
{ |
| 43 |
return adoptPtr(new WidgetBackingStorePrivate(widget, size)); |
| 44 |
} |
| 45 |
|
| 46 |
~WidgetBackingStorePrivate() |
| 47 |
{ |
| 48 |
XFreePixmap(m_display, m_pixmap); |
| 49 |
XFreeGC(m_display, m_gc); |
| 50 |
} |
| 51 |
|
| 52 |
private: |
| 53 |
// We keep two copies of the surface here, which will double the memory usage, but increase |
| 54 |
// scrolling performance since we do not have to keep reallocating a memory region during |
| 55 |
// quick scrolling requests. |
| 56 |
WidgetBackingStorePrivate(GtkWidget* widget, const IntSize& size) |
| 57 |
{ |
| 58 |
GdkVisual* visual = gtk_widget_get_visual(widget); |
| 59 |
GdkScreen* screen = gdk_visual_get_screen(visual); |
| 60 |
m_display = GDK_SCREEN_XDISPLAY(screen); |
| 61 |
m_pixmap = XCreatePixmap(m_display, |
| 62 |
GDK_WINDOW_XID(gdk_screen_get_root_window(screen)), |
| 63 |
size.width(), size.height(), |
| 64 |
gdk_visual_get_depth(visual)); |
| 65 |
m_gc = XCreateGC(m_display, m_pixmap, 0, 0); |
| 66 |
|
| 67 |
m_surface = adoptRef(cairo_xlib_surface_create(m_display, m_pixmap, |
| 68 |
GDK_VISUAL_XVISUAL(visual), |
| 69 |
size.width(), size.height())); |
| 70 |
} |
| 71 |
}; |
| 72 |
|
| 73 |
PassOwnPtr<WidgetBackingStore> WidgetBackingStore::create(GtkWidget* widget, const IntSize& size) |
| 74 |
{ |
31 |
{ |
| 75 |
return adoptPtr(new WidgetBackingStore(widget, size)); |
32 |
return adoptPtr(new WidgetBackingStoreGtkX11(widget, size)); |
| 76 |
} |
33 |
} |
| 77 |
|
34 |
|
| 78 |
WidgetBackingStore::WidgetBackingStore(GtkWidget* widget, const IntSize& size) |
35 |
// We keep two copies of the surface here, which will double the memory usage, but increase |
| 79 |
: m_private(WidgetBackingStorePrivate::create(widget, size)) |
36 |
// scrolling performance since we do not have to keep reallocating a memory region during |
| 80 |
, m_size(size) |
37 |
// quick scrolling requests. |
|
|
38 |
WidgetBackingStoreGtkX11::WidgetBackingStoreGtkX11(GtkWidget* widget, const IntSize& size) |
| 39 |
: WidgetBackingStore(size) |
| 81 |
{ |
40 |
{ |
|
|
41 |
GdkVisual* visual = gtk_widget_get_visual(widget); |
| 42 |
GdkScreen* screen = gdk_visual_get_screen(visual); |
| 43 |
m_display = GDK_SCREEN_XDISPLAY(screen); |
| 44 |
m_pixmap = XCreatePixmap(m_display, |
| 45 |
GDK_WINDOW_XID(gdk_screen_get_root_window(screen)), |
| 46 |
size.width(), size.height(), |
| 47 |
gdk_visual_get_depth(visual)); |
| 48 |
m_gc = XCreateGC(m_display, m_pixmap, 0, 0); |
| 49 |
|
| 50 |
m_surface = adoptRef(cairo_xlib_surface_create(m_display, m_pixmap, |
| 51 |
GDK_VISUAL_XVISUAL(visual), size.width(), size.height())); |
| 82 |
} |
52 |
} |
| 83 |
|
53 |
|
| 84 |
WidgetBackingStore::~WidgetBackingStore() |
54 |
WidgetBackingStoreGtkX11::~WidgetBackingStoreGtkX11() |
| 85 |
{ |
55 |
{ |
|
|
56 |
XFreePixmap(m_display, m_pixmap); |
| 57 |
XFreeGC(m_display, m_gc); |
| 86 |
} |
58 |
} |
| 87 |
|
59 |
|
| 88 |
cairo_surface_t* WidgetBackingStore::cairoSurface() |
60 |
cairo_surface_t* WidgetBackingStoreGtkX11::cairoSurface() |
| 89 |
{ |
61 |
{ |
| 90 |
return m_private->m_surface.get(); |
62 |
return m_surface.get(); |
| 91 |
} |
63 |
} |
| 92 |
|
64 |
|
| 93 |
void WidgetBackingStore::scroll(const IntRect& scrollRect, const IntSize& scrollOffset) |
65 |
void WidgetBackingStoreGtkX11::scroll(const IntRect& scrollRect, const IntSize& scrollOffset) |
| 94 |
{ |
66 |
{ |
| 95 |
IntRect targetRect(scrollRect); |
67 |
IntRect targetRect(scrollRect); |
| 96 |
targetRect.move(scrollOffset); |
68 |
targetRect.move(scrollOffset); |
|
Lines 98-109
Source/WebCore/platform/gtk/GtkWidgetBackingStoreX11.cpp_sec2
|
| 98 |
if (targetRect.isEmpty()) |
70 |
if (targetRect.isEmpty()) |
| 99 |
return; |
71 |
return; |
| 100 |
|
72 |
|
| 101 |
cairo_surface_flush(m_private->m_surface.get()); |
73 |
cairo_surface_flush(m_surface.get()); |
| 102 |
XCopyArea(m_private->m_display, m_private->m_pixmap, m_private->m_pixmap, m_private->m_gc, |
74 |
XCopyArea(m_display, m_pixmap, m_pixmap, m_gc, |
| 103 |
targetRect.x() - scrollOffset.width(), targetRect.y() - scrollOffset.height(), |
75 |
targetRect.x() - scrollOffset.width(), targetRect.y() - scrollOffset.height(), |
| 104 |
targetRect.width(), targetRect.height(), |
76 |
targetRect.width(), targetRect.height(), |
| 105 |
targetRect.x(), targetRect.y()); |
77 |
targetRect.x(), targetRect.y()); |
| 106 |
cairo_surface_mark_dirty_rectangle(m_private->m_surface.get(), |
78 |
cairo_surface_mark_dirty_rectangle(m_surface.get(), |
| 107 |
targetRect.x(), targetRect.y(), |
79 |
targetRect.x(), targetRect.y(), |
| 108 |
targetRect.width(), targetRect.height()); |
80 |
targetRect.width(), targetRect.height()); |
| 109 |
} |
81 |
} |