Line data Source code
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 :
6 : #include "X11TextureHost.h"
7 : #include "mozilla/layers/BasicCompositor.h"
8 : #include "mozilla/layers/X11TextureSourceBasic.h"
9 : #ifdef GL_PROVIDER_GLX
10 : #include "mozilla/layers/CompositorOGL.h"
11 : #include "mozilla/layers/X11TextureSourceOGL.h"
12 : #endif
13 : #include "gfxXlibSurface.h"
14 : #include "gfx2DGlue.h"
15 :
16 : namespace mozilla {
17 : namespace layers {
18 :
19 : using namespace mozilla::gfx;
20 :
21 0 : X11TextureHost::X11TextureHost(TextureFlags aFlags,
22 0 : const SurfaceDescriptorX11& aDescriptor)
23 0 : : TextureHost(aFlags)
24 : {
25 0 : RefPtr<gfxXlibSurface> surface = aDescriptor.OpenForeign();
26 0 : mSurface = surface.get();
27 :
28 0 : if (!(aFlags & TextureFlags::DEALLOCATE_CLIENT)) {
29 0 : mSurface->TakePixmap();
30 : }
31 0 : }
32 :
33 : bool
34 0 : X11TextureHost::Lock()
35 : {
36 0 : if (!mCompositor) {
37 0 : return false;
38 : }
39 :
40 0 : if (!mTextureSource) {
41 0 : switch (mCompositor->GetBackendType()) {
42 : case LayersBackend::LAYERS_BASIC:
43 : mTextureSource =
44 0 : new X11TextureSourceBasic(mCompositor->AsBasicCompositor(), mSurface);
45 0 : break;
46 : #ifdef GL_PROVIDER_GLX
47 : case LayersBackend::LAYERS_OPENGL:
48 : mTextureSource =
49 0 : new X11TextureSourceOGL(mCompositor->AsCompositorOGL(), mSurface);
50 0 : break;
51 : #endif
52 : default:
53 0 : return false;
54 : }
55 : }
56 :
57 0 : return true;
58 : }
59 :
60 : void
61 0 : X11TextureHost::SetTextureSourceProvider(TextureSourceProvider* aProvider)
62 : {
63 0 : mProvider = aProvider;
64 0 : if (mProvider) {
65 0 : mCompositor = mProvider->AsCompositor();
66 : } else {
67 0 : mCompositor = nullptr;
68 : }
69 0 : if (mTextureSource) {
70 0 : mTextureSource->SetTextureSourceProvider(aProvider);
71 : }
72 0 : }
73 :
74 : SurfaceFormat
75 0 : X11TextureHost::GetFormat() const
76 : {
77 0 : gfxContentType type = mSurface->GetContentType();
78 : #ifdef GL_PROVIDER_GLX
79 0 : if (mCompositor->GetBackendType() == LayersBackend::LAYERS_OPENGL) {
80 0 : return X11TextureSourceOGL::ContentTypeToSurfaceFormat(type);
81 : }
82 : #endif
83 0 : return X11TextureSourceBasic::ContentTypeToSurfaceFormat(type);
84 : }
85 :
86 : IntSize
87 0 : X11TextureHost::GetSize() const
88 : {
89 0 : return mSurface->GetSize();
90 : }
91 :
92 : already_AddRefed<gfx::DataSourceSurface>
93 0 : X11TextureHost::GetAsSurface()
94 : {
95 0 : if (!mTextureSource || !mTextureSource->AsSourceBasic()) {
96 0 : return nullptr;
97 : }
98 : RefPtr<DrawTarget> tempDT =
99 0 : gfxPlatform::GetPlatform()->CreateOffscreenContentDrawTarget(
100 0 : GetSize(), GetFormat());
101 0 : if (!tempDT) {
102 0 : return nullptr;
103 : }
104 0 : RefPtr<SourceSurface> surf = mTextureSource->AsSourceBasic()->GetSurface(tempDT);
105 0 : if (!surf) {
106 0 : return nullptr;
107 : }
108 0 : return surf->GetDataSurface();
109 : }
110 :
111 : }
112 : }
|