XlibDisplay.cpp (1053B)
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 "XlibDisplay.h" 7 8 #include "mozilla/Assertions.h" 9 10 namespace mozilla::gfx { 11 12 XlibDisplay::XlibDisplay(Display* aDisplay, bool aOwned) 13 : mDisplay(aDisplay), mOwned(aOwned) { 14 MOZ_ASSERT(mDisplay); 15 } 16 17 XlibDisplay::~XlibDisplay() { 18 if (mOwned) { 19 XCloseDisplay(mDisplay); 20 } 21 } 22 23 /* static */ 24 std::shared_ptr<XlibDisplay> XlibDisplay::Borrow(Display* aDisplay) { 25 if (!aDisplay) { 26 return nullptr; 27 } 28 return std::shared_ptr<XlibDisplay>(new XlibDisplay(aDisplay, false)); 29 } 30 31 /* static */ 32 std::shared_ptr<XlibDisplay> XlibDisplay::Open(const char* aDisplayName) { 33 Display* disp = XOpenDisplay(aDisplayName); 34 if (!disp) { 35 return nullptr; 36 } 37 return std::shared_ptr<XlibDisplay>(new XlibDisplay(disp, true)); 38 } 39 40 } // namespace mozilla::gfx