Coverage Report

Created: 2018-09-25 14:53

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