forked from Floorp-Projects/Floorp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWindowSurfaceXRender.cpp
59 lines (51 loc) · 2.1 KB
/
WindowSurfaceXRender.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "WindowSurfaceXRender.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/gfx/Types.h"
#include "gfxPlatform.h"
namespace mozilla {
namespace widget {
WindowSurfaceXRender::WindowSurfaceXRender(Display* aDisplay,
Window aWindow,
Visual* aVisual,
unsigned int aDepth)
: WindowSurfaceX11(aDisplay, aWindow, aVisual, aDepth)
, mXlibSurface(nullptr)
{
}
already_AddRefed<gfx::DrawTarget>
WindowSurfaceXRender::Lock(const LayoutDeviceIntRegion& aRegion)
{
gfx::IntRect bounds = aRegion.GetBounds().ToUnknownRect();
gfx::IntSize size(bounds.XMost(), bounds.YMost());
if (!mXlibSurface || mXlibSurface->CairoStatus() != 0 ||
mXlibSurface->GetSize().width < size.width ||
mXlibSurface->GetSize().height < size.height)
{
mXlibSurface = gfxXlibSurface::Create(DefaultScreenOfDisplay(mDisplay),
mVisual,
size,
mWindow);
}
if (mXlibSurface && mXlibSurface->CairoStatus() == 0) {
return gfxPlatform::GetPlatform()->CreateDrawTargetForSurface(mXlibSurface.get(), size);
}
return nullptr;
}
void
WindowSurfaceXRender::CommitToDrawable(Drawable aDest, GC aGC,
const LayoutDeviceIntRegion& aInvalidRegion)
{
MOZ_ASSERT(mXlibSurface && mXlibSurface->CairoStatus() == 0,
"Attempted to commit invalid surface!");
gfx::IntRect bounds = aInvalidRegion.GetBounds().ToUnknownRect();
gfx::IntSize size(bounds.XMost(), bounds.YMost());
XCopyArea(mDisplay, mXlibSurface->XDrawable(), aDest, aGC, bounds.x, bounds.y,
size.width, size.height, bounds.x, bounds.y);
}
} // namespace widget
} // namespace mozilla