|
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
|
2 // * This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 #include "mozilla/layers/TextureClientX11.h" |
|
6 #include "mozilla/layers/CompositableClient.h" |
|
7 #include "mozilla/layers/CompositableForwarder.h" |
|
8 #include "mozilla/layers/ISurfaceAllocator.h" |
|
9 #include "mozilla/layers/ShadowLayerUtilsX11.h" |
|
10 #include "mozilla/gfx/2D.h" |
|
11 #include "gfxXlibSurface.h" |
|
12 #include "gfx2DGlue.h" |
|
13 |
|
14 #include "mozilla/X11Util.h" |
|
15 #include <X11/Xlib.h> |
|
16 |
|
17 using namespace mozilla; |
|
18 using namespace mozilla::gfx; |
|
19 using namespace mozilla::layers; |
|
20 |
|
21 TextureClientX11::TextureClientX11(SurfaceFormat aFormat, TextureFlags aFlags) |
|
22 : TextureClient(aFlags), |
|
23 mFormat(aFormat), |
|
24 mLocked(false) |
|
25 { |
|
26 MOZ_COUNT_CTOR(TextureClientX11); |
|
27 } |
|
28 |
|
29 TextureClientX11::~TextureClientX11() |
|
30 { |
|
31 MOZ_COUNT_DTOR(TextureClientX11); |
|
32 } |
|
33 |
|
34 bool |
|
35 TextureClientX11::IsAllocated() const |
|
36 { |
|
37 return !!mSurface; |
|
38 } |
|
39 |
|
40 bool |
|
41 TextureClientX11::Lock(OpenMode aMode) |
|
42 { |
|
43 MOZ_ASSERT(!mLocked, "The TextureClient is already Locked!"); |
|
44 mLocked = IsValid() && IsAllocated(); |
|
45 return mLocked; |
|
46 } |
|
47 |
|
48 void |
|
49 TextureClientX11::Unlock() |
|
50 { |
|
51 MOZ_ASSERT(mLocked, "The TextureClient is already Unlocked!"); |
|
52 mLocked = false; |
|
53 |
|
54 if (mSurface) { |
|
55 FinishX(DefaultXDisplay()); |
|
56 } |
|
57 } |
|
58 |
|
59 bool |
|
60 TextureClientX11::ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor) |
|
61 { |
|
62 MOZ_ASSERT(IsValid()); |
|
63 if (!mSurface) { |
|
64 return false; |
|
65 } |
|
66 |
|
67 aOutDescriptor = SurfaceDescriptorX11(mSurface); |
|
68 return true; |
|
69 } |
|
70 |
|
71 TextureClientData* |
|
72 TextureClientX11::DropTextureData() |
|
73 { |
|
74 MOZ_ASSERT(!(mFlags & TEXTURE_DEALLOCATE_CLIENT)); |
|
75 return nullptr; |
|
76 } |
|
77 |
|
78 bool |
|
79 TextureClientX11::AllocateForSurface(IntSize aSize, TextureAllocationFlags aTextureFlags) |
|
80 { |
|
81 MOZ_ASSERT(IsValid()); |
|
82 //MOZ_ASSERT(mFormat != gfx::FORMAT_YUV, "This TextureClient cannot use YCbCr data"); |
|
83 |
|
84 gfxContentType contentType = ContentForFormat(mFormat); |
|
85 nsRefPtr<gfxASurface> surface = gfxPlatform::GetPlatform()->CreateOffscreenSurface(aSize, contentType); |
|
86 if (!surface || surface->GetType() != gfxSurfaceType::Xlib) { |
|
87 NS_ERROR("creating Xlib surface failed!"); |
|
88 return false; |
|
89 } |
|
90 |
|
91 mSize = aSize; |
|
92 mSurface = static_cast<gfxXlibSurface*>(surface.get()); |
|
93 |
|
94 // The host is always responsible for freeing the pixmap. |
|
95 mSurface->ReleasePixmap(); |
|
96 return true; |
|
97 } |
|
98 |
|
99 TemporaryRef<DrawTarget> |
|
100 TextureClientX11::GetAsDrawTarget() |
|
101 { |
|
102 MOZ_ASSERT(IsValid()); |
|
103 if (!mSurface) { |
|
104 return nullptr; |
|
105 } |
|
106 |
|
107 IntSize size = ToIntSize(mSurface->GetSize()); |
|
108 return Factory::CreateDrawTargetForCairoSurface(mSurface->CairoSurface(), size); |
|
109 } |