IGraphicsDataToken and IGraphicsCommandQueue::stopRenderer()

This commit is contained in:
Jack Andersen 2015-12-04 14:41:30 -10:00
parent 32d4797ac6
commit d145e15ecb
9 changed files with 81 additions and 28 deletions

View File

@ -58,7 +58,6 @@ public:
/* Creates a new context on current thread!! Call from client loading thread */
virtual IGraphicsDataFactory* getLoadContextDataFactory()=0;
};
}

View File

@ -18,25 +18,31 @@ enum class EMouseButton
Aux2 = 5
};
struct SWindowCoord
{
int pixel[2];
int virtualPixel[2];
float norm[2];
};
struct SWindowRect
{
int location[2];
int size[2];
bool operator !=(const SWindowRect& other) const
bool operator!=(const SWindowRect& other) const
{
return location[0] != other.location[0] ||
location[1] != other.location[1] ||
size[0] != other.size[0] ||
size[1] != other.size[1];
}
bool operator ==(const SWindowRect& other) const {return !(*this != other);}
};
bool operator==(const SWindowRect& other) const {return !(*this != other);}
struct SWindowCoord
{
int pixel[2];
int virtualPixel[2];
float norm[2];
bool coordInRect(const SWindowCoord& coord) const
{
return coord.pixel[0] >= location[0] && coord.pixel[0] < location[0] + size[0] &&
coord.pixel[1] >= location[1] && coord.pixel[1] < location[1] + size[1];
}
};
struct STouchCoord
@ -246,7 +252,6 @@ public:
/* Creates a new context on current thread!! Call from client loading thread */
virtual IGraphicsDataFactory* getLoadContextDataFactory()=0;
};
}

View File

@ -17,9 +17,11 @@ class GLDataFactory : public IGraphicsDataFactory
struct GLData* m_deferredData = nullptr;
std::unordered_set<struct GLData*> m_committedData;
std::vector<int> m_texUnis;
void destroyData(IGraphicsData*);
void destroyAllData();
public:
GLDataFactory(IGraphicsContext* parent);
~GLDataFactory() {}
~GLDataFactory() {destroyAllData();}
Platform platform() const {return Platform::OGL;}
const SystemChar* platformName() const {return _S("OGL");}
@ -54,9 +56,7 @@ public:
size_t texCount, ITexture** texs);
void reset();
IGraphicsData* commit();
void destroyData(IGraphicsData*);
void destroyAllData();
IGraphicsDataToken commit();
};
}

View File

@ -38,6 +38,8 @@ struct IGraphicsCommandQueue
virtual void resolveDisplay(ITextureR* source)=0;
virtual void execute()=0;
virtual void stopRenderer()=0;
};
}

View File

@ -7,6 +7,7 @@
namespace boo
{
struct IGraphicsCommandQueue;
struct IGraphicsBuffer
{
@ -145,12 +146,9 @@ struct IShaderPipeline {};
* as a reference */
struct IShaderDataBinding {};
/** Opaque token for maintaining ownership of factory-created resources
* deletion of this token triggers mass-deallocation of the factory's
* resource batch. */
struct IGraphicsData
{
};
/** Opaque object for maintaining ownership of factory-created resources */
struct IGraphicsData {};
class IGraphicsDataToken;
/** Used by platform shader pipeline constructors */
enum class BlendFactor
@ -220,11 +218,55 @@ struct IGraphicsDataFactory
size_t texCount, ITexture** texs)=0;
virtual void reset()=0;
virtual IGraphicsData* commit()=0;
virtual IGraphicsDataToken commit()=0;
private:
friend class IGraphicsDataToken;
virtual void destroyData(IGraphicsData*)=0;
virtual void destroyAllData()=0;
};
/** Opaque token for maintaining ownership of factory-created resources
* deletion of this token triggers mass-deallocation of the factory's
* IGraphicsData. */
class IGraphicsDataToken
{
friend class GLDataFactory;
friend class D3D12DataFactory;
friend class D3D11DataFactory;
friend class MetalDataFactory;
IGraphicsDataFactory* m_factory = nullptr;
IGraphicsData* m_data = nullptr;
IGraphicsDataToken(IGraphicsDataFactory* factory, IGraphicsData* data)
: m_factory(factory), m_data(data) {}
void doDestroy()
{
if (m_factory && m_data)
m_factory->destroyData(m_data);
}
public:
IGraphicsDataToken() = default;
IGraphicsDataToken(const IGraphicsDataToken& other) = delete;
IGraphicsDataToken(IGraphicsDataToken&& other)
{
m_factory = other.m_factory;
other.m_factory = nullptr;
m_data = other.m_data;
other.m_data = nullptr;
}
IGraphicsDataToken& operator=(const IGraphicsDataToken& other) = delete;
IGraphicsDataToken& operator=(IGraphicsDataToken&& other)
{
doDestroy();
m_factory = other.m_factory;
other.m_factory = nullptr;
m_data = other.m_data;
other.m_data = nullptr;
return *this;
}
~IGraphicsDataToken() {doDestroy();}
};
}
#endif // IGFXDATAFACTORY_HPP

View File

@ -557,7 +557,7 @@ void GLDataFactory::reset()
m_deferredData = new struct GLData();
}
IGraphicsData* GLDataFactory::commit()
IGraphicsDataToken GLDataFactory::commit()
{
GLData* retval = m_deferredData;
m_deferredData = new struct GLData();
@ -566,7 +566,7 @@ IGraphicsData* GLDataFactory::commit()
While this isn't strictly required, some drivers might behave
differently */
glFlush();
return retval;
return IGraphicsDataToken(this, retval);
}
void GLDataFactory::destroyData(IGraphicsData* d)
@ -900,13 +900,18 @@ struct GLCommandQueue : IGraphicsCommandQueue
m_initlk.unlock();
}
~GLCommandQueue()
void stopRenderer()
{
m_running = false;
m_cv.notify_one();
m_thr.join();
}
~GLCommandQueue()
{
if (m_running) stopRenderer();
}
void setShaderDataBinding(IShaderDataBinding* binding)
{
std::vector<Command>& cmds = m_cmdBufs[m_fillBuf];

View File

@ -60,7 +60,7 @@ static Window GetWindowOfEvent(XEvent* event, bool& windowEvent)
case ButtonRelease:
{
windowEvent = true;
return event->xbutton.window;;
return event->xbutton.window;
}
case MotionNotify:
{
@ -290,7 +290,6 @@ public:
XNextEvent(m_xDisp, &event);
bool windowEvent;
Window evWindow = GetWindowOfEvent(&event, windowEvent);
//fprintf(stderr, "EVENT %d\n", XCB_EVENT_RESPONSE_TYPE(event));
if (windowEvent)
{
auto window = m_windows.find(evWindow);

View File

@ -25,7 +25,7 @@
#include "XlibCommon.hpp"
#define REF_DPMM 3.7824 /* 96 DPI */
#define REF_DPMM 3.78138
#define FS_ATOM "_NET_WM_STATE_FULLSCREEN"
#define MWM_HINTS_FUNCTIONS (1L << 0)

View File

@ -377,7 +377,7 @@ struct TestApplicationCallback : IApplicationCallback
factory->newShaderDataBinding(pipeline, vfmt, vbo, nullptr, nullptr, 0, nullptr, 1, &texture);
/* Commit objects */
IGraphicsData* data = factory->commit();
IGraphicsDataToken data = factory->commit();
/* Return control to client */
lk.unlock();
@ -458,6 +458,7 @@ struct TestApplicationCallback : IApplicationCallback
}
}
gfxQ->stopRenderer();
m_cv.notify_one();
loaderThread.join();
return 0;