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