Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/gfx/layers/basic/X11BasicCompositor.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 "X11BasicCompositor.h"
8
#include "gfxPlatform.h"
9
#include "gfx2DGlue.h"
10
#include "gfxXlibSurface.h"
11
#include "gfxImageSurface.h"
12
#include "mozilla/X11Util.h"
13
14
namespace mozilla {
15
using namespace mozilla::gfx;
16
17
namespace layers {
18
19
bool
20
X11DataTextureSourceBasic::Update(gfx::DataSourceSurface* aSurface,
21
                                  nsIntRegion* aDestRegion,
22
                                  gfx::IntPoint* aSrcOffset)
23
0
{
24
0
  // Reallocate our internal X11 surface if we don't have a DrawTarget yet,
25
0
  // or if we changed surface size or format since last update.
26
0
  if (!mBufferDrawTarget ||
27
0
      (aSurface->GetSize() != mBufferDrawTarget->GetSize()) ||
28
0
      (aSurface->GetFormat() != mBufferDrawTarget->GetFormat())) {
29
0
30
0
    RefPtr<gfxASurface> surf;
31
0
    gfxImageFormat imageFormat = SurfaceFormatToImageFormat(aSurface->GetFormat());
32
0
    Display *display = DefaultXDisplay();
33
0
    Screen *screen = DefaultScreenOfDisplay(display);
34
0
    XRenderPictFormat *xrenderFormat =
35
0
      gfxXlibSurface::FindRenderFormat(display, imageFormat);
36
0
37
0
    if (xrenderFormat) {
38
0
      surf = gfxXlibSurface::Create(screen, xrenderFormat,
39
0
                                    aSurface->GetSize());
40
0
    }
41
0
42
0
    if (!surf) {
43
0
      NS_WARNING("Couldn't create native surface, fallback to image surface");
44
0
      surf = new gfxImageSurface(aSurface->GetSize(), imageFormat);
45
0
    }
46
0
47
0
    mBufferDrawTarget = gfxPlatform::GetPlatform()->
48
0
      CreateDrawTargetForSurface(surf, aSurface->GetSize());
49
0
  }
50
0
51
0
  // Image contents have changed, upload to our DrawTarget
52
0
  // If aDestRegion is null, means we're updating the whole surface
53
0
  // Note : Incremental update with a source offset is only used on Mac.
54
0
  NS_ASSERTION(!aSrcOffset, "SrcOffset should not be used with linux OMTC basic");
55
0
56
0
  if (aDestRegion) {
57
0
    for (auto iter = aDestRegion->RectIter(); !iter.Done(); iter.Next()) {
58
0
      const IntRect& rect = iter.Get();
59
0
      IntRect srcRect(rect.X(), rect.Y(), rect.Width(), rect.Height());
60
0
      IntPoint dstPoint(rect.X(), rect.Y());
61
0
62
0
      // We're uploading regions to our buffer, so let's just copy contents over
63
0
      mBufferDrawTarget->CopySurface(aSurface, srcRect, dstPoint);
64
0
    }
65
0
  } else {
66
0
    // We're uploading the whole buffer, so let's just copy the full surface
67
0
    IntSize size = aSurface->GetSize();
68
0
    mBufferDrawTarget->CopySurface(aSurface, IntRect(0, 0, size.width, size.height),
69
0
                                   IntPoint(0, 0));
70
0
  }
71
0
72
0
  return true;
73
0
}
74
75
TextureSourceBasic*
76
X11DataTextureSourceBasic::AsSourceBasic()
77
0
{
78
0
  return this;
79
0
}
80
81
IntSize
82
X11DataTextureSourceBasic::GetSize() const
83
0
{
84
0
  if (!mBufferDrawTarget) {
85
0
    NS_WARNING("Trying to query the size of an uninitialized TextureSource");
86
0
    return IntSize(0, 0);
87
0
  }
88
0
  return mBufferDrawTarget->GetSize();
89
0
}
90
91
gfx::SurfaceFormat
92
X11DataTextureSourceBasic::GetFormat() const
93
0
{
94
0
  if (!mBufferDrawTarget) {
95
0
    NS_WARNING("Trying to query the format of an uninitialized TextureSource");
96
0
    return gfx::SurfaceFormat::UNKNOWN;
97
0
  }
98
0
  return mBufferDrawTarget->GetFormat();
99
0
}
100
101
SourceSurface*
102
X11DataTextureSourceBasic::GetSurface(DrawTarget* aTarget)
103
0
{
104
0
  RefPtr<gfx::SourceSurface> surface;
105
0
  if (mBufferDrawTarget) {
106
0
    surface = mBufferDrawTarget->Snapshot();
107
0
    return surface.get();
108
0
  }
109
0
  return nullptr;
110
0
}
111
112
void
113
X11DataTextureSourceBasic::DeallocateDeviceData()
114
0
{
115
0
  mBufferDrawTarget = nullptr;
116
0
}
117
118
already_AddRefed<DataTextureSource>
119
X11BasicCompositor::CreateDataTextureSource(TextureFlags aFlags)
120
0
{
121
0
  RefPtr<DataTextureSource> result =
122
0
    new X11DataTextureSourceBasic();
123
0
  return result.forget();
124
0
}
125
126
void
127
X11BasicCompositor::EndFrame()
128
0
{
129
0
  BasicCompositor::EndFrame();
130
0
  XFlush(DefaultXDisplay());
131
0
}
132
133
} // namespace layers
134
} // namespace mozilla