Changeset 184197 in webkit


Ignore:
Timestamp:
May 12, 2015, 4:11:00 AM (10 years ago)
Author:
Carlos Garcia Campos
Message:

[X11] Add XUniquePtr and XUniqueResource to automatically free X resources
https://bugs.webkit.org/show_bug.cgi?id=144521

Reviewed by Darin Adler.

Source/WebCore:

Add XUniquePtr as a template alias of std:unique_ptr to handle X
resources using pointers and XUniqueResource as a new class to
handle X resources using a long unsigned identifier. This
simplifies the code and makes it more difficult to leak X resources.

  • PlatformEfl.cmake: Add new files to compilation.
  • PlatformGTK.cmake: Ditto.
  • platform/graphics/cairo/BackingStoreBackendCairoX11.cpp:

(WebCore::BackingStoreBackendCairoX11::BackingStoreBackendCairoX11):
Remove the display member, and use XUnique for Pixmap and GC.
(WebCore::BackingStoreBackendCairoX11::~BackingStoreBackendCairoX11):
Remove code to explicitly free Pixmap and GC.
(WebCore::BackingStoreBackendCairoX11::scroll):

  • platform/graphics/cairo/BackingStoreBackendCairoX11.h:
  • platform/graphics/glx/GLContextGLX.cpp:

(WebCore::GLContextGLX::createWindowContext): Use XUnique and the
new constructor that receives a XID, since there's no longer
conflict with the one receiving a Pbuffer.
(WebCore::GLContextGLX::createPbufferContext): Use XUnique and the
new constructor that receives a XUniqueGLXPbuffer&&.
(WebCore::GLContextGLX::createPixmapContext):
(WebCore::GLContextGLX::createContext):
(WebCore::GLContextGLX::GLContextGLX):
(WebCore::GLContextGLX::~GLContextGLX): Remove code to explicitly
free X resources.
(WebCore::GLContextGLX::makeContextCurrent):
(WebCore::GLContextGLX::cairoDevice):
(WebCore::GLContextGLX::platformContext):

  • platform/graphics/glx/GLContextGLX.h:
  • platform/graphics/surfaces/egl/EGLXSurface.cpp:

(WebCore::EGLXTransportSurfaceClient::EGLXTransportSurfaceClient):
(WebCore::EGLXTransportSurfaceClient::destroy):
(WebCore::EGLXTransportSurfaceClient::prepareTexture):

  • platform/graphics/surfaces/egl/EGLXSurface.h:
  • platform/graphics/surfaces/glx/GLXConfigSelector.h:

(WebCore::GLXConfigSelector::findMatchingConfig): Use XUnique
instead of the custom std::unique X11Deleter.
(WebCore::GLXConfigSelector::findMatchingConfigWithVisualId): Ditto.

  • platform/graphics/surfaces/glx/GLXSurface.cpp:

(WebCore::GLXTransportSurface::GLXTransportSurface): Ditto.
(WebCore::GLXOffScreenSurface::initialize):

  • platform/graphics/surfaces/glx/X11Helper.cpp:

(WebCore::X11Helper::createOffScreenWindow): Ditto.
(WebCore::X11Helper::createPixmap): Ditto.

  • platform/graphics/surfaces/glx/X11Helper.h:
  • platform/graphics/x11/XUniquePtr.h: Remove X11Deleter.

(WebCore::XPtrDeleter::operator()):

  • platform/graphics/x11/XUniqueResource.cpp: Added.

(WebCore::XUniqueResource<XResource::Colormap>::deleteXResource):
(WebCore::XUniqueResource<XResource::Damage>::deleteXResource):
(WebCore::XUniqueResource<XResource::Pixmap>::deleteXResource):
(WebCore::XUniqueResource<XResource::Window>::deleteXResource):
(WebCore::XUniqueResource<XResource::GLXPbuffer>::deleteXResource):
(WebCore::XUniqueResource<XResource::GLXPixmap>::deleteXResource):

  • platform/graphics/x11/XUniqueResource.h: Added.

(WebCore::XUniqueResource::XUniqueResource):
(WebCore::XUniqueResource::operator=):
(WebCore::XUniqueResource::~XUniqueResource):
(WebCore::XUniqueResource::get):
(WebCore::XUniqueResource::release):
(WebCore::XUniqueResource::reset):
(WebCore::XUniqueResource::operator!):
(WebCore::XUniqueResource::operator UnspecifiedBoolType*):

Source/WebKit2:

Use XUniquePtr and XUniqueResource to free X resources.

  • PlatformEfl.cmake: Add Source/WebCore/platform/graphics/x11 dir

to the include dir list.

  • PlatformGTK.cmake: Ditto.
  • UIProcess/cairo/BackingStoreCairo.cpp:

(WebKit::BackingStore::createBackend): Do not pass the display to
the BackingStoreBackendCairoX11 constructor.

  • UIProcess/gtk/RedirectedXCompositeWindow.cpp:

(WebKit::RedirectedXCompositeWindow::RedirectedXCompositeWindow):
(WebKit::RedirectedXCompositeWindow::~RedirectedXCompositeWindow):
(WebKit::RedirectedXCompositeWindow::resize):
(WebKit::RedirectedXCompositeWindow::cleanupPixmapAndPixmapSurface):
(WebKit::RedirectedXCompositeWindow::surface):

  • UIProcess/gtk/RedirectedXCompositeWindow.h:

(WebKit::RedirectedXCompositeWindow::windowID):

  • WebProcess/Plugins/Netscape/NetscapePlugin.h:
  • WebProcess/Plugins/Netscape/x11/NetscapePluginX11.cpp:

(WebKit::NetscapePlugin::platformPostInitializeWindowless):
(WebKit::NetscapePlugin::platformDestroy):
(WebKit::NetscapePlugin::platformGeometryDidChange):
(WebKit::NetscapePlugin::platformPaint):

Location:
trunk/Source
Files:
3 added
21 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r184193 r184197  
     12015-05-08  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [X11] Add XUniquePtr and XUniqueResource to automatically free X resources
     4        https://bugs.webkit.org/show_bug.cgi?id=144521
     5
     6        Reviewed by Darin Adler.
     7
     8        Add XUniquePtr as a template alias of std:unique_ptr to handle X
     9        resources using pointers and XUniqueResource as a new class to
     10        handle X resources using a long unsigned identifier. This
     11        simplifies the code and makes it more difficult to leak X resources.
     12
     13        * PlatformEfl.cmake: Add new files to compilation.
     14        * PlatformGTK.cmake: Ditto.
     15        * platform/graphics/cairo/BackingStoreBackendCairoX11.cpp:
     16        (WebCore::BackingStoreBackendCairoX11::BackingStoreBackendCairoX11):
     17        Remove the display member, and use XUnique for Pixmap and GC.
     18        (WebCore::BackingStoreBackendCairoX11::~BackingStoreBackendCairoX11):
     19        Remove code to explicitly free Pixmap and GC.
     20        (WebCore::BackingStoreBackendCairoX11::scroll):
     21        * platform/graphics/cairo/BackingStoreBackendCairoX11.h:
     22        * platform/graphics/glx/GLContextGLX.cpp:
     23        (WebCore::GLContextGLX::createWindowContext): Use XUnique and the
     24        new constructor that receives a XID, since there's no longer
     25        conflict with the one receiving a Pbuffer.
     26        (WebCore::GLContextGLX::createPbufferContext): Use XUnique and the
     27        new constructor that receives a XUniqueGLXPbuffer&&.
     28        (WebCore::GLContextGLX::createPixmapContext):
     29        (WebCore::GLContextGLX::createContext):
     30        (WebCore::GLContextGLX::GLContextGLX):
     31        (WebCore::GLContextGLX::~GLContextGLX): Remove code to explicitly
     32        free X resources.
     33        (WebCore::GLContextGLX::makeContextCurrent):
     34        (WebCore::GLContextGLX::cairoDevice):
     35        (WebCore::GLContextGLX::platformContext):
     36        * platform/graphics/glx/GLContextGLX.h:
     37        * platform/graphics/surfaces/egl/EGLXSurface.cpp:
     38        (WebCore::EGLXTransportSurfaceClient::EGLXTransportSurfaceClient):
     39        (WebCore::EGLXTransportSurfaceClient::destroy):
     40        (WebCore::EGLXTransportSurfaceClient::prepareTexture):
     41        * platform/graphics/surfaces/egl/EGLXSurface.h:
     42        * platform/graphics/surfaces/glx/GLXConfigSelector.h:
     43        (WebCore::GLXConfigSelector::findMatchingConfig): Use XUnique
     44        instead of the custom std::unique X11Deleter.
     45        (WebCore::GLXConfigSelector::findMatchingConfigWithVisualId): Ditto.
     46        * platform/graphics/surfaces/glx/GLXSurface.cpp:
     47        (WebCore::GLXTransportSurface::GLXTransportSurface): Ditto.
     48        (WebCore::GLXOffScreenSurface::initialize):
     49        * platform/graphics/surfaces/glx/X11Helper.cpp:
     50        (WebCore::X11Helper::createOffScreenWindow): Ditto.
     51        (WebCore::X11Helper::createPixmap): Ditto.
     52        * platform/graphics/surfaces/glx/X11Helper.h:
     53        * platform/graphics/x11/XUniquePtr.h: Remove X11Deleter.
     54        (WebCore::XPtrDeleter::operator()):
     55        * platform/graphics/x11/XUniqueResource.cpp: Added.
     56        (WebCore::XUniqueResource<XResource::Colormap>::deleteXResource):
     57        (WebCore::XUniqueResource<XResource::Damage>::deleteXResource):
     58        (WebCore::XUniqueResource<XResource::Pixmap>::deleteXResource):
     59        (WebCore::XUniqueResource<XResource::Window>::deleteXResource):
     60        (WebCore::XUniqueResource<XResource::GLXPbuffer>::deleteXResource):
     61        (WebCore::XUniqueResource<XResource::GLXPixmap>::deleteXResource):
     62        * platform/graphics/x11/XUniqueResource.h: Added.
     63        (WebCore::XUniqueResource::XUniqueResource):
     64        (WebCore::XUniqueResource::operator=):
     65        (WebCore::XUniqueResource::~XUniqueResource):
     66        (WebCore::XUniqueResource::get):
     67        (WebCore::XUniqueResource::release):
     68        (WebCore::XUniqueResource::reset):
     69        (WebCore::XUniqueResource::operator!):
     70        (WebCore::XUniqueResource::operator UnspecifiedBoolType*):
     71
    1722015-05-12  Zan Dobersek  <zdobersek@igalia.com>
    273
  • trunk/Source/WebCore/PlatformEfl.cmake

    r183807 r184197  
    198198
    199199    platform/graphics/x11/PlatformDisplayX11.cpp
     200    platform/graphics/x11/XUniqueResource.cpp
    200201
    201202    platform/image-decoders/ImageDecoder.cpp
  • trunk/Source/WebCore/PlatformGTK.cmake

    r183807 r184197  
    127127
    128128    platform/graphics/x11/PlatformDisplayX11.cpp
     129    platform/graphics/x11/XUniqueResource.cpp
    129130
    130131    platform/gtk/ErrorsGtk.cpp
  • trunk/Source/WebCore/platform/graphics/cairo/BackingStoreBackendCairoX11.cpp

    r175159 r184197  
    2727namespace WebCore {
    2828
    29 BackingStoreBackendCairoX11::BackingStoreBackendCairoX11(Display* display, unsigned long rootWindowID, Visual* visual, int depth, const IntSize& size, float deviceScaleFactor)
     29BackingStoreBackendCairoX11::BackingStoreBackendCairoX11(unsigned long rootWindowID, Visual* visual, int depth, const IntSize& size, float deviceScaleFactor)
    3030    : BackingStoreBackendCairo(size)
    31     , m_display(display)
    3231{
    3332    IntSize scaledSize = size;
    3433    scaledSize.scale(deviceScaleFactor);
    3534
    36     m_pixmap = XCreatePixmap(m_display, rootWindowID, scaledSize.width(), scaledSize.height(), depth);
    37     m_gc = XCreateGC(m_display, m_pixmap, 0, nullptr);
     35    auto* display = downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native();
     36    m_pixmap = XCreatePixmap(display, rootWindowID, scaledSize.width(), scaledSize.height(), depth);
     37    m_gc.reset(XCreateGC(display, m_pixmap.get(), 0, nullptr));
    3838
    39     m_surface = adoptRef(cairo_xlib_surface_create(m_display, m_pixmap, visual, scaledSize.width(), scaledSize.height()));
     39    m_surface = adoptRef(cairo_xlib_surface_create(display, m_pixmap.get(), visual, scaledSize.width(), scaledSize.height()));
    4040    cairoSurfaceSetDeviceScale(m_surface.get(), deviceScaleFactor, deviceScaleFactor);
    4141}
     
    4545    // The pixmap needs to exist when the surface is destroyed, so begin by clearing it.
    4646    m_surface.clear();
    47     XFreePixmap(m_display, m_pixmap);
    48     XFreeGC(m_display, m_gc);
    4947}
    5048
     
    6664
    6765    cairo_surface_flush(m_surface.get());
    68     XCopyArea(m_display, m_pixmap, m_pixmap, m_gc,
     66    XCopyArea(downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native(), m_pixmap.get(), m_pixmap.get(), m_gc.get(),
    6967        targetRect.x() - scaledScrollOffset.width(), targetRect.y() - scaledScrollOffset.height(),
    7068        targetRect.width(), targetRect.height(), targetRect.x(), targetRect.y());
  • trunk/Source/WebCore/platform/graphics/cairo/BackingStoreBackendCairoX11.h

    r175159 r184197  
    2323
    2424#if USE(CAIRO) && PLATFORM(X11)
    25 #include <X11/Xlib.h>
     25#include "XUniquePtr.h"
     26#include "XUniqueResource.h"
    2627
    2728namespace WebCore {
     
    2930class BackingStoreBackendCairoX11 final : public BackingStoreBackendCairo {
    3031public:
    31     BackingStoreBackendCairoX11(Display*, unsigned long rootWindowID, Visual*, int depth, const IntSize&, float deviceScaleFactor);
     32    BackingStoreBackendCairoX11(unsigned long rootWindowID, Visual*, int depth, const IntSize&, float deviceScaleFactor);
    3233    virtual ~BackingStoreBackendCairoX11();
    3334
     
    3536
    3637private:
    37     Display* m_display;
    38     Pixmap m_pixmap;
    39     GC m_gc;
     38    XUniquePixmap m_pixmap;
     39    XUniqueGC m_gc;
    4040};
    4141
  • trunk/Source/WebCore/platform/graphics/glx/GLContextGLX.cpp

    r183731 r184197  
    4444
    4545    int numReturned = 0;
    46     XVisualInfo* visualInfoList = XGetVisualInfo(display, VisualIDMask, &visualInfo, &numReturned);
    47 
    48     GLXContext glxSharingContext = sharingContext ? static_cast<GLContextGLX*>(sharingContext)->m_context : 0;
    49     GLXContext context = glXCreateContext(display, visualInfoList, glxSharingContext, True);
    50     XFree(visualInfoList);
    51 
    52     if (!context)
    53         return nullptr;
    54 
    55     // GLXPbuffer and XID are both the same types underneath, so we have to share
    56     // a constructor here with the window path.
    57     auto contextWrapper = std::make_unique<GLContextGLX>(context);
    58     contextWrapper->m_window = window;
    59     return WTF::move(contextWrapper);
     46    XUniquePtr<XVisualInfo> visualInfoList(XGetVisualInfo(display, VisualIDMask, &visualInfo, &numReturned));
     47
     48    GLXContext glxSharingContext = sharingContext ? static_cast<GLContextGLX*>(sharingContext)->m_context.get() : nullptr;
     49    XUniqueGLXContext context(glXCreateContext(display, visualInfoList.get(), glxSharingContext, True));
     50    if (!context)
     51        return nullptr;
     52
     53    return std::make_unique<GLContextGLX>(WTF::move(context), window);
    6054}
    6155
    6256std::unique_ptr<GLContextGLX> GLContextGLX::createPbufferContext(GLXContext sharingContext)
    6357{
    64     int fbConfigAttributes[] = {
     58    static const int fbConfigAttributes[] = {
    6559        GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT,
    6660        GLX_RENDER_TYPE, GLX_RGBA_BIT,
     
    7569    int returnedElements;
    7670    Display* display = downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native();
    77     GLXFBConfig* configs = glXChooseFBConfig(display, 0, fbConfigAttributes, &returnedElements);
    78     if (!returnedElements) {
    79         XFree(configs);
    80         return nullptr;
    81     }
     71    XUniquePtr<GLXFBConfig> configs(glXChooseFBConfig(display, 0, fbConfigAttributes, &returnedElements));
     72    if (!returnedElements)
     73        return nullptr;
    8274
    8375    // We will be rendering to a texture, so our pbuffer does not need to be large.
    8476    static const int pbufferAttributes[] = { GLX_PBUFFER_WIDTH, 1, GLX_PBUFFER_HEIGHT, 1, 0 };
    85     GLXPbuffer pbuffer = glXCreatePbuffer(display, configs[0], pbufferAttributes);
    86     if (!pbuffer) {
    87         XFree(configs);
    88         return nullptr;
    89     }
    90 
    91     GLXContext context = glXCreateNewContext(display, configs[0], GLX_RGBA_TYPE, sharingContext, GL_TRUE);
    92     XFree(configs);
    93     if (!context) {
    94         glXDestroyPbuffer(display, pbuffer);
    95         return nullptr;
    96     }
    97 
    98     // GLXPbuffer and XID are both the same types underneath, so we have to share
    99     // a constructor here with the window path.
    100     auto contextWrapper = std::make_unique<GLContextGLX>(context);
    101     contextWrapper->m_pbuffer = pbuffer;
    102     return WTF::move(contextWrapper);
     77    XUniqueGLXPbuffer pbuffer(glXCreatePbuffer(display, configs.get()[0], pbufferAttributes));
     78    if (!pbuffer)
     79        return nullptr;
     80
     81    XUniqueGLXContext context(glXCreateNewContext(display, configs.get()[0], GLX_RGBA_TYPE, sharingContext, GL_TRUE));
     82    if (!context)
     83        return nullptr;
     84
     85    return std::make_unique<GLContextGLX>(WTF::move(context), WTF::move(pbuffer));
    10386}
    10487
     
    11598
    11699    Display* display = downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native();
    117     XVisualInfo* visualInfo = glXChooseVisual(display, DefaultScreen(display), visualAttributes);
     100    XUniquePtr<XVisualInfo> visualInfo(glXChooseVisual(display, DefaultScreen(display), visualAttributes));
    118101    if (!visualInfo)
    119102        return nullptr;
    120103
    121     GLXContext context = glXCreateContext(display, visualInfo, sharingContext, GL_TRUE);
    122     if (!context) {
    123         XFree(visualInfo);
    124         return nullptr;
    125     }
    126 
    127     Pixmap pixmap = XCreatePixmap(display, DefaultRootWindow(display), 1, 1, visualInfo->depth);
    128     if (!pixmap) {
    129         XFree(visualInfo);
    130         return nullptr;
    131     }
    132 
    133     GLXPixmap glxPixmap = glXCreateGLXPixmap(display, visualInfo, pixmap);
    134     if (!glxPixmap) {
    135         XFreePixmap(display, pixmap);
    136         XFree(visualInfo);
    137         return nullptr;
    138     }
    139 
    140     XFree(visualInfo);
    141     return std::make_unique<GLContextGLX>(context, pixmap, glxPixmap);
     104    XUniqueGLXContext context(glXCreateContext(display, visualInfo.get(), sharingContext, GL_TRUE));
     105    if (!context)
     106        return nullptr;
     107
     108    XUniquePixmap pixmap(XCreatePixmap(display, DefaultRootWindow(display), 1, 1, visualInfo->depth));
     109    if (!pixmap)
     110        return nullptr;
     111
     112    XUniqueGLXPixmap glxPixmap(glXCreateGLXPixmap(display, visualInfo.get(), pixmap.get()));
     113    if (!glxPixmap)
     114        return nullptr;
     115
     116    return std::make_unique<GLContextGLX>(WTF::move(context), WTF::move(pixmap), WTF::move(glxPixmap));
    142117}
    143118
     
    153128        return nullptr;
    154129
    155     GLXContext glxSharingContext = sharingContext ? static_cast<GLContextGLX*>(sharingContext)->m_context : 0;
     130    GLXContext glxSharingContext = sharingContext ? static_cast<GLContextGLX*>(sharingContext)->m_context.get() : nullptr;
    156131    auto context = window ? createWindowContext(window, sharingContext) : nullptr;
    157132    if (!context)
     
    165140}
    166141
    167 GLContextGLX::GLContextGLX(GLXContext context)
    168     : m_context(context)
    169     , m_window(0)
    170     , m_pbuffer(0)
    171     , m_pixmap(0)
    172     , m_glxPixmap(0)
    173     , m_cairoDevice(0)
    174 {
    175 }
    176 
    177 GLContextGLX::GLContextGLX(GLXContext context, Pixmap pixmap, GLXPixmap glxPixmap)
    178     : m_context(context)
    179     , m_window(0)
    180     , m_pbuffer(0)
    181     , m_pixmap(pixmap)
    182     , m_glxPixmap(glxPixmap)
    183     , m_cairoDevice(0)
     142GLContextGLX::GLContextGLX(XUniqueGLXContext&& context, XID window)
     143    : m_context(WTF::move(context))
     144    , m_window(window)
     145{
     146}
     147
     148GLContextGLX::GLContextGLX(XUniqueGLXContext&& context, XUniqueGLXPbuffer&& pbuffer)
     149    : m_context(WTF::move(context))
     150    , m_pbuffer(WTF::move(pbuffer))
     151{
     152}
     153
     154GLContextGLX::GLContextGLX(XUniqueGLXContext&& context, XUniquePixmap&& pixmap, XUniqueGLXPixmap&& glxPixmap)
     155    : m_context(WTF::move(context))
     156    , m_pixmap(WTF::move(pixmap))
     157    , m_glxPixmap(WTF::move(glxPixmap))
    184158{
    185159}
     
    190164        cairo_device_destroy(m_cairoDevice);
    191165
    192     Display* display = downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native();
    193166    if (m_context) {
    194167        // This may be necessary to prevent crashes with NVidia's closed source drivers. Originally
    195168        // from Mozilla's 3D canvas implementation at: http://bitbucket.org/ilmari/canvas3d/
     169        Display* display = downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native();
    196170        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
    197171        glXMakeCurrent(display, None, None);
    198         glXDestroyContext(display, m_context);
    199     }
    200 
    201     if (m_pbuffer) {
    202         glXDestroyPbuffer(display, m_pbuffer);
    203         m_pbuffer = 0;
    204     }
    205     if (m_glxPixmap) {
    206         glXDestroyGLXPixmap(display, m_glxPixmap);
    207         m_glxPixmap = 0;
    208     }
    209     if (m_pixmap) {
    210         XFreePixmap(display, m_pixmap);
    211         m_pixmap = 0;
    212172    }
    213173}
     
    238198
    239199    GLContext::makeContextCurrent();
    240     if (glXGetCurrentContext() == m_context)
     200    if (glXGetCurrentContext() == m_context.get())
    241201        return true;
    242202
    243203    Display* display = downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native();
    244204    if (m_window)
    245         return glXMakeCurrent(display, m_window, m_context);
     205        return glXMakeCurrent(display, m_window, m_context.get());
    246206
    247207    if (m_pbuffer)
    248         return glXMakeCurrent(display, m_pbuffer, m_context);
    249 
    250     return ::glXMakeCurrent(display, m_glxPixmap, m_context);
     208        return glXMakeCurrent(display, m_pbuffer.get(), m_context.get());
     209
     210    return ::glXMakeCurrent(display, m_glxPixmap.get(), m_context.get());
    251211}
    252212
     
    268228
    269229#if ENABLE(ACCELERATED_2D_CANVAS)
    270     m_cairoDevice = cairo_glx_device_create(downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native(), m_context);
     230    m_cairoDevice = cairo_glx_device_create(downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native(), m_context.get());
    271231#endif
    272232
     
    277237PlatformGraphicsContext3D GLContextGLX::platformContext()
    278238{
    279     return m_context;
     239    return m_context.get();
    280240}
    281241#endif
  • trunk/Source/WebCore/platform/graphics/glx/GLContextGLX.h

    r183432 r184197  
    2424
    2525#include "GLContext.h"
     26#include "XUniquePtr.h"
     27#include "XUniqueResource.h"
    2628
    27 typedef struct __GLXcontextRec* GLXContext;
    28 typedef unsigned long GLXPbuffer;
    29 typedef unsigned long GLXPixmap;
    3029typedef unsigned char GLubyte;
    31 typedef unsigned long Pixmap;
    3230typedef unsigned long XID;
    3331typedef void* ContextKeyType;
     
    4139    static std::unique_ptr<GLContextGLX> createWindowContext(XID window, GLContext* sharingContext);
    4240
    43     GLContextGLX(GLXContext);
    44     GLContextGLX(GLXContext, Pixmap, GLXPixmap);
     41    GLContextGLX(XUniqueGLXContext&&, XID);
     42    GLContextGLX(XUniqueGLXContext&&, XUniqueGLXPbuffer&&);
     43    GLContextGLX(XUniqueGLXContext&&, XUniquePixmap&&, XUniqueGLXPixmap&&);
    4544    virtual ~GLContextGLX();
    4645    virtual bool makeContextCurrent();
     
    6059    static std::unique_ptr<GLContextGLX> createPixmapContext(GLXContext sharingContext);
    6160
    62     GLXContext m_context;
    63     XID m_window;
    64     GLXPbuffer m_pbuffer;
    65     Pixmap m_pixmap;
    66     GLXPixmap m_glxPixmap;
    67     cairo_device_t* m_cairoDevice;
     61    XUniqueGLXContext m_context;
     62    XID m_window { 0 };
     63    XUniqueGLXPbuffer m_pbuffer;
     64    XUniquePixmap m_pixmap;
     65    XUniqueGLXPixmap m_glxPixmap;
     66    cairo_device_t* m_cairoDevice { nullptr };
    6867};
    6968
  • trunk/Source/WebCore/platform/graphics/surfaces/egl/EGLXSurface.cpp

    r183868 r184197  
    142142EGLXTransportSurfaceClient::EGLXTransportSurfaceClient(const PlatformBufferHandle handle, const IntSize& size, bool hasAlpha)
    143143    : GLTransportSurfaceClient()
    144     , m_image(0)
    145144    , m_size(size)
    146145    , m_totalBytes(0)
     
    198197
    199198    eglWaitGL();
    200 
    201     if (m_image) {
    202         XDestroyImage(m_image);
    203         m_image = 0;
    204     }
     199    m_image = nullptr;
    205200}
    206201
     
    215210
    216211    // Fallback to use XImage in case EGLImage and TextureToPixmap are not supported.
    217     m_image = XGetImage(NativeWrapper::nativeDisplay(), m_handle, 0, 0, m_size.width(), m_size.height(), AllPlanes, ZPixmap);
     212    m_image.reset(XGetImage(NativeWrapper::nativeDisplay(), m_handle, 0, 0, m_size.width(), m_size.height(), AllPlanes, ZPixmap));
    218213
    219214#if USE(OPENGL_ES_2)
     
    226221    glTexImage2D(GL_TEXTURE_2D, 0, m_format, m_size.width(), m_size.height(), 0, m_format, GL_UNSIGNED_BYTE, m_image->data);
    227222
    228     if (m_image) {
    229         XDestroyImage(m_image);
    230         m_image = 0;
    231     }
     223    m_image = nullptr;
    232224}
    233225
  • trunk/Source/WebCore/platform/graphics/surfaces/egl/EGLXSurface.h

    r177429 r184197  
    3030
    3131#include "EGLSurface.h"
     32#include "XUniquePtr.h"
    3233#include <glx/X11Helper.h>
    3334
    3435namespace WebCore {
    3536
    36 typedef X11Helper NativeWrapper;
    3737typedef Pixmap NativePixmap;
    3838
     
    7575
    7676private:
    77     XImage* m_image;
     77    XUniquePtr<XImage> m_image;
    7878    IntSize m_size;
    7979    PlatformBufferHandle m_handle;
  • trunk/Source/WebCore/platform/graphics/surfaces/glx/GLXConfigSelector.h

    r183265 r184197  
    3030
    3131#include "X11Helper.h"
     32#include "XUniquePtr.h"
    3233#include <opengl/GLDefs.h>
    3334#include <opengl/GLPlatformSurface.h>
     
    141142    {
    142143        int numAvailableConfigs;
    143         std::unique_ptr<GLXFBConfig[], X11Deleter> temp(glXChooseFBConfig(X11Helper::nativeDisplay(), DefaultScreen(X11Helper::nativeDisplay()), attributes, &numAvailableConfigs));
     144        XUniquePtr<GLXFBConfig> temp(glXChooseFBConfig(X11Helper::nativeDisplay(), DefaultScreen(X11Helper::nativeDisplay()), attributes, &numAvailableConfigs));
    144145
    145146        if (!numAvailableConfigs || !temp.get())
     
    147148
    148149        for (int i = 0; i < numAvailableConfigs; ++i) {
    149             std::unique_ptr<XVisualInfo, X11Deleter> scopedVisualInfo { glXGetVisualFromFBConfig(X11Helper::nativeDisplay(), temp[i]) };
     150            XUniquePtr<XVisualInfo> scopedVisualInfo { glXGetVisualFromFBConfig(X11Helper::nativeDisplay(), temp.get()[i]) };
    150151            if (!scopedVisualInfo.get())
    151152                continue;
     
    158159                    if (m_attributes & GLPlatformSurface::SupportAlpha) {
    159160                        if (scopedVisualInfo->depth == depth && format->direct.alphaMask > 0)
    160                             return temp[i];
     161                            return temp.get()[i];
    161162                    } else if (!format->direct.alphaMask)
    162                         return temp[i];
     163                        return temp.get()[i];
    163164                }
    164165            }
    165166#endif
    166167            if (scopedVisualInfo->depth == depth)
    167                 return temp[i];
     168                return temp.get()[i];
    168169        }
    169170
    170171        // Did not find any visual supporting alpha, select the first available config.
    171         std::unique_ptr<XVisualInfo, X11Deleter> scopedVisualInfo { glXGetVisualFromFBConfig(X11Helper::nativeDisplay(), temp[0]) };
     172        XUniquePtr<XVisualInfo> scopedVisualInfo { glXGetVisualFromFBConfig(X11Helper::nativeDisplay(), temp.get()[0]) };
    172173
    173174        if ((m_attributes & GLPlatformSurface::SupportAlpha) && (scopedVisualInfo->depth != 32))
    174175            m_attributes &= ~GLPlatformSurface::SupportAlpha;
    175176
    176         return temp[0];
     177        return temp.get()[0];
    177178    }
    178179
     
    180181    {
    181182        int numAvailableConfigs;
    182         std::unique_ptr<GLXFBConfig[], X11Deleter> temp(glXChooseFBConfig(X11Helper::nativeDisplay(), DefaultScreen(X11Helper::nativeDisplay()), attributes, &numAvailableConfigs));
     183        XUniquePtr<GLXFBConfig> temp(glXChooseFBConfig(X11Helper::nativeDisplay(), DefaultScreen(X11Helper::nativeDisplay()), attributes, &numAvailableConfigs));
    183184
    184185        if (!numAvailableConfigs || !temp.get())
     
    186187
    187188        for (int i = 0; i < numAvailableConfigs; ++i) {
    188             std::unique_ptr<XVisualInfo, X11Deleter> scopedVisualInfo { glXGetVisualFromFBConfig(X11Helper::nativeDisplay(), temp[i]) };
     189            XUniquePtr<XVisualInfo> scopedVisualInfo { glXGetVisualFromFBConfig(X11Helper::nativeDisplay(), temp.get()[i]) };
    189190            if (!scopedVisualInfo.get())
    190191                continue;
    191192
    192193            if (id && scopedVisualInfo->depth == depth && scopedVisualInfo->visualid == id)
    193                 return temp[i];
     194                return temp.get()[i];
    194195        }
    195196
  • trunk/Source/WebCore/platform/graphics/surfaces/glx/GLXSurface.cpp

    r183868 r184197  
    2929#if USE(GLX)
    3030
     31#include "XUniquePtr.h"
     32
    3133namespace WebCore {
    3234
     
    6769    attributes |= GLPlatformSurface::DoubleBuffered;
    6870    m_configSelector = std::make_unique<GLXConfigSelector>(attributes);
    69     std::unique_ptr<XVisualInfo, X11Deleter> visInfo(m_configSelector->visualInfo(m_configSelector->surfaceContextConfig()));
     71    XUniquePtr<XVisualInfo> visInfo(m_configSelector->visualInfo(m_configSelector->surfaceContextConfig()));
    7072
    7173    if (!visInfo.get()) {
     
    143145    m_configSelector = std::make_unique<GLXConfigSelector>(attributes);
    144146
    145     std::unique_ptr<XVisualInfo, X11Deleter> visualInfo(m_configSelector->visualInfo(m_configSelector->pixmapContextConfig()));
     147    XUniquePtr<XVisualInfo> visualInfo(m_configSelector->visualInfo(m_configSelector->pixmapContextConfig()));
    146148    X11Helper::createPixmap(&m_pixmap, *visualInfo.get());
    147149
  • trunk/Source/WebCore/platform/graphics/surfaces/glx/X11Helper.cpp

    r183731 r184197  
    2828
    2929#include "PlatformDisplayX11.h"
     30#include "XUniquePtr.h"
    3031
    3132namespace WebCore {
     
    224225    visualInfoTemplate.visualid = visualId;
    225226    int matchingCount = 0;
    226     std::unique_ptr<XVisualInfo, X11Deleter> matchingVisuals(XGetVisualInfo(nativeDisplay(), VisualIDMask, &visualInfoTemplate, &matchingCount));
     227    XUniquePtr<XVisualInfo> matchingVisuals(XGetVisualInfo(nativeDisplay(), VisualIDMask, &visualInfoTemplate, &matchingCount));
    227228    XVisualInfo* foundVisual = 0;
    228229
     
    261262    visualInfoTemplate.visualid = visualId;
    262263    int matchingCount = 0;
    263     std::unique_ptr<XVisualInfo, X11Deleter> matchingVisuals(XGetVisualInfo(nativeDisplay(), VisualIDMask, &visualInfoTemplate, &matchingCount));
     264    XUniquePtr<XVisualInfo> matchingVisuals(XGetVisualInfo(nativeDisplay(), VisualIDMask, &visualInfoTemplate, &matchingCount));
    264265    XVisualInfo* foundVisual = 0;
    265266    int requiredDepth = hasAlpha ? 32 : 24;
  • trunk/Source/WebCore/platform/graphics/surfaces/glx/X11Helper.h

    r183265 r184197  
    4343namespace WebCore {
    4444
    45 class X11Deleter {
    46 public:
    47     template<typename T> void operator()(T* resource)
    48     {
    49         if (resource)
    50             XFree(resource);
    51     }
    52 };
    53 
    5445class X11Helper {
    5546public:
  • trunk/Source/WebKit2/ChangeLog

    r184151 r184197  
     12015-05-08  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [X11] Add XUniquePtr and XUniqueResource to automatically free X resources
     4        https://bugs.webkit.org/show_bug.cgi?id=144521
     5
     6        Reviewed by Darin Adler.
     7
     8        Use XUniquePtr and XUniqueResource to free X resources.
     9
     10        * PlatformEfl.cmake: Add Source/WebCore/platform/graphics/x11 dir
     11        to the include dir list.
     12        * PlatformGTK.cmake: Ditto.
     13        * UIProcess/cairo/BackingStoreCairo.cpp:
     14        (WebKit::BackingStore::createBackend): Do not pass the display to
     15        the BackingStoreBackendCairoX11 constructor.
     16        * UIProcess/gtk/RedirectedXCompositeWindow.cpp:
     17        (WebKit::RedirectedXCompositeWindow::RedirectedXCompositeWindow):
     18        (WebKit::RedirectedXCompositeWindow::~RedirectedXCompositeWindow):
     19        (WebKit::RedirectedXCompositeWindow::resize):
     20        (WebKit::RedirectedXCompositeWindow::cleanupPixmapAndPixmapSurface):
     21        (WebKit::RedirectedXCompositeWindow::surface):
     22        * UIProcess/gtk/RedirectedXCompositeWindow.h:
     23        (WebKit::RedirectedXCompositeWindow::windowID):
     24        * WebProcess/Plugins/Netscape/NetscapePlugin.h:
     25        * WebProcess/Plugins/Netscape/x11/NetscapePluginX11.cpp:
     26        (WebKit::NetscapePlugin::platformPostInitializeWindowless):
     27        (WebKit::NetscapePlugin::platformDestroy):
     28        (WebKit::NetscapePlugin::platformGeometryDidChange):
     29        (WebKit::NetscapePlugin::platformPaint):
     30
    1312015-05-11  Dan Bernstein  <mitz@apple.com>
    232
  • trunk/Source/WebKit2/PlatformEfl.cmake

    r183737 r184197  
    227227    "${WEBCORE_DIR}/platform/graphics/efl"
    228228    "${WEBCORE_DIR}/platform/graphics/opentype"
     229    "${WEBCORE_DIR}/platform/graphics/x11"
    229230    "${WEBCORE_DIR}/platform/network/soup"
    230231    "${WEBCORE_DIR}/platform/text/enchant"
  • trunk/Source/WebKit2/PlatformGTK.cmake

    r183936 r184197  
    456456    "${WEBCORE_DIR}/platform/graphics/cairo"
    457457    "${WEBCORE_DIR}/platform/graphics/opentype"
     458    "${WEBCORE_DIR}/platform/graphics/x11"
    458459    "${WEBCORE_DIR}/platform/network/soup"
    459460    "${WEBCORE_DIR}/platform/text/enchant"
  • trunk/Source/WebKit2/UIProcess/cairo/BackingStoreCairo.cpp

    r183731 r184197  
    5555        GdkScreen* screen = gdk_visual_get_screen(visual);
    5656        ASSERT(downcast<PlatformDisplayX11>(sharedDisplay).native() == GDK_SCREEN_XDISPLAY(screen));
    57         return std::make_unique<BackingStoreBackendCairoX11>(downcast<PlatformDisplayX11>(sharedDisplay).native(), GDK_WINDOW_XID(gdk_screen_get_root_window(screen)),
     57        return std::make_unique<BackingStoreBackendCairoX11>(GDK_WINDOW_XID(gdk_screen_get_root_window(screen)),
    5858            GDK_VISUAL_XVISUAL(visual), gdk_visual_get_depth(visual), m_size, m_deviceScaleFactor);
    5959    }
  • trunk/Source/WebKit2/UIProcess/gtk/RedirectedXCompositeWindow.cpp

    r181847 r184197  
    3030#if USE(REDIRECTED_XCOMPOSITE_WINDOW)
    3131
     32#include <X11/Xlib.h>
    3233#include <X11/extensions/Xcomposite.h>
    3334#include <X11/extensions/Xdamage.h>
     
    136137RedirectedXCompositeWindow::RedirectedXCompositeWindow(GdkWindow* parentWindow, std::function<void()> damageNotify)
    137138    : m_display(GDK_DISPLAY_XDISPLAY(gdk_window_get_display(parentWindow)))
    138     , m_window(0)
    139     , m_parentWindow(0)
    140     , m_pixmap(0)
    141     , m_damage(0)
    142139    , m_needsNewPixmapAfterResize(false)
    143140{
     141    ASSERT(downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native() == m_display);
    144142    Screen* screen = DefaultScreenOfDisplay(m_display);
    145143
    146144    GdkVisual* visual = gdk_window_get_visual(parentWindow);
    147     Colormap colormap = XCreateColormap(m_display, RootWindowOfScreen(screen), GDK_VISUAL_XVISUAL(visual), AllocNone);
     145    XUniqueColormap colormap(XCreateColormap(m_display, RootWindowOfScreen(screen), GDK_VISUAL_XVISUAL(visual), AllocNone));
    148146
    149147    // This is based on code from Chromium: src/content/common/gpu/image_transport_surface_linux.cc
    150148    XSetWindowAttributes windowAttributes;
    151149    windowAttributes.override_redirect = True;
    152     windowAttributes.colormap = colormap;
     150    windowAttributes.colormap = colormap.get();
    153151
    154152    // CWBorderPixel must be present when the depth doesn't match the parent's one.
     
    165163        CWOverrideRedirect | CWColormap | CWBorderPixel,
    166164        &windowAttributes);
    167     XMapWindow(m_display, m_parentWindow);
     165    XMapWindow(m_display, m_parentWindow.get());
    168166
    169167    windowAttributes.event_mask = StructureNotifyMask;
     
    171169    // Create the window of at last 1x1 since X doesn't allow to create empty windows.
    172170    m_window = XCreateWindow(m_display,
    173         m_parentWindow,
     171        m_parentWindow.get(),
    174172        0, 0,
    175173        std::max(1, m_size.width()),
     
    181179        CWEventMask,
    182180        &windowAttributes);
    183     XMapWindow(m_display, m_window);
    184 
    185     XFreeColormap(m_display, colormap);
    186 
    187     xDamageNotifier().add(m_window, WTF::move(damageNotify));
     181    XMapWindow(m_display, m_window.get());
     182
     183    xDamageNotifier().add(m_window.get(), WTF::move(damageNotify));
    188184
    189185    while (1) {
    190186        XEvent event;
    191         XWindowEvent(m_display, m_window, StructureNotifyMask, &event);
    192         if (event.type == MapNotify && event.xmap.window == m_window)
     187        XWindowEvent(m_display, m_window.get(), StructureNotifyMask, &event);
     188        if (event.type == MapNotify && event.xmap.window == m_window.get())
    193189            break;
    194190    }
    195     XSelectInput(m_display, m_window, NoEventMask);
    196     XCompositeRedirectWindow(m_display, m_window, CompositeRedirectManual);
    197     m_damage = XDamageCreate(m_display, m_window, XDamageReportNonEmpty);
     191    XSelectInput(m_display, m_window.get(), NoEventMask);
     192    XCompositeRedirectWindow(m_display, m_window.get(), CompositeRedirectManual);
     193    m_damage = XDamageCreate(m_display, m_window.get(), XDamageReportNonEmpty);
    198194}
    199195
     
    205201    ASSERT(m_parentWindow);
    206202
    207     xDamageNotifier().remove(m_window);
    208 
    209     XDamageDestroy(m_display, m_damage);
    210     XDestroyWindow(m_display, m_window);
    211     XDestroyWindow(m_display, m_parentWindow);
    212     cleanupPixmapAndPixmapSurface();
     203    xDamageNotifier().remove(m_window.get());
     204
     205    // Explicitly reset these because we need to ensure it happens in this order.
     206    m_damage.reset();
     207    m_window.reset();
     208    m_parentWindow.reset();
    213209}
    214210
     
    219215
    220216    // Resize the window to at last 1x1 since X doesn't allow to create empty windows.
    221     XResizeWindow(m_display, m_window, std::max(1, size.width()), std::max(1, size.height()));
     217    XResizeWindow(m_display, m_window.get(), std::max(1, size.width()), std::max(1, size.height()));
    222218    XFlush(m_display);
    223219
     
    233229        return;
    234230
    235     XFreePixmap(m_display, m_pixmap);
    236     m_pixmap = 0;
    237231    m_surface = nullptr;
     232    m_pixmap.reset();
    238233}
    239234
     
    248243    m_needsNewPixmapAfterResize = false;
    249244
    250     Pixmap newPixmap = XCompositeNameWindowPixmap(m_display, m_window);
     245    XUniquePixmap newPixmap(XCompositeNameWindowPixmap(m_display, m_window.get()));
    251246    if (!newPixmap) {
    252247        cleanupPixmapAndPixmapSurface();
     
    255250
    256251    XWindowAttributes windowAttributes;
    257     if (!XGetWindowAttributes(m_display, m_window, &windowAttributes)) {
     252    if (!XGetWindowAttributes(m_display, m_window.get(), &windowAttributes)) {
    258253        cleanupPixmapAndPixmapSurface();
    259         XFreePixmap(m_display, newPixmap);
    260254        return nullptr;
    261255    }
    262256
    263     RefPtr<cairo_surface_t> newSurface = adoptRef(cairo_xlib_surface_create(m_display, newPixmap, windowAttributes.visual, m_size.width(), m_size.height()));
     257    RefPtr<cairo_surface_t> newSurface = adoptRef(cairo_xlib_surface_create(m_display, newPixmap.get(), windowAttributes.visual, m_size.width(), m_size.height()));
    264258
    265259    // Nvidia drivers seem to prepare their redirected window pixmap asynchronously, so for a few fractions
     
    276270
    277271    cleanupPixmapAndPixmapSurface();
    278     m_pixmap = newPixmap;
     272    m_pixmap = WTF::move(newPixmap);
    279273    m_surface = newSurface;
    280274    return m_surface.get();
  • trunk/Source/WebKit2/UIProcess/gtk/RedirectedXCompositeWindow.h

    r181847 r184197  
    3232#include <WebCore/IntSize.h>
    3333#include <WebCore/RefPtrCairo.h>
    34 #include <X11/Xlib.h>
     34#include <WebCore/XUniqueResource.h>
    3535#include <functional>
    3636
    3737typedef struct _GdkWindow GdkWindow;
    38 typedef unsigned long Damage;
     38typedef struct _XDisplay Display;
     39typedef unsigned long Window;
    3940
    4041namespace WebKit {
     
    4546    ~RedirectedXCompositeWindow();
    4647
    47     Window windowID() const { return m_window; }
     48    Window windowID() const { return m_window.get(); }
    4849    void resize(const WebCore::IntSize&);
    4950    cairo_surface_t* surface();
     
    5556    Display* m_display;
    5657    WebCore::IntSize m_size;
    57     Window m_window;
    58     Window m_parentWindow;
    59     Pixmap m_pixmap;
    60     Damage m_damage;
     58    WebCore::XUniqueWindow m_window;
     59    WebCore::XUniqueWindow m_parentWindow;
     60    WebCore::XUniquePixmap m_pixmap;
     61    WebCore::XUniqueDamage m_damage;
    6162    RefPtr<cairo_surface_t> m_surface;
    6263    bool m_needsNewPixmapAfterResize;
  • trunk/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h

    r183941 r184197  
    4141#if PLATFORM(COCOA)
    4242#include "WebHitTestResult.h"
     43#endif
     44
     45#if PLUGIN_ARCHITECTURE(X11)
     46#include <WebCore/XUniqueResource.h>
    4347#endif
    4448
     
    389393#endif
    390394#elif PLUGIN_ARCHITECTURE(X11)
    391     Pixmap m_drawable;
     395    WebCore::XUniquePixmap m_drawable;
    392396    Display* m_pluginDisplay;
    393397#if PLATFORM(GTK)
  • trunk/Source/WebKit2/WebProcess/Plugins/Netscape/x11/NetscapePluginX11.cpp

    r183731 r184197  
    3535#include <WebCore/NotImplemented.h>
    3636#include <WebCore/PlatformDisplayX11.h>
     37#include <WebCore/XUniquePtr.h>
    3738
    3839#if PLATFORM(GTK)
     
    176177    visualTemplate.c_class = TrueColor;
    177178    int numMatching;
    178     XVisualInfo* visualInfo = XGetVisualInfo(display, VisualScreenMask | VisualDepthMask | VisualClassMask,
    179                                              &visualTemplate, &numMatching);
     179    XUniquePtr<XVisualInfo> visualInfo(XGetVisualInfo(display, VisualScreenMask | VisualDepthMask | VisualClassMask, &visualTemplate, &numMatching));
    180180    ASSERT(visualInfo);
    181     Visual* visual = visualInfo[0].visual;
     181    Visual* visual = visualInfo.get()[0].visual;
    182182    ASSERT(visual);
    183     XFree(visualInfo);
    184183
    185184    callbackStruct->visual = visual;
     
    233232    delete callbackStruct;
    234233
    235     if (m_drawable) {
    236         XFreePixmap(hostDisplay, m_drawable);
    237         m_drawable = 0;
    238     }
     234    m_drawable.reset();
    239235
    240236#if PLATFORM(GTK)
     
    263259    }
    264260
    265     Display* display = x11HostDisplay();
    266     if (m_drawable)
    267         XFreePixmap(display, m_drawable);
    268 
    269     if (m_pluginSize.isEmpty()) {
    270         m_drawable = 0;
    271         return;
    272     }
    273 
    274     m_drawable = XCreatePixmap(display, rootWindowID(), m_pluginSize.width(), m_pluginSize.height(), displayDepth());
    275 
    276     XSync(display, false); // Make sure that the server knows about the Drawable.
     261    m_drawable.reset();
     262    if (m_pluginSize.isEmpty())
     263        return;
     264
     265    m_drawable = XCreatePixmap(x11HostDisplay(), rootWindowID(), m_pluginSize.width(), m_pluginSize.height(), displayDepth());
     266    XSync(x11HostDisplay(), false); // Make sure that the server knows about the Drawable.
    277267}
    278268
     
    308298    exposeEvent.type = GraphicsExpose;
    309299    exposeEvent.display = x11HostDisplay();
    310     exposeEvent.drawable = m_drawable;
     300    exposeEvent.drawable = m_drawable.get();
    311301
    312302    IntRect exposedRect(dirtyRect);
     
    325315
    326316#if PLATFORM(GTK) || (PLATFORM(EFL) && USE(CAIRO))
    327     RefPtr<cairo_surface_t> drawableSurface = adoptRef(cairo_xlib_surface_create(m_pluginDisplay,
    328                                                                                  m_drawable,
    329                                                                                  static_cast<NPSetWindowCallbackStruct*>(m_npWindow.ws_info)->visual,
    330                                                                                  m_pluginSize.width(),
    331                                                                                  m_pluginSize.height()));
     317    RefPtr<cairo_surface_t> drawableSurface = adoptRef(cairo_xlib_surface_create(m_pluginDisplay, m_drawable.get(),
     318        static_cast<NPSetWindowCallbackStruct*>(m_npWindow.ws_info)->visual, m_pluginSize.width(), m_pluginSize.height()));
    332319    cairo_t* cr = context->platformContext()->cr();
    333320    cairo_save(cr);
Note: See TracChangeset for help on using the changeset viewer.