11#ifndef GAMP_WTSURFACE_HPP_
12#define GAMP_WTSURFACE_HPP_
31 using namespace jau::fractions_i64_literals;
32 using namespace jau::math;
38 class Surface :
public std::enable_shared_from_this<Surface> {
51 int m_swapInterval = -1;
61 void disposeImpl(
handle_t)
noexcept {}
62 bool setSwapIntervalImpl(
int v)
noexcept;
66 static void setCaps(
handle_t surface_handle,
const Capabilities& requested)
noexcept;
69 template <
typename ChildT>
71 return std::static_pointer_cast<ChildT>(shared_from_this());
82 : m_surface_handle(surface_handle), m_surface_size(surface_size), m_capsptr_req(requested.clone()) { }
85 return std::make_shared<Surface>(
Private(), surface_handle, surface_size, requested);
95 if( m_surface_lock.isOwner() ) {
101 m_surface_handle = 0;
102 m_renderContext =
nullptr;
105 if( m_renderContext ) {
106 m_renderContext->dispose();
107 m_renderContext =
nullptr;
109 if( m_surface_handle ) {
110 disposeImpl(m_surface_handle);
111 m_surface_handle = 0;
119 if( rc && rc->isValid() ) {
120 m_renderContext = std::move(rc);
121 m_capsptr_chosen = retrieveCaps(
shared());
132 return m_renderContext ? m_renderContext.get() :
nullptr;
135 return m_renderContext ? m_renderContext.get() :
nullptr;
157 if( m_renderContext && m_renderContext->isValid() ) {
158 return setSwapIntervalImpl(v);
196 virtual bool isValid() const noexcept {
return 0 != m_surface_handle; }
239 if( !m_surface_lock.tryLock(
TIMEOUT) ) {
242 if (1 == m_surface_lock.holdCount()) {
245 m_surface_lock.unlock();
267 m_surface_lock.validateLocked();
268 if (1 == m_surface_lock.holdCount()) {
271 m_surface_lock.unlock();
275 std::string res =
"Surface[";
277 .append(
", ").append(m_renderContext ? m_renderContext->toString() :
"nil-ctx")
278 .append(
", size ").append(m_surface_size.toString())
279 .append(
", caps[req ").append(m_capsptr_req->toString())
280 .append(
", chosen ").append(m_capsptr_chosen?m_capsptr_chosen->toString():
"nocaps")
Specifies the render profile.
Specifies a set of capabilities that a window's rendering context must support, such as color depth p...
void operator=(const Surface &)=delete
gamp::render::RenderContext * renderContext() noexcept
static constexpr bool is_locked(const lock_status_t ls) noexcept
static SurfaceSRef create(handle_t surface_handle, const Vec2i &surface_size, const Capabilities &requested)
constexpr handle_t surfaceHandle() const noexcept
Returns the handle to the surface for this NativeSurface.
lock_status_t lockSurface()
Lock the surface of this native window.
const SurfaceSRef shared()
const gamp::render::RenderContext * renderContext() const noexcept
Surface(const Surface &)=delete
void setSurfaceSize(const Vec2i &sz) noexcept
void unlockSurface()
Unlock the surface of this native window.
std::string toString() const noexcept
Surface(Private, handle_t surface_handle, const Vec2i &surface_size, const Capabilities &requested)
Private ctor for single Surface::create() method w/o public ctor.
virtual ~Surface() noexcept
Releases this instance.
virtual bool isValid() const noexcept
static void setCaps(handle_t surface_handle, const Capabilities &requested) noexcept
virtual void nativeSurfaceUnlock() noexcept
constexpr int swapInterval() const noexcept
Returns desired or determined swap interval.
std::shared_ptr< ChildT > shared_from_base()
constexpr bool isBLOriented() const noexcept
Returns true if this surface is rendered in OpenGL's coordinate system, origin at bottom left.
virtual bool surfaceSwap() noexcept
Provide a mechanism to utilize custom (pre-) swap surface code.
void setRequestedCapabilities(CapabilitiesPtr &&req) noexcept
Sets the requested capabilities for a surface to be realized.
const Capabilities * capabilities() const noexcept
Returns the chosen (retrieved) capabilities of a realized surface.
virtual void dispose(const jau::fraction_timespec &) noexcept
static constexpr const jau::fraction_i64 TIMEOUT
virtual void disposedNotify(const jau::fraction_timespec &) noexcept
constexpr const Vec2i & surfaceSize() const noexcept
Returns the surface size of the client area excluding insets (window decorations) in pixel units.
bool setSwapInterval(int v) noexcept
Returns true if swap interval could be set with the native toolkit post createContext().
virtual lock_status_t nativeSurfaceLock() noexcept
bool createContext(const gamp::render::RenderProfile &profile, const gamp::render::RenderContextFlags &contextFlags)
fraction< int64_t > fraction_i64
fraction using int64_t as integral type
std::unique_ptr< RenderContext > RenderContextPtr
RenderContextFlags
OpenGL context flags.
std::shared_ptr< Surface > SurfaceSRef
std::unique_ptr< Capabilities > CapabilitiesPtr
uintptr_t handle_t
A native handle type, big enough to store a pointer.
std::string toHexString(const void *data, const nsize_t length, const lb_endian_t byteOrder=lb_endian_t::big, const LoUpCase capitalization=LoUpCase::lower, const PrefixOpt prefix=PrefixOpt::prefix) noexcept
Produce a hexadecimal string representation of the given lsb-first byte values.
Requirement (concept) Definitions.
std::string threadName(const std::thread::id id) noexcept
Timespec structure using int64_t for its components in analogy to struct timespec_t on 64-bit platfor...