Changeset 184197 in webkit
- Timestamp:
- May 12, 2015, 4:11:00 AM (10 years ago)
- Location:
- trunk/Source
- Files:
-
- 3 added
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r184193 r184197 1 2015-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 1 72 2015-05-12 Zan Dobersek <zdobersek@igalia.com> 2 73 -
trunk/Source/WebCore/PlatformEfl.cmake
r183807 r184197 198 198 199 199 platform/graphics/x11/PlatformDisplayX11.cpp 200 platform/graphics/x11/XUniqueResource.cpp 200 201 201 202 platform/image-decoders/ImageDecoder.cpp -
trunk/Source/WebCore/PlatformGTK.cmake
r183807 r184197 127 127 128 128 platform/graphics/x11/PlatformDisplayX11.cpp 129 platform/graphics/x11/XUniqueResource.cpp 129 130 130 131 platform/gtk/ErrorsGtk.cpp -
trunk/Source/WebCore/platform/graphics/cairo/BackingStoreBackendCairoX11.cpp
r175159 r184197 27 27 namespace WebCore { 28 28 29 BackingStoreBackendCairoX11::BackingStoreBackendCairoX11( Display* display,unsigned long rootWindowID, Visual* visual, int depth, const IntSize& size, float deviceScaleFactor)29 BackingStoreBackendCairoX11::BackingStoreBackendCairoX11(unsigned long rootWindowID, Visual* visual, int depth, const IntSize& size, float deviceScaleFactor) 30 30 : BackingStoreBackendCairo(size) 31 , m_display(display)32 31 { 33 32 IntSize scaledSize = size; 34 33 scaledSize.scale(deviceScaleFactor); 35 34 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)); 38 38 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())); 40 40 cairoSurfaceSetDeviceScale(m_surface.get(), deviceScaleFactor, deviceScaleFactor); 41 41 } … … 45 45 // The pixmap needs to exist when the surface is destroyed, so begin by clearing it. 46 46 m_surface.clear(); 47 XFreePixmap(m_display, m_pixmap);48 XFreeGC(m_display, m_gc);49 47 } 50 48 … … 66 64 67 65 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(), 69 67 targetRect.x() - scaledScrollOffset.width(), targetRect.y() - scaledScrollOffset.height(), 70 68 targetRect.width(), targetRect.height(), targetRect.x(), targetRect.y()); -
trunk/Source/WebCore/platform/graphics/cairo/BackingStoreBackendCairoX11.h
r175159 r184197 23 23 24 24 #if USE(CAIRO) && PLATFORM(X11) 25 #include <X11/Xlib.h> 25 #include "XUniquePtr.h" 26 #include "XUniqueResource.h" 26 27 27 28 namespace WebCore { … … 29 30 class BackingStoreBackendCairoX11 final : public BackingStoreBackendCairo { 30 31 public: 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); 32 33 virtual ~BackingStoreBackendCairoX11(); 33 34 … … 35 36 36 37 private: 37 Display* m_display; 38 Pixmap m_pixmap; 39 GC m_gc; 38 XUniquePixmap m_pixmap; 39 XUniqueGC m_gc; 40 40 }; 41 41 -
trunk/Source/WebCore/platform/graphics/glx/GLContextGLX.cpp
r183731 r184197 44 44 45 45 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); 60 54 } 61 55 62 56 std::unique_ptr<GLContextGLX> GLContextGLX::createPbufferContext(GLXContext sharingContext) 63 57 { 64 int fbConfigAttributes[] = {58 static const int fbConfigAttributes[] = { 65 59 GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT, 66 60 GLX_RENDER_TYPE, GLX_RGBA_BIT, … … 75 69 int returnedElements; 76 70 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; 82 74 83 75 // We will be rendering to a texture, so our pbuffer does not need to be large. 84 76 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)); 103 86 } 104 87 … … 115 98 116 99 Display* display = downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native(); 117 X VisualInfo* visualInfo = glXChooseVisual(display, DefaultScreen(display), visualAttributes);100 XUniquePtr<XVisualInfo> visualInfo(glXChooseVisual(display, DefaultScreen(display), visualAttributes)); 118 101 if (!visualInfo) 119 102 return nullptr; 120 103 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)); 142 117 } 143 118 … … 153 128 return nullptr; 154 129 155 GLXContext glxSharingContext = sharingContext ? static_cast<GLContextGLX*>(sharingContext)->m_context : 0;130 GLXContext glxSharingContext = sharingContext ? static_cast<GLContextGLX*>(sharingContext)->m_context.get() : nullptr; 156 131 auto context = window ? createWindowContext(window, sharingContext) : nullptr; 157 132 if (!context) … … 165 140 } 166 141 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) 142 GLContextGLX::GLContextGLX(XUniqueGLXContext&& context, XID window) 143 : m_context(WTF::move(context)) 144 , m_window(window) 145 { 146 } 147 148 GLContextGLX::GLContextGLX(XUniqueGLXContext&& context, XUniqueGLXPbuffer&& pbuffer) 149 : m_context(WTF::move(context)) 150 , m_pbuffer(WTF::move(pbuffer)) 151 { 152 } 153 154 GLContextGLX::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)) 184 158 { 185 159 } … … 190 164 cairo_device_destroy(m_cairoDevice); 191 165 192 Display* display = downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native();193 166 if (m_context) { 194 167 // This may be necessary to prevent crashes with NVidia's closed source drivers. Originally 195 168 // from Mozilla's 3D canvas implementation at: http://bitbucket.org/ilmari/canvas3d/ 169 Display* display = downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native(); 196 170 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 197 171 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;212 172 } 213 173 } … … 238 198 239 199 GLContext::makeContextCurrent(); 240 if (glXGetCurrentContext() == m_context )200 if (glXGetCurrentContext() == m_context.get()) 241 201 return true; 242 202 243 203 Display* display = downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native(); 244 204 if (m_window) 245 return glXMakeCurrent(display, m_window, m_context );205 return glXMakeCurrent(display, m_window, m_context.get()); 246 206 247 207 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()); 251 211 } 252 212 … … 268 228 269 229 #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()); 271 231 #endif 272 232 … … 277 237 PlatformGraphicsContext3D GLContextGLX::platformContext() 278 238 { 279 return m_context ;239 return m_context.get(); 280 240 } 281 241 #endif -
trunk/Source/WebCore/platform/graphics/glx/GLContextGLX.h
r183432 r184197 24 24 25 25 #include "GLContext.h" 26 #include "XUniquePtr.h" 27 #include "XUniqueResource.h" 26 28 27 typedef struct __GLXcontextRec* GLXContext;28 typedef unsigned long GLXPbuffer;29 typedef unsigned long GLXPixmap;30 29 typedef unsigned char GLubyte; 31 typedef unsigned long Pixmap;32 30 typedef unsigned long XID; 33 31 typedef void* ContextKeyType; … … 41 39 static std::unique_ptr<GLContextGLX> createWindowContext(XID window, GLContext* sharingContext); 42 40 43 GLContextGLX(GLXContext); 44 GLContextGLX(GLXContext, Pixmap, GLXPixmap); 41 GLContextGLX(XUniqueGLXContext&&, XID); 42 GLContextGLX(XUniqueGLXContext&&, XUniqueGLXPbuffer&&); 43 GLContextGLX(XUniqueGLXContext&&, XUniquePixmap&&, XUniqueGLXPixmap&&); 45 44 virtual ~GLContextGLX(); 46 45 virtual bool makeContextCurrent(); … … 60 59 static std::unique_ptr<GLContextGLX> createPixmapContext(GLXContext sharingContext); 61 60 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 }; 68 67 }; 69 68 -
trunk/Source/WebCore/platform/graphics/surfaces/egl/EGLXSurface.cpp
r183868 r184197 142 142 EGLXTransportSurfaceClient::EGLXTransportSurfaceClient(const PlatformBufferHandle handle, const IntSize& size, bool hasAlpha) 143 143 : GLTransportSurfaceClient() 144 , m_image(0)145 144 , m_size(size) 146 145 , m_totalBytes(0) … … 198 197 199 198 eglWaitGL(); 200 201 if (m_image) { 202 XDestroyImage(m_image); 203 m_image = 0; 204 } 199 m_image = nullptr; 205 200 } 206 201 … … 215 210 216 211 // 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)); 218 213 219 214 #if USE(OPENGL_ES_2) … … 226 221 glTexImage2D(GL_TEXTURE_2D, 0, m_format, m_size.width(), m_size.height(), 0, m_format, GL_UNSIGNED_BYTE, m_image->data); 227 222 228 if (m_image) { 229 XDestroyImage(m_image); 230 m_image = 0; 231 } 223 m_image = nullptr; 232 224 } 233 225 -
trunk/Source/WebCore/platform/graphics/surfaces/egl/EGLXSurface.h
r177429 r184197 30 30 31 31 #include "EGLSurface.h" 32 #include "XUniquePtr.h" 32 33 #include <glx/X11Helper.h> 33 34 34 35 namespace WebCore { 35 36 36 typedef X11Helper NativeWrapper;37 37 typedef Pixmap NativePixmap; 38 38 … … 75 75 76 76 private: 77 X Image*m_image;77 XUniquePtr<XImage> m_image; 78 78 IntSize m_size; 79 79 PlatformBufferHandle m_handle; -
trunk/Source/WebCore/platform/graphics/surfaces/glx/GLXConfigSelector.h
r183265 r184197 30 30 31 31 #include "X11Helper.h" 32 #include "XUniquePtr.h" 32 33 #include <opengl/GLDefs.h> 33 34 #include <opengl/GLPlatformSurface.h> … … 141 142 { 142 143 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)); 144 145 145 146 if (!numAvailableConfigs || !temp.get()) … … 147 148 148 149 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]) }; 150 151 if (!scopedVisualInfo.get()) 151 152 continue; … … 158 159 if (m_attributes & GLPlatformSurface::SupportAlpha) { 159 160 if (scopedVisualInfo->depth == depth && format->direct.alphaMask > 0) 160 return temp [i];161 return temp.get()[i]; 161 162 } else if (!format->direct.alphaMask) 162 return temp [i];163 return temp.get()[i]; 163 164 } 164 165 } 165 166 #endif 166 167 if (scopedVisualInfo->depth == depth) 167 return temp [i];168 return temp.get()[i]; 168 169 } 169 170 170 171 // 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]) }; 172 173 173 174 if ((m_attributes & GLPlatformSurface::SupportAlpha) && (scopedVisualInfo->depth != 32)) 174 175 m_attributes &= ~GLPlatformSurface::SupportAlpha; 175 176 176 return temp [0];177 return temp.get()[0]; 177 178 } 178 179 … … 180 181 { 181 182 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)); 183 184 184 185 if (!numAvailableConfigs || !temp.get()) … … 186 187 187 188 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]) }; 189 190 if (!scopedVisualInfo.get()) 190 191 continue; 191 192 192 193 if (id && scopedVisualInfo->depth == depth && scopedVisualInfo->visualid == id) 193 return temp [i];194 return temp.get()[i]; 194 195 } 195 196 -
trunk/Source/WebCore/platform/graphics/surfaces/glx/GLXSurface.cpp
r183868 r184197 29 29 #if USE(GLX) 30 30 31 #include "XUniquePtr.h" 32 31 33 namespace WebCore { 32 34 … … 67 69 attributes |= GLPlatformSurface::DoubleBuffered; 68 70 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())); 70 72 71 73 if (!visInfo.get()) { … … 143 145 m_configSelector = std::make_unique<GLXConfigSelector>(attributes); 144 146 145 std::unique_ptr<XVisualInfo, X11Deleter> visualInfo(m_configSelector->visualInfo(m_configSelector->pixmapContextConfig()));147 XUniquePtr<XVisualInfo> visualInfo(m_configSelector->visualInfo(m_configSelector->pixmapContextConfig())); 146 148 X11Helper::createPixmap(&m_pixmap, *visualInfo.get()); 147 149 -
trunk/Source/WebCore/platform/graphics/surfaces/glx/X11Helper.cpp
r183731 r184197 28 28 29 29 #include "PlatformDisplayX11.h" 30 #include "XUniquePtr.h" 30 31 31 32 namespace WebCore { … … 224 225 visualInfoTemplate.visualid = visualId; 225 226 int matchingCount = 0; 226 std::unique_ptr<XVisualInfo, X11Deleter> matchingVisuals(XGetVisualInfo(nativeDisplay(), VisualIDMask, &visualInfoTemplate, &matchingCount));227 XUniquePtr<XVisualInfo> matchingVisuals(XGetVisualInfo(nativeDisplay(), VisualIDMask, &visualInfoTemplate, &matchingCount)); 227 228 XVisualInfo* foundVisual = 0; 228 229 … … 261 262 visualInfoTemplate.visualid = visualId; 262 263 int matchingCount = 0; 263 std::unique_ptr<XVisualInfo, X11Deleter> matchingVisuals(XGetVisualInfo(nativeDisplay(), VisualIDMask, &visualInfoTemplate, &matchingCount));264 XUniquePtr<XVisualInfo> matchingVisuals(XGetVisualInfo(nativeDisplay(), VisualIDMask, &visualInfoTemplate, &matchingCount)); 264 265 XVisualInfo* foundVisual = 0; 265 266 int requiredDepth = hasAlpha ? 32 : 24; -
trunk/Source/WebCore/platform/graphics/surfaces/glx/X11Helper.h
r183265 r184197 43 43 namespace WebCore { 44 44 45 class X11Deleter {46 public:47 template<typename T> void operator()(T* resource)48 {49 if (resource)50 XFree(resource);51 }52 };53 54 45 class X11Helper { 55 46 public: -
trunk/Source/WebKit2/ChangeLog
r184151 r184197 1 2015-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 1 31 2015-05-11 Dan Bernstein <mitz@apple.com> 2 32 -
trunk/Source/WebKit2/PlatformEfl.cmake
r183737 r184197 227 227 "${WEBCORE_DIR}/platform/graphics/efl" 228 228 "${WEBCORE_DIR}/platform/graphics/opentype" 229 "${WEBCORE_DIR}/platform/graphics/x11" 229 230 "${WEBCORE_DIR}/platform/network/soup" 230 231 "${WEBCORE_DIR}/platform/text/enchant" -
trunk/Source/WebKit2/PlatformGTK.cmake
r183936 r184197 456 456 "${WEBCORE_DIR}/platform/graphics/cairo" 457 457 "${WEBCORE_DIR}/platform/graphics/opentype" 458 "${WEBCORE_DIR}/platform/graphics/x11" 458 459 "${WEBCORE_DIR}/platform/network/soup" 459 460 "${WEBCORE_DIR}/platform/text/enchant" -
trunk/Source/WebKit2/UIProcess/cairo/BackingStoreCairo.cpp
r183731 r184197 55 55 GdkScreen* screen = gdk_visual_get_screen(visual); 56 56 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)), 58 58 GDK_VISUAL_XVISUAL(visual), gdk_visual_get_depth(visual), m_size, m_deviceScaleFactor); 59 59 } -
trunk/Source/WebKit2/UIProcess/gtk/RedirectedXCompositeWindow.cpp
r181847 r184197 30 30 #if USE(REDIRECTED_XCOMPOSITE_WINDOW) 31 31 32 #include <X11/Xlib.h> 32 33 #include <X11/extensions/Xcomposite.h> 33 34 #include <X11/extensions/Xdamage.h> … … 136 137 RedirectedXCompositeWindow::RedirectedXCompositeWindow(GdkWindow* parentWindow, std::function<void()> damageNotify) 137 138 : 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)142 139 , m_needsNewPixmapAfterResize(false) 143 140 { 141 ASSERT(downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native() == m_display); 144 142 Screen* screen = DefaultScreenOfDisplay(m_display); 145 143 146 144 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)); 148 146 149 147 // This is based on code from Chromium: src/content/common/gpu/image_transport_surface_linux.cc 150 148 XSetWindowAttributes windowAttributes; 151 149 windowAttributes.override_redirect = True; 152 windowAttributes.colormap = colormap ;150 windowAttributes.colormap = colormap.get(); 153 151 154 152 // CWBorderPixel must be present when the depth doesn't match the parent's one. … … 165 163 CWOverrideRedirect | CWColormap | CWBorderPixel, 166 164 &windowAttributes); 167 XMapWindow(m_display, m_parentWindow );165 XMapWindow(m_display, m_parentWindow.get()); 168 166 169 167 windowAttributes.event_mask = StructureNotifyMask; … … 171 169 // Create the window of at last 1x1 since X doesn't allow to create empty windows. 172 170 m_window = XCreateWindow(m_display, 173 m_parentWindow ,171 m_parentWindow.get(), 174 172 0, 0, 175 173 std::max(1, m_size.width()), … … 181 179 CWEventMask, 182 180 &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)); 188 184 189 185 while (1) { 190 186 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()) 193 189 break; 194 190 } 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); 198 194 } 199 195 … … 205 201 ASSERT(m_parentWindow); 206 202 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(); 213 209 } 214 210 … … 219 215 220 216 // 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())); 222 218 XFlush(m_display); 223 219 … … 233 229 return; 234 230 235 XFreePixmap(m_display, m_pixmap);236 m_pixmap = 0;237 231 m_surface = nullptr; 232 m_pixmap.reset(); 238 233 } 239 234 … … 248 243 m_needsNewPixmapAfterResize = false; 249 244 250 Pixmap newPixmap = XCompositeNameWindowPixmap(m_display, m_window);245 XUniquePixmap newPixmap(XCompositeNameWindowPixmap(m_display, m_window.get())); 251 246 if (!newPixmap) { 252 247 cleanupPixmapAndPixmapSurface(); … … 255 250 256 251 XWindowAttributes windowAttributes; 257 if (!XGetWindowAttributes(m_display, m_window , &windowAttributes)) {252 if (!XGetWindowAttributes(m_display, m_window.get(), &windowAttributes)) { 258 253 cleanupPixmapAndPixmapSurface(); 259 XFreePixmap(m_display, newPixmap);260 254 return nullptr; 261 255 } 262 256 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())); 264 258 265 259 // Nvidia drivers seem to prepare their redirected window pixmap asynchronously, so for a few fractions … … 276 270 277 271 cleanupPixmapAndPixmapSurface(); 278 m_pixmap = newPixmap;272 m_pixmap = WTF::move(newPixmap); 279 273 m_surface = newSurface; 280 274 return m_surface.get(); -
trunk/Source/WebKit2/UIProcess/gtk/RedirectedXCompositeWindow.h
r181847 r184197 32 32 #include <WebCore/IntSize.h> 33 33 #include <WebCore/RefPtrCairo.h> 34 #include < X11/Xlib.h>34 #include <WebCore/XUniqueResource.h> 35 35 #include <functional> 36 36 37 37 typedef struct _GdkWindow GdkWindow; 38 typedef unsigned long Damage; 38 typedef struct _XDisplay Display; 39 typedef unsigned long Window; 39 40 40 41 namespace WebKit { … … 45 46 ~RedirectedXCompositeWindow(); 46 47 47 Window windowID() const { return m_window ; }48 Window windowID() const { return m_window.get(); } 48 49 void resize(const WebCore::IntSize&); 49 50 cairo_surface_t* surface(); … … 55 56 Display* m_display; 56 57 WebCore::IntSize m_size; 57 W indow m_window;58 W indow 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; 61 62 RefPtr<cairo_surface_t> m_surface; 62 63 bool m_needsNewPixmapAfterResize; -
trunk/Source/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h
r183941 r184197 41 41 #if PLATFORM(COCOA) 42 42 #include "WebHitTestResult.h" 43 #endif 44 45 #if PLUGIN_ARCHITECTURE(X11) 46 #include <WebCore/XUniqueResource.h> 43 47 #endif 44 48 … … 389 393 #endif 390 394 #elif PLUGIN_ARCHITECTURE(X11) 391 Pixmap m_drawable;395 WebCore::XUniquePixmap m_drawable; 392 396 Display* m_pluginDisplay; 393 397 #if PLATFORM(GTK) -
trunk/Source/WebKit2/WebProcess/Plugins/Netscape/x11/NetscapePluginX11.cpp
r183731 r184197 35 35 #include <WebCore/NotImplemented.h> 36 36 #include <WebCore/PlatformDisplayX11.h> 37 #include <WebCore/XUniquePtr.h> 37 38 38 39 #if PLATFORM(GTK) … … 176 177 visualTemplate.c_class = TrueColor; 177 178 int numMatching; 178 XVisualInfo* visualInfo = XGetVisualInfo(display, VisualScreenMask | VisualDepthMask | VisualClassMask, 179 &visualTemplate, &numMatching); 179 XUniquePtr<XVisualInfo> visualInfo(XGetVisualInfo(display, VisualScreenMask | VisualDepthMask | VisualClassMask, &visualTemplate, &numMatching)); 180 180 ASSERT(visualInfo); 181 Visual* visual = visualInfo [0].visual;181 Visual* visual = visualInfo.get()[0].visual; 182 182 ASSERT(visual); 183 XFree(visualInfo);184 183 185 184 callbackStruct->visual = visual; … … 233 232 delete callbackStruct; 234 233 235 if (m_drawable) { 236 XFreePixmap(hostDisplay, m_drawable); 237 m_drawable = 0; 238 } 234 m_drawable.reset(); 239 235 240 236 #if PLATFORM(GTK) … … 263 259 } 264 260 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. 277 267 } 278 268 … … 308 298 exposeEvent.type = GraphicsExpose; 309 299 exposeEvent.display = x11HostDisplay(); 310 exposeEvent.drawable = m_drawable ;300 exposeEvent.drawable = m_drawable.get(); 311 301 312 302 IntRect exposedRect(dirtyRect); … … 325 315 326 316 #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())); 332 319 cairo_t* cr = context->platformContext()->cr(); 333 320 cairo_save(cr);
Note:
See TracChangeset
for help on using the changeset viewer.