Skip to content

Commit 975337b

Browse files
[[ ThreadedRendering ]] Updated stack tile creation and rendering to platform indapendent level.
[[ ThreadedRendering ]] Put locks around stack id cache access. [[ ThreadedRendering ]] Fixed minor bug in legacy gradients.
1 parent 585c872 commit 975337b

26 files changed

+441
-835
lines changed

engine/src/desktop-dc.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,10 @@ bool MCScreenDC::isbackdrop(MCPlatformWindowRef p_window)
556556
void MCScreenDC::redrawbackdrop(MCPlatformSurfaceRef p_surface, MCGRegionRef p_region)
557557
{
558558
MCGContextRef t_context;
559-
if (MCPlatformSurfaceLockGraphics(p_surface, p_region, t_context))
559+
MCGRaster t_raster;
560+
MCGIntegerRectangle t_bounds;
561+
t_bounds = MCGRegionGetBounds(p_region);
562+
if (MCPlatformSurfaceLockGraphics(p_surface, t_bounds, t_context, t_raster))
560563
{
561564
MCGraphicsContext *t_gfxcontext;
562565
/* UNCHECKED */ t_gfxcontext = new MCGraphicsContext(t_context);
@@ -568,7 +571,7 @@ void MCScreenDC::redrawbackdrop(MCPlatformSurfaceRef p_surface, MCGRegionRef p_r
568571
t_gfxcontext -> fillrect(MCRectangleFromMCGIntegerRectangle(MCGRegionGetBounds(p_region)), false);
569572
delete t_gfxcontext;
570573

571-
MCPlatformSurfaceUnlockGraphics(p_surface);
574+
MCPlatformSurfaceUnlockGraphics(p_surface, t_bounds, t_context, t_raster);
572575
}
573576
}
574577

engine/src/desktop-stack.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -369,24 +369,24 @@ class MCDesktopStackSurface: public MCStackSurface
369369
{
370370
}
371371

372-
bool LockGraphics(MCGRegionRef p_area, MCGContextRef& r_context)
372+
bool LockGraphics(MCGIntegerRectangle p_region, MCGContextRef& r_context, MCGRaster &r_raster)
373373
{
374-
return MCPlatformSurfaceLockGraphics(m_surface, p_area, r_context);
374+
return MCPlatformSurfaceLockGraphics(m_surface, p_region, r_context, r_raster);
375375
}
376376

377-
void UnlockGraphics(void)
377+
void UnlockGraphics(MCGIntegerRectangle p_region, MCGContextRef p_context, MCGRaster &p_raster)
378378
{
379-
MCPlatformSurfaceUnlockGraphics(m_surface);
379+
MCPlatformSurfaceUnlockGraphics(m_surface, p_region, p_context, p_raster);
380380
}
381381

382382
bool LockPixels(MCGIntegerRectangle p_area, MCGRaster& r_raster)
383383
{
384384
return MCPlatformSurfaceLockPixels(m_surface, p_area, r_raster);
385385
}
386386

387-
void UnlockPixels(void)
387+
void UnlockPixels(MCGIntegerRectangle p_area, MCGRaster& p_raster)
388388
{
389-
MCPlatformSurfaceUnlockPixels(m_surface);
389+
MCPlatformSurfaceUnlockPixels(m_surface, p_area, p_raster);
390390
}
391391

392392
bool LockTarget(MCStackSurfaceTargetType p_type, void*& r_context)

engine/src/idraw.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
3535
#include "graphicscontext.h"
3636
#include "graphics_util.h"
3737

38-
#include "stacktile.h"
39-
4038
////////////////////////////////////////////////////////////////////////////////
4139

4240
bool MCImage::get_rep_and_transform(MCImageRep *&r_rep, bool &r_has_transform, MCGAffineTransform &r_transform)
@@ -153,9 +151,7 @@ void MCImage::drawme(MCDC *dc, int2 sx, int2 sy, uint2 sw, uint2 sh, int2 dx, in
153151

154152
// IM-2014-01-31: [[ HiDPI ]] Get the appropriate image for the combined
155153
// context device & image transforms
156-
MCStackTileMainThreadLock();
157154
t_success = t_rep->LockImageFrame(currentframe, t_device_scale, t_frame);
158-
MCStackTileMainThreadUnlock();
159155
if (t_success)
160156
{
161157
MCImageDescriptor t_image;
@@ -209,14 +205,11 @@ void MCImage::drawme(MCDC *dc, int2 sx, int2 sy, uint2 sw, uint2 sh, int2 dx, in
209205
drawnodata(dc, drect, sw, sh, dx, dy, dw, dh);
210206
}
211207

212-
MCStackTileMainThreadLock();
213208
t_rep->UnlockImageFrame(currentframe, t_frame);
214-
MCStackTileMainThreadUnlock();
215209
}
216210

217211
if (state & CS_DO_START)
218212
{
219-
MCStackTileMainThreadLock();
220213
MCGImageFrame *t_frame = nil;
221214
if (m_rep->LockImageFrame(currentframe, getdevicescale(), t_frame))
222215
{
@@ -225,7 +218,6 @@ void MCImage::drawme(MCDC *dc, int2 sx, int2 sy, uint2 sw, uint2 sh, int2 dx, in
225218

226219
state &= ~CS_DO_START;
227220
}
228-
MCStackTileMainThreadUnlock();
229221
}
230222
}
231223
else if (filename != nil)

engine/src/image_rep.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
2424

2525
#include "image.h"
2626
#include "image_rep.h"
27+
#include "systhreads.h"
2728

2829
////////////////////////////////////////////////////////////////////////////////
2930

@@ -73,11 +74,14 @@ MCLoadableImageRep::MCLoadableImageRep()
7374
m_frames_premultiplied = false;
7475

7576
m_next = m_prev = nil;
77+
78+
/* UNCHECKED */ MCThreadMutexCreate(m_frame_lock);
7679
}
7780

7881
MCLoadableImageRep::~MCLoadableImageRep()
7982
{
8083
ReleaseFrames();
84+
MCThreadMutexRelease(m_frame_lock);
8185
}
8286

8387
////////////////////////////////////////////////////////////////////////////////
@@ -241,13 +245,17 @@ bool MCLoadableImageRep::LockImageFrame(uindex_t p_frame, MCGFloat p_density, MC
241245
if (p_frame >= m_frame_count)
242246
return false;
243247

248+
MCThreadMutexLock(m_frame_lock);
249+
244250
// prevent data being removed by cache flush
245251
m_lock_count++;
246252

247253
// prevent deletion due to ImageRep::Release()
248254
Retain();
249255

250256
r_frame = &m_frames[p_frame];
257+
258+
MCThreadMutexUnlock(m_frame_lock);
251259

252260
return true;
253261
}
@@ -325,10 +333,14 @@ void MCLoadableImageRep::UnlockImageFrame(uindex_t p_index, MCGImageFrame *p_fra
325333
if (m_frames == nil || &m_frames[p_index] != p_frame)
326334
return;
327335

336+
MCThreadMutexLock(m_frame_lock);
337+
328338
m_lock_count--;
329339
Release();
330340

331341
MoveRepToHead(this);
342+
343+
MCThreadMutexUnlock(m_frame_lock);
332344
}
333345

334346
void MCLoadableImageRep::UnlockBitmapFrame(uindex_t p_index, MCBitmapFrame *p_frame)

engine/src/image_rep.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
1717
#ifndef __MC_IMAGE_REP_H__
1818
#define __MC_IMAGE_REP_H__
1919

20+
#include "systhreads.h"
21+
2022
typedef enum
2123
{
2224
kMCImageRepUnknown,
@@ -160,6 +162,8 @@ class MCLoadableImageRep : public MCCachedImageRep
160162
MCGImageFrame *m_frames;
161163
uindex_t m_frame_count;
162164
bool m_frames_premultiplied;
165+
166+
MCThreadMutexRef m_frame_lock;
163167
};
164168

165169
////////////////////////////////////////////////////////////////////////////////

engine/src/imagelist.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
#include "graphics_util.h"
1616

17-
#include "stacktile.h"
18-
1917
////////////////////////////////////////////////////////////////////////////////
2018

2119
// IM-2013-08-14: [[ ResIndependence ]] MCPattern struct which associates an image with a scale
@@ -215,9 +213,7 @@ bool MCPatternLockForContextTransform(MCPatternRef p_pattern, const MCGAffineTra
215213
MCGFloat t_scale;
216214
t_scale = MCGAffineTransformGetEffectiveScale(t_combined);
217215

218-
MCStackTileMainThreadLock();
219216
t_success = p_pattern->source->LockImageFrame(0, t_scale, t_frame);
220-
MCStackTileMainThreadUnlock();
221217

222218
if (t_success)
223219
{
@@ -267,9 +263,7 @@ bool MCPatternLockForContextTransform(MCPatternRef p_pattern, const MCGAffineTra
267263

268264
t_image = MCGImageRetain(t_frame->image);
269265
}
270-
MCStackTileMainThreadLock();
271266
p_pattern->source->UnlockImageFrame(0, t_frame);
272-
MCStackTileMainThreadUnlock();
273267
}
274268

275269
if (!t_success)

0 commit comments

Comments
 (0)