1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #ifndef INCLUDED_VCL_INC_OPENGL_ZONE_H
11 #define INCLUDED_VCL_INC_OPENGL_ZONE_H
13 #include <sal/config.h>
14 #include <sal/types.h>
15 #include <vcl/dllapi.h>
19 #include <type_traits>
21 class OpenGLWatchdogThread
;
24 * We want to be able to detect if a given crash came
25 * from the OpenGL code, so use this helper to track that.
27 class VCL_DLLPUBLIC OpenGLZone
{
28 friend class OpenGLWatchdogThread
;
29 friend class OpenGLSalGraphicsImpl
;
31 // gnEnterCount and gnLeaveCount are accessed both from multiple threads (cf.
32 // OpenGLWatchdogThread::execute; so need to be of atomic type) and from signal handlers (cf.
33 // VCLExceptionSignal_impl; so need to be of lock-free atomic type). sig_atomic_t is chosen as
34 // the underlying type under the assumption that it is most likely to lead to an atomic type
35 // that is actually lock-free. However, gnEnterCount and gnLeaveCount are both monotonically
36 // increasing, so will eventually overflow, so the underlying type better be unsigned, which
37 // sig_atomic_t is not guaranteed to be:
38 #if !defined ARM32 || (defined ARM32 && defined __ARM_PCS_VFP)
39 using AtomicCounter
= std::atomic
<std::make_unsigned_t
<std::sig_atomic_t>>;
40 static_assert(AtomicCounter::is_always_lock_free
);
42 using AtomicCounter
= volatile std::make_unsigned_t
<std::sig_atomic_t>;
45 /// how many times have we entered a GL zone
46 static AtomicCounter gnEnterCount
;
47 /// how many times have we left a new GL zone
48 static AtomicCounter gnLeaveCount
;
50 static void enter() { gnEnterCount
++; }
51 static void leave() { gnLeaveCount
++; }
53 OpenGLZone() { enter(); }
54 ~OpenGLZone() { leave(); }
55 static bool isInZone() { return gnEnterCount
!= gnLeaveCount
; }
56 static void hardDisable();
57 static void relaxWatchdogTimings();
60 /// Create this to not only enter the zone, but set VCL context.
61 class OpenGLVCLContextZone
{
62 OpenGLZone
const aZone
;
64 OpenGLVCLContextZone();
67 class VCL_DLLPUBLIC PreDefaultWinNoOpenGLZone
{
69 PreDefaultWinNoOpenGLZone();
70 ~PreDefaultWinNoOpenGLZone();
73 #endif // INCLUDED_VCL_INC_OPENGL_ZONE_H
75 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */