gfx/layers/ipc/ShadowLayerUtilsX11.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
michael@0 2 * vim: sw=2 ts=8 et :
michael@0 3 */
michael@0 4 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 5 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 7
michael@0 8 #include "ShadowLayerUtilsX11.h"
michael@0 9 #include <X11/X.h> // for Drawable, XID
michael@0 10 #include <X11/Xlib.h> // for Display, Visual, etc
michael@0 11 #include <X11/extensions/Xrender.h> // for XRenderPictFormat, etc
michael@0 12 #include <X11/extensions/render.h> // for PictFormat
michael@0 13 #include "cairo-xlib.h"
michael@0 14 #include <stdint.h> // for uint32_t
michael@0 15 #include "GLDefs.h" // for GLenum
michael@0 16 #include "gfxPlatform.h" // for gfxPlatform
michael@0 17 #include "gfxXlibSurface.h" // for gfxXlibSurface
michael@0 18 #include "gfx2DGlue.h" // for Moz2D transistion helpers
michael@0 19 #include "mozilla/X11Util.h" // for DefaultXDisplay, FinishX, etc
michael@0 20 #include "mozilla/gfx/Point.h" // for IntSize
michael@0 21 #include "mozilla/layers/CompositableForwarder.h"
michael@0 22 #include "mozilla/layers/CompositorTypes.h" // for OpenMode
michael@0 23 #include "mozilla/layers/ISurfaceAllocator.h" // for ISurfaceAllocator, etc
michael@0 24 #include "mozilla/layers/LayerManagerComposite.h"
michael@0 25 #include "mozilla/layers/LayersSurfaces.h" // for SurfaceDescriptor, etc
michael@0 26 #include "mozilla/layers/ShadowLayers.h" // for ShadowLayerForwarder, etc
michael@0 27 #include "mozilla/mozalloc.h" // for operator new
michael@0 28 #include "nsAutoPtr.h" // for nsRefPtr
michael@0 29 #include "nsCOMPtr.h" // for already_AddRefed
michael@0 30 #include "nsDebug.h" // for NS_ERROR
michael@0 31 #include "prenv.h" // for PR_GetEnv
michael@0 32
michael@0 33 using namespace mozilla::gl;
michael@0 34
michael@0 35 namespace mozilla {
michael@0 36 namespace gl {
michael@0 37 class GLContext;
michael@0 38 class TextureImage;
michael@0 39 }
michael@0 40
michael@0 41 namespace layers {
michael@0 42
michael@0 43 // Return true if we're likely compositing using X and so should use
michael@0 44 // Xlib surfaces in shadow layers.
michael@0 45 static bool
michael@0 46 UsingXCompositing()
michael@0 47 {
michael@0 48 if (!PR_GetEnv("MOZ_LAYERS_ENABLE_XLIB_SURFACES")) {
michael@0 49 return false;
michael@0 50 }
michael@0 51 return (gfxSurfaceType::Xlib ==
michael@0 52 gfxPlatform::GetPlatform()->ScreenReferenceSurface()->GetType());
michael@0 53 }
michael@0 54
michael@0 55 // LookReturn a pointer to |aFormat| that lives in the Xrender library.
michael@0 56 // All code using render formats assumes it doesn't need to copy.
michael@0 57 static XRenderPictFormat*
michael@0 58 GetXRenderPictFormatFromId(Display* aDisplay, PictFormat aFormatId)
michael@0 59 {
michael@0 60 XRenderPictFormat tmplate;
michael@0 61 tmplate.id = aFormatId;
michael@0 62 return XRenderFindFormat(aDisplay, PictFormatID, &tmplate, 0);
michael@0 63 }
michael@0 64
michael@0 65 SurfaceDescriptorX11::SurfaceDescriptorX11(gfxXlibSurface* aSurf)
michael@0 66 : mId(aSurf->XDrawable())
michael@0 67 , mSize(aSurf->GetSize().ToIntSize())
michael@0 68 {
michael@0 69 const XRenderPictFormat *pictFormat = aSurf->XRenderFormat();
michael@0 70 if (pictFormat) {
michael@0 71 mFormat = pictFormat->id;
michael@0 72 } else {
michael@0 73 mFormat = cairo_xlib_surface_get_visual(aSurf->CairoSurface())->visualid;
michael@0 74 }
michael@0 75 }
michael@0 76
michael@0 77 SurfaceDescriptorX11::SurfaceDescriptorX11(Drawable aDrawable, XID aFormatID,
michael@0 78 const gfx::IntSize& aSize)
michael@0 79 : mId(aDrawable)
michael@0 80 , mFormat(aFormatID)
michael@0 81 , mSize(aSize)
michael@0 82 { }
michael@0 83
michael@0 84 already_AddRefed<gfxXlibSurface>
michael@0 85 SurfaceDescriptorX11::OpenForeign() const
michael@0 86 {
michael@0 87 Display* display = DefaultXDisplay();
michael@0 88 Screen* screen = DefaultScreenOfDisplay(display);
michael@0 89
michael@0 90 nsRefPtr<gfxXlibSurface> surf;
michael@0 91 XRenderPictFormat* pictFormat = GetXRenderPictFormatFromId(display, mFormat);
michael@0 92 if (pictFormat) {
michael@0 93 surf = new gfxXlibSurface(screen, mId, pictFormat, gfx::ThebesIntSize(mSize));
michael@0 94 } else {
michael@0 95 Visual* visual;
michael@0 96 int depth;
michael@0 97 FindVisualAndDepth(display, mFormat, &visual, &depth);
michael@0 98 if (!visual)
michael@0 99 return nullptr;
michael@0 100
michael@0 101 surf = new gfxXlibSurface(display, mId, visual, gfx::ThebesIntSize(mSize));
michael@0 102 }
michael@0 103 return surf->CairoStatus() ? nullptr : surf.forget();
michael@0 104 }
michael@0 105
michael@0 106 /*static*/ void
michael@0 107 ShadowLayerForwarder::PlatformSyncBeforeUpdate()
michael@0 108 {
michael@0 109 if (UsingXCompositing()) {
michael@0 110 // If we're using X surfaces, then we need to finish all pending
michael@0 111 // operations on the back buffers before handing them to the
michael@0 112 // parent, otherwise the surface might be used by the parent's
michael@0 113 // Display in between two operations queued by our Display.
michael@0 114 FinishX(DefaultXDisplay());
michael@0 115 }
michael@0 116 }
michael@0 117
michael@0 118 /*static*/ void
michael@0 119 LayerManagerComposite::PlatformSyncBeforeReplyUpdate()
michael@0 120 {
michael@0 121 if (UsingXCompositing()) {
michael@0 122 // If we're using X surfaces, we need to finish all pending
michael@0 123 // operations on the *front buffers* before handing them back to
michael@0 124 // the child, even though they will be read operations.
michael@0 125 // Otherwise, the child might start scribbling on new back buffers
michael@0 126 // that are still participating in requests as old front buffers.
michael@0 127 FinishX(DefaultXDisplay());
michael@0 128 }
michael@0 129 }
michael@0 130
michael@0 131 /*static*/ bool
michael@0 132 LayerManagerComposite::SupportsDirectTexturing()
michael@0 133 {
michael@0 134 return false;
michael@0 135 }
michael@0 136
michael@0 137 } // namespace layers
michael@0 138 } // namespace mozilla

mercurial