gfx/layers/ipc/ShadowLayerUtilsX11.cpp

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

mercurial