1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/layers/ipc/ShadowLayerUtilsX11.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,138 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 + * vim: sw=2 ts=8 et : 1.6 + */ 1.7 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.8 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.9 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.10 + 1.11 +#include "ShadowLayerUtilsX11.h" 1.12 +#include <X11/X.h> // for Drawable, XID 1.13 +#include <X11/Xlib.h> // for Display, Visual, etc 1.14 +#include <X11/extensions/Xrender.h> // for XRenderPictFormat, etc 1.15 +#include <X11/extensions/render.h> // for PictFormat 1.16 +#include "cairo-xlib.h" 1.17 +#include <stdint.h> // for uint32_t 1.18 +#include "GLDefs.h" // for GLenum 1.19 +#include "gfxPlatform.h" // for gfxPlatform 1.20 +#include "gfxXlibSurface.h" // for gfxXlibSurface 1.21 +#include "gfx2DGlue.h" // for Moz2D transistion helpers 1.22 +#include "mozilla/X11Util.h" // for DefaultXDisplay, FinishX, etc 1.23 +#include "mozilla/gfx/Point.h" // for IntSize 1.24 +#include "mozilla/layers/CompositableForwarder.h" 1.25 +#include "mozilla/layers/CompositorTypes.h" // for OpenMode 1.26 +#include "mozilla/layers/ISurfaceAllocator.h" // for ISurfaceAllocator, etc 1.27 +#include "mozilla/layers/LayerManagerComposite.h" 1.28 +#include "mozilla/layers/LayersSurfaces.h" // for SurfaceDescriptor, etc 1.29 +#include "mozilla/layers/ShadowLayers.h" // for ShadowLayerForwarder, etc 1.30 +#include "mozilla/mozalloc.h" // for operator new 1.31 +#include "nsAutoPtr.h" // for nsRefPtr 1.32 +#include "nsCOMPtr.h" // for already_AddRefed 1.33 +#include "nsDebug.h" // for NS_ERROR 1.34 +#include "prenv.h" // for PR_GetEnv 1.35 + 1.36 +using namespace mozilla::gl; 1.37 + 1.38 +namespace mozilla { 1.39 +namespace gl { 1.40 +class GLContext; 1.41 +class TextureImage; 1.42 +} 1.43 + 1.44 +namespace layers { 1.45 + 1.46 +// Return true if we're likely compositing using X and so should use 1.47 +// Xlib surfaces in shadow layers. 1.48 +static bool 1.49 +UsingXCompositing() 1.50 +{ 1.51 + if (!PR_GetEnv("MOZ_LAYERS_ENABLE_XLIB_SURFACES")) { 1.52 + return false; 1.53 + } 1.54 + return (gfxSurfaceType::Xlib == 1.55 + gfxPlatform::GetPlatform()->ScreenReferenceSurface()->GetType()); 1.56 +} 1.57 + 1.58 +// LookReturn a pointer to |aFormat| that lives in the Xrender library. 1.59 +// All code using render formats assumes it doesn't need to copy. 1.60 +static XRenderPictFormat* 1.61 +GetXRenderPictFormatFromId(Display* aDisplay, PictFormat aFormatId) 1.62 +{ 1.63 + XRenderPictFormat tmplate; 1.64 + tmplate.id = aFormatId; 1.65 + return XRenderFindFormat(aDisplay, PictFormatID, &tmplate, 0); 1.66 +} 1.67 + 1.68 +SurfaceDescriptorX11::SurfaceDescriptorX11(gfxXlibSurface* aSurf) 1.69 + : mId(aSurf->XDrawable()) 1.70 + , mSize(aSurf->GetSize().ToIntSize()) 1.71 +{ 1.72 + const XRenderPictFormat *pictFormat = aSurf->XRenderFormat(); 1.73 + if (pictFormat) { 1.74 + mFormat = pictFormat->id; 1.75 + } else { 1.76 + mFormat = cairo_xlib_surface_get_visual(aSurf->CairoSurface())->visualid; 1.77 + } 1.78 +} 1.79 + 1.80 +SurfaceDescriptorX11::SurfaceDescriptorX11(Drawable aDrawable, XID aFormatID, 1.81 + const gfx::IntSize& aSize) 1.82 + : mId(aDrawable) 1.83 + , mFormat(aFormatID) 1.84 + , mSize(aSize) 1.85 +{ } 1.86 + 1.87 +already_AddRefed<gfxXlibSurface> 1.88 +SurfaceDescriptorX11::OpenForeign() const 1.89 +{ 1.90 + Display* display = DefaultXDisplay(); 1.91 + Screen* screen = DefaultScreenOfDisplay(display); 1.92 + 1.93 + nsRefPtr<gfxXlibSurface> surf; 1.94 + XRenderPictFormat* pictFormat = GetXRenderPictFormatFromId(display, mFormat); 1.95 + if (pictFormat) { 1.96 + surf = new gfxXlibSurface(screen, mId, pictFormat, gfx::ThebesIntSize(mSize)); 1.97 + } else { 1.98 + Visual* visual; 1.99 + int depth; 1.100 + FindVisualAndDepth(display, mFormat, &visual, &depth); 1.101 + if (!visual) 1.102 + return nullptr; 1.103 + 1.104 + surf = new gfxXlibSurface(display, mId, visual, gfx::ThebesIntSize(mSize)); 1.105 + } 1.106 + return surf->CairoStatus() ? nullptr : surf.forget(); 1.107 +} 1.108 + 1.109 +/*static*/ void 1.110 +ShadowLayerForwarder::PlatformSyncBeforeUpdate() 1.111 +{ 1.112 + if (UsingXCompositing()) { 1.113 + // If we're using X surfaces, then we need to finish all pending 1.114 + // operations on the back buffers before handing them to the 1.115 + // parent, otherwise the surface might be used by the parent's 1.116 + // Display in between two operations queued by our Display. 1.117 + FinishX(DefaultXDisplay()); 1.118 + } 1.119 +} 1.120 + 1.121 +/*static*/ void 1.122 +LayerManagerComposite::PlatformSyncBeforeReplyUpdate() 1.123 +{ 1.124 + if (UsingXCompositing()) { 1.125 + // If we're using X surfaces, we need to finish all pending 1.126 + // operations on the *front buffers* before handing them back to 1.127 + // the child, even though they will be read operations. 1.128 + // Otherwise, the child might start scribbling on new back buffers 1.129 + // that are still participating in requests as old front buffers. 1.130 + FinishX(DefaultXDisplay()); 1.131 + } 1.132 +} 1.133 + 1.134 +/*static*/ bool 1.135 +LayerManagerComposite::SupportsDirectTexturing() 1.136 +{ 1.137 + return false; 1.138 +} 1.139 + 1.140 +} // namespace layers 1.141 +} // namespace mozilla