summaryrefslogtreecommitdiff
path: root/threading.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'threading.cpp')
-rw-r--r--threading.cpp66
1 files changed, 37 insertions, 29 deletions
diff --git a/threading.cpp b/threading.cpp
index 84e5463..f1d7284 100644
--- a/threading.cpp
+++ b/threading.cpp
@@ -34,50 +34,58 @@ TestThread(void *ptr)
}
static bool32
-Threading_IsActive()
+Threading_IsActive(render_type RenderType)
{
+ int32 Threads = 16;
+ if (RenderType == render_type_brush)
+ Threads = 4;
uint32 C = SDL_AtomicGet(&CompletedEntries);
- Assert(C < 17);
- return (C == 16) ? false : true;
+ Assert(C < Threads + 1);
+ return (C == Threads) ? false : true;
}
static void
-Threading_BitmapOp(void *Data, void *OutputBuffer, rectangle InitialRenderRegion)
+Threading_BitmapOp(void *Data, void *OutputBuffer, render_type RenderType, rectangle InitialRenderRegion)
{
- uint16 TileWidth = (InitialRenderRegion.Max.x - InitialRenderRegion.Min.x) / 4;
- uint16 TileHeight = (InitialRenderRegion.Max.y - InitialRenderRegion.Min.y) / 4;
+ int i = (RenderType != render_type_brush) ? 4 : 2;
+ uint16 TileWidth = (InitialRenderRegion.Max.x - InitialRenderRegion.Min.x) / i;
+ uint16 TileHeight = (InitialRenderRegion.Max.y - InitialRenderRegion.Min.y) / i;
SDL_AtomicSet(&QueuedEntries, 0);
SDL_AtomicSet(&CurrentEntry, 0);
SDL_AtomicSet(&CompletedEntries, 0);
- for (int y = 0; y < 4; y++) {
- for (int x = 0; x < 4; x++) {
- // if (x == y) {
- rectangle RenderRegion = { TileWidth*x, TileHeight*y, TileWidth + TileWidth*x, TileHeight + TileHeight*y };
+ for (int y = 0; y < i; y++) {
+ for (int x = 0; x < i; x++) {
+ // if ((x == 0 && y == 0)|| RenderType != render_type_brush) {
- RenderRegion.Min.x -= RenderRegion.Min.x % 8;
- RenderRegion.Min.y -= RenderRegion.Min.y % 8;
- RenderRegion.Max.x -= RenderRegion.Max.x % 8;
- RenderRegion.Max.y -= RenderRegion.Max.y % 8;
+ rectangle RenderRegion = { TileWidth*x, TileHeight*y,
+ TileWidth + TileWidth*x, TileHeight + TileHeight*y };
- if (RenderRegion.Max.x > InitialRenderRegion.Max.x)
- RenderRegion.Max.x = InitialRenderRegion.Max.x;
- if (RenderRegion.Max.y > InitialRenderRegion.Max.y)
- RenderRegion.Max.y = InitialRenderRegion.Max.y;
+ if (RenderType == render_type_brush) {
+ RenderRegion.Min.x += InitialRenderRegion.Min.x;
+ RenderRegion.Min.y += InitialRenderRegion.Min.y;
+ RenderRegion.Max.x += InitialRenderRegion.Min.x;
+ RenderRegion.Max.y += InitialRenderRegion.Min.y;
+ }
- if (x == 3)
- RenderRegion.Max.x = InitialRenderRegion.Max.x;
- if (y == 3)
- RenderRegion.Max.y = InitialRenderRegion.Max.y;
+ if (RenderRegion.Max.x > InitialRenderRegion.Max.x)
+ RenderRegion.Max.x = InitialRenderRegion.Max.x;
+ if (RenderRegion.Max.y > InitialRenderRegion.Max.y)
+ RenderRegion.Max.y = InitialRenderRegion.Max.y;
- render_entry Entry = { Data, OutputBuffer, RenderRegion };
+ if (x == i-1)
+ RenderRegion.Max.x = InitialRenderRegion.Max.x;
+ if (y == i-1)
+ RenderRegion.Max.y = InitialRenderRegion.Max.y;
- uint32 Q = SDL_AtomicGet(&QueuedEntries);
- *(Entries + Q) = Entry;
- SDL_AtomicAdd(&QueuedEntries, 1);
- SDL_SemPost(Semaphore);
- }
- // }
+ render_entry Entry = { Data, OutputBuffer, RenderType, RenderRegion };
+
+ uint32 Q = SDL_AtomicGet(&QueuedEntries);
+ *(Entries + Q) = Entry;
+ SDL_AtomicAdd(&QueuedEntries, 1);
+ SDL_SemPost(Semaphore);
+ // }
+ }
}
}