21 #include "../gpu/pipeline.h"
39 DebugAssertion::check(!
bitmap->
isDirty(),
"Reading a dirty bitmap");
41 DebugAssertion::check(gpu,
"Cannot lock a bitmap on GPU: no graphic pipeline instance available");
44 bool transferToGpuNeeded =
false;
45 bool transferFromGpuNeeded =
false;
63 if (
lock.cpu || transferToGpuNeeded || transferFromGpuNeeded) {
65 lock.isDataLocked =
true;
73 auto&
lock = it->second;
76 "Lock target mismatch: a bitmap was previously locked for a different target");
83 if (!
lock.isDataLocked && (transferToGpuNeeded || transferFromGpuNeeded)) {
85 lock.isDataLocked =
true;
94 if (transferToGpuNeeded)
96 else if (transferFromGpuNeeded)
104 DebugAssertion::check(gpu,
"Cannot lock a bitmap on GPU: no graphic pipeline instance available");
120 if (
lock.isDataLocked)
126 auto&
lock = it->second;
129 throw RuntimeError(
"Cannot a bitmap for writing: it was locked for reading before. Lock it for writing first.");
134 lock.isDataLocked =
true;
148 DebugAssertion::check(it !=
bitmaps.end(),
"Trying to unlock a bitmap that is not locked.");
151 auto&
lock = it->second;
153 if (
lock.refs == 0) {
154 if (
lock.isDataLocked)
169 auto&
lock = it.second;
170 if (
lock.isDataLocked)
171 it.first->unlockPixelData();
A very basic class for any image.
bool isDirty() const
Returns true if the bitmap does not contain any valid content.
bool isUpToDate(ProcessingTarget) const
bool upToDate[2]
bitmap up-to-date state on CPU and GPU
void unlock(AbstractBitmap *bitmap)
Drops a lock to the bitmap.
void lock(GraphicPipeline *gpu, AbstractBitmap *input, AbstractBitmap *output)
std::map< AbstractBitmap *, LockDescriptor > bitmaps
void readLock(GraphicPipeline *gpu, AbstractBitmap *bitmap, ProcessingTarget target)
Locks content of a bitmap for reading using a specific processing target device.
void writeLock(GraphicPipeline *gpu, AbstractBitmap *bitmap, ProcessingTarget target)
Locks content of a bitmap for writing using a specific processing target device.
void unlockAll()
Unlocks all the locked bitmaps unconditionally.
Internal low-level GPU control API.
void pullPixels(AbstractBitmap &bitmap)
Transfers bitmap pixels from GPU to CPU.
void pushPixels(AbstractBitmap &bitmap)
Transfers bitmap pixels from CPU to GPU.
void unlockPixelData()
Unlocks access to the CPU memory buffer containing pixel data.
void lockPixelData()
Locks access to the CPU memory buffer containing pixel data.
static void check(const bool condition, const std::string &message)
#define BEATMUP_DEBUG_E(...)
Beatmup::InternalBitmap * bitmap