Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ion::portgfx::Visual Class Reference

Opaque class that sets up an offscreen OpenGL context/surface/visual in a platform-specific way to allow OpenGL calls to succeed on the current thread. More...

#include "visual.h"

Public Member Functions

virtual ~Visual ()
 OpenGL calls should not be made after the Visual is destroyed. More...
 
bool IsCurrent () const
 Return true if this is the current Visual on this thread. More...
 
virtual bool IsValid () const
 Returns true if the OpenGL initialization was successful. More...
 
size_t GetId () const
 Returns the ID associated with this Visual. More...
 
int GetGlVersion () const
 Returns the major and minor OpenGL version without a decimal point, e.g. More...
 

Static Public Member Functions

static void RefreshCurrentVisual ()
 Refreshes the current visual's internal state. More...
 
static const VisualGetCurrent ()
 Returns the Visual that is current for the calling thread. More...
 
static std::unique_ptr< VisualCreateVisual ()
 Creates a new Visual that is not in a share group. More...
 
static std::unique_ptr< VisualCreateVisualInCurrentShareGroup ()
 Creates a new Visual in the same share group as the current Visual. More...
 
static bool MakeCurrent (const Visual *new_current)
 Makes the passed Visual the current one for this thread. More...
 
static void DestroyWrappingVisual (const Visual *visual)
 If the passed Visual wraps a GL context not created by Ion, the Visual is destroyed; the passed pointer should then not be used after calling this function. More...
 
static size_t GetCurrentId ()
 Returns a unique ID for the currently bound Visual. More...
 

Protected Member Functions

 Visual ()
 Constructor for subclasses that make their own contexts. More...
 
virtual VisualCreateVisualInShareGroup () const
 Return a newly-instantiated Visual in the same share group as this Visual. More...
 
virtual bool MakeCurrent () const
 Makes this Visual current for this thread and returns whether its associated GL context was successfully made current. More...
 
virtual void TeardownContextNew ()
 Destroy Visuals of type kNew. More...
 
virtual void TeardownContextShared ()
 Destroy Visuals of type kShare. More...
 
virtual void UpdateId ()
 Updates this' ID in a platform dependent way. More...
 
void SetId (size_t id)
 Sets the ID of this. More...
 

Static Protected Member Functions

static void TeardownVisual (Visual *visual)
 Responsible for cleaning up |visual's| resources. More...
 
static void RegisterVisual (Visual *visual)
 Registers the passed Visual in the global list. More...
 

Friends

class MockVisual
 

Detailed Description

Opaque class that sets up an offscreen OpenGL context/surface/visual in a platform-specific way to allow OpenGL calls to succeed on the current thread.

Note
clients may do this on their own, and do not have to use a Visual at all. This class is intended for two purposes: testing GL code using native GL calls, and for initializing OpenGL on non-rendering threads, e.g., for creating and sharing contexts on worker threads. The the case of worker threads, each thread must have its own Visual.

To create a Visual that is part of a context share group, bind a valid GL context and construct a Visual(true). The original context can be the main context used for rendering (which Ion does not manage), or another Visual.

Definition at line 40 of file visual.h.

Constructor & Destructor Documentation

ion::portgfx::Visual::~Visual ( )
virtual

OpenGL calls should not be made after the Visual is destroyed.

Definition at line 953 of file visual.cc.

References TeardownVisual().

ion::portgfx::Visual::Visual ( )
protected

Constructor for subclasses that make their own contexts.

Definition at line 948 of file visual.cc.

Referenced by CreateVisual(), CreateVisualInShareGroup(), and GetCurrent().

Member Function Documentation

std::unique_ptr< Visual > ion::portgfx::Visual::CreateVisual ( )
static

Creates a new Visual that is not in a share group.

Returns NULL if there is no current Visual.

Definition at line 353 of file visual.cc.

References RegisterVisual(), UpdateId(), and Visual().

std::unique_ptr< Visual > ion::portgfx::Visual::CreateVisualInCurrentShareGroup ( )
static

Creates a new Visual in the same share group as the current Visual.

Returns NULL if there is no current Visual.

Definition at line 360 of file visual.cc.

References CreateVisualInShareGroup(), GetCurrent(), IsValid(), LOG, RegisterVisual(), UpdateId(), and ion::port::WARNING.

Visual * ion::portgfx::Visual::CreateVisualInShareGroup ( ) const
protectedvirtual

Return a newly-instantiated Visual in the same share group as this Visual.

If this Visual is not current, then return NULL without creating a clone.

Definition at line 381 of file visual.cc.

References DCHECK_EQ, GetCurrent(), and Visual().

Referenced by CreateVisualInCurrentShareGroup().

void ion::portgfx::Visual::DestroyWrappingVisual ( const Visual visual)
static

If the passed Visual wraps a GL context not created by Ion, the Visual is destroyed; the passed pointer should then not be used after calling this function.

Passing Visuals created with CreateVisual() or CreateVisualInCurrentShareGroup() has no effect.

Definition at line 291 of file visual.cc.

References DCHECK_EQ, and GetId().

const Visual * ion::portgfx::Visual::GetCurrent ( )
static

Returns the Visual that is current for the calling thread.

This has the following semantics:

  • If a Visual of type kMock is bound (only creatable by subclasses) then return it.
  • If there is no GL context bound, returns NULL.
  • If there is a GL context bound, but no Visual bound, returns a Visual that wraps it. The Visual object will be created and managed by Ion (but can be explicitly destroyed via DestroyWrappingVisual(), below), and associated with the GL context.
  • If there is a GL context bound, and a Visual bound, returns the Visual that actually wraps the actually bound GL context, creating one if necessary (see previous item).

Definition at line 213 of file visual.cc.

References DCHECK, DCHECK_EQ, GetCurrent(), GetId(), id, MakeCurrent(), and Visual().

Referenced by CreateVisualInCurrentShareGroup(), CreateVisualInShareGroup(), GetCurrent(), GetCurrentId(), ion::portgfx::IsExtensionSupported(), MakeCurrent(), RefreshCurrentVisual(), and TeardownVisual().

size_t ion::portgfx::Visual::GetCurrentId ( )
static

Returns a unique ID for the currently bound Visual.

The visual's context pointer is used as the id, which may be recycled, i.e. the pointer may get reused when a context is destroyed and another is created.

Definition at line 313 of file visual.cc.

References GetCurrent(), and GetId().

Referenced by ion::gfx::Renderer::DestroyCurrentStateCache().

int ion::portgfx::Visual::GetGlVersion ( ) const

Returns the major and minor OpenGL version without a decimal point, e.g.

version 2.0 returns 20, version 4.3 returns 43.

Definition at line 964 of file visual.cc.

References LOG, ion::base::StartsWith(), and ion::port::WARNING.

size_t ion::portgfx::Visual::GetId ( ) const
inline

Returns the ID associated with this Visual.

Definition at line 54 of file visual.h.

Referenced by ion::gfx::Renderer::DestroyStateCache(), DestroyWrappingVisual(), GetCurrent(), GetCurrentId(), RegisterVisual(), and TeardownVisual().

bool ion::portgfx::Visual::IsCurrent ( ) const
inline

Return true if this is the current Visual on this thread.

Definition at line 46 of file visual.h.

bool ion::portgfx::Visual::IsValid ( ) const
virtual

Returns true if the OpenGL initialization was successful.

Callers should not attempt to make calls to OpenGL if Ion is managing the GL context, and this returns false.

Definition at line 949 of file visual.cc.

Referenced by CreateVisualInCurrentShareGroup(), MakeCurrent(), and RegisterVisual().

bool ion::portgfx::Visual::MakeCurrent ( const Visual new_current)
static

Makes the passed Visual the current one for this thread.

The Visual's GL context is also made current. Returns whether the Visual was successfully made current.

Definition at line 266 of file visual.cc.

References GetCurrent(), IsValid(), LOG, MakeCurrent(), and ion::port::WARNING.

Referenced by MakeCurrent().

bool ion::portgfx::Visual::MakeCurrent ( ) const
protectedvirtual

Makes this Visual current for this thread and returns whether its associated GL context was successfully made current.

Future GL calls on this thread should succeed after a return value of true.

Definition at line 950 of file visual.cc.

Referenced by GetCurrent().

void ion::portgfx::Visual::RefreshCurrentVisual ( )
static

Refreshes the current visual's internal state.

Implemented solely for EGL to reacquire the current surface on platforms like Android that replace the active surface during resize/resume operations.

Definition at line 992 of file visual.cc.

References GetCurrent().

void ion::portgfx::Visual::RegisterVisual ( Visual visual)
staticprotected

Registers the passed Visual in the global list.

Subclasses must call this to ensure that they are returned from GetCurrent().

Definition at line 373 of file visual.cc.

References GetId(), and IsValid().

Referenced by CreateVisual(), and CreateVisualInCurrentShareGroup().

void ion::portgfx::Visual::SetId ( size_t  id)
inlineprotected

Sets the ID of this.

Definition at line 127 of file visual.h.

References id.

Referenced by UpdateId().

void ion::portgfx::Visual::TeardownContextNew ( )
protectedvirtual

Destroy Visuals of type kNew.

Definition at line 951 of file visual.cc.

Referenced by TeardownVisual().

void ion::portgfx::Visual::TeardownContextShared ( )
protectedvirtual

Destroy Visuals of type kShare.

Should not attempt to destroy parts of the current OpenGL context, surface, display, etc.

Definition at line 952 of file visual.cc.

Referenced by TeardownVisual().

void ion::portgfx::Visual::TeardownVisual ( Visual visual)
staticprotected

Responsible for cleaning up |visual's| resources.

Calls SetCurrent(NULL) if visual->IsCurrent(), and dispatches into DestroyContextNew() or DestroyContextShared() for kNew and kShared visuals, respectively.

Note
if type is kNew, and the visual is current, then the current OpenGL context will be cleared by ClearCurrentContext().

Definition at line 325 of file visual.cc.

References DCHECK, GetCurrent(), GetId(), TeardownContextNew(), and TeardownContextShared().

Referenced by ~Visual().

void ion::portgfx::Visual::UpdateId ( )
protectedvirtual

Updates this' ID in a platform dependent way.

Definition at line 959 of file visual.cc.

References SetId().

Referenced by CreateVisual(), and CreateVisualInCurrentShareGroup().

Friends And Related Function Documentation

friend class MockVisual
friend

Definition at line 175 of file visual.h.


The documentation for this class was generated from the following files: