Bug 1874684 - Part 28: Return DateDuration from DifferenceISODateTime. r=mgaudet
[gecko.git] / gfx / thebes / XlibDisplay.cpp
blob3bae50194edeb58510b4a4dce6c976ac6acec5c8
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/. */
6 #include "XlibDisplay.h"
8 #include "mozilla/Assertions.h"
10 namespace mozilla::gfx {
12 XlibDisplay::XlibDisplay(Display* aDisplay, bool aOwned)
13 : mDisplay(aDisplay), mOwned(aOwned) {
14 MOZ_ASSERT(mDisplay);
17 XlibDisplay::~XlibDisplay() {
18 if (mOwned) {
19 XCloseDisplay(mDisplay);
23 /* static */
24 std::shared_ptr<XlibDisplay> XlibDisplay::Borrow(Display* aDisplay) {
25 if (!aDisplay) {
26 return nullptr;
28 return std::shared_ptr<XlibDisplay>(new XlibDisplay(aDisplay, false));
31 /* static */
32 std::shared_ptr<XlibDisplay> XlibDisplay::Open(const char* aDisplayName) {
33 Display* disp = XOpenDisplay(aDisplayName);
34 if (!disp) {
35 return nullptr;
37 return std::shared_ptr<XlibDisplay>(new XlibDisplay(disp, true));
40 } // namespace mozilla::gfx