Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 166fe75

Browse files
committed
Merge branch 'refactor-graphics' of https://github.com/runrev/livecode into refactor-graphics
2 parents 790760a + 4609199 commit 166fe75

11 files changed

Lines changed: 105 additions & 123 deletions

engine/src/lnxstack.cpp

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -905,15 +905,8 @@ class MCLinuxStackSurface: public MCStackSurface
905905
}
906906
};
907907

908-
void MCStack::updatewindow(MCRegionRef p_region)
908+
void MCStack::device_updatewindow(MCRegionRef p_region)
909909
{
910-
MCRegionRef t_device_region;
911-
t_device_region = nil;
912-
913-
// IM-2012-08-12: [[ ResIndependence ]] Scale update region to device coords
914-
/* UNCHECKED */ MCRegionCreate(t_device_region);
915-
/* UNCHECKED */ MCRegionSetRect(t_device_region, MCGRectangleGetIntegerBounds(MCResUserToDeviceRect(MCRegionGetBoundingBox(p_region))));
916-
917910
MCRegionRef t_update_region;
918911
t_update_region = nil;
919912

@@ -930,21 +923,21 @@ void MCStack::updatewindow(MCRegionRef p_region)
930923
}
931924

932925
if (t_update_region != nil)
933-
MCRegionUnion(t_update_region, t_update_region, t_device_region);
926+
MCRegionUnion(t_update_region, t_update_region, p_region);
934927
else
935-
t_update_region = t_device_region;
928+
t_update_region = p_region;
936929

937930
onexpose(t_update_region);
938931

939-
if (t_update_region != t_device_region)
932+
if (t_update_region != p_region)
940933
MCRegionDestroy(t_update_region);
941934
}
942935

943-
void MCStack::updatewindowwithcallback(MCRegionRef p_region, MCStackUpdateCallback p_callback, void *p_context)
936+
void MCStack::device_updatewindowwithcallback(MCRegionRef p_region, MCStackUpdateCallback p_callback, void *p_context)
944937
{
945938
s_update_callback = p_callback;
946939
s_update_context = p_context;
947-
updatewindow(p_region);
940+
device_updatewindow(p_region);
948941
s_update_callback = nil;
949942
s_update_context = nil;
950943
}

engine/src/mblandroiddc.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ class MCOpenGLStackSurface: public MCStackSurface
865865
}
866866
};
867867

868-
void MCStack::updatewindow(MCRegionRef p_region)
868+
void MCStack::device_updatewindow(MCRegionRef p_region)
869869
{
870870
if (!s_android_opengl_enabled)
871871
{
@@ -875,7 +875,7 @@ void MCStack::updatewindow(MCRegionRef p_region)
875875

876876
// Note that as android regions are just rects at the moment, we cheat.
877877
MCRectangle t_rect;
878-
t_rect = MCGRectangleGetIntegerBounds(MCResUserToDeviceRect(MCRegionGetBoundingBox(p_region)));
878+
t_rect = MCRegionGetBoundingBox(p_region);
879879

880880
MCRegionRef t_actual_region;
881881
MCRegionCreate(t_actual_region);
@@ -933,15 +933,15 @@ void MCStack::updatewindow(MCRegionRef p_region)
933933

934934
// MW-2011-12-12: [[ Bug 9908 ]] Make sure both front and back buffers hold the same image
935935
// to prevent a flicker back to an old frame when making the opengl layer visible.
936-
updatewindow(p_region);
936+
device_updatewindow(p_region);
937937

938938
MCAndroidEngineRemoteCall("hideBitmapView", "v", nil);
939939
}
940940
}
941941

942942
}
943943

944-
void MCStack::updatewindowwithcallback(MCRegionRef p_region, MCStackUpdateCallback p_callback, void *p_context)
944+
void MCStack::device_updatewindowwithcallback(MCRegionRef p_region, MCStackUpdateCallback p_callback, void *p_context)
945945
{
946946
MCRectangle t_rect;
947947
t_rect = MCRegionGetBoundingBox(p_region);

engine/src/mbliphonegfx.mm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static void do_update(void *p_dirty)
6868
[MCIPhoneGetDisplayView() renderInRegion: (MCRegionRef)p_dirty];
6969
}
7070

71-
void MCStack::updatewindow(MCRegionRef p_dirty_rgn)
71+
void MCStack::device_updatewindow(MCRegionRef p_dirty_rgn)
7272
{
7373
// MW-2011-09-13: [[ Redraw ]] Only perform an update if the window should
7474
// draw (i.e. if it is top-most).
@@ -349,8 +349,8 @@ - (void)renderInRegion: (MCRegionRef)p_region
349349
MCRectangle t_visible;
350350
t_visible = MCRegionGetBoundingBox(p_region);
351351

352-
[ self setNeedsDisplayInRect: CGRectMake((float)t_visible . x / MCIPhoneGetResolutionScale(), (float)t_visible . y / MCIPhoneGetResolutionScale(),
353-
(float)t_visible . width / MCIPhoneGetResolutionScale(), (float)t_visible . height / MCIPhoneGetResolutionScale()) ];
352+
[ self setNeedsDisplayInRect: CGRectMake((float)t_visible . x / MCIPhoneGetDeviceScale(), (float)t_visible . y / MCIPhoneGetDeviceScale(),
353+
(float)t_visible . width / MCIPhoneGetDeviceScale(), (float)t_visible . height / MCIPhoneGetDeviceScale()) ];
354354
[[self layer] display];
355355
}
356356

engine/src/osxcisupport.mm

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,8 @@ rei_boolean_t coreimage_visualeffect_lookup(const char *p_name, rei_visualeffect
240240

241241
static CIFilter *sg_current_filter = nil;
242242
static rei_rectangle_t sg_current_area;
243+
// IM-2013-08-29: [[ RefactorGraphics ]] Record surface height so we can transform image location to flipped context
244+
static CGFloat sg_current_height;
243245

244246
bool MCGImageToCIImage(MCGImageRef p_image, CIImage *&r_image)
245247
{
@@ -260,7 +262,7 @@ bool MCGImageToCIImage(MCGImageRef p_image, CIImage *&r_image)
260262
return t_success;
261263
}
262264

263-
rei_boolean_t coreimage_visualeffect_begin(rei_handle_t p_handle, MCGImageRef p_image_a, MCGImageRef p_image_b, rei_rectangle_ref_t p_area, rei_visualeffect_parameter_list_ref_t p_parameters)
265+
rei_boolean_t coreimage_visualeffect_begin(rei_handle_t p_handle, MCGImageRef p_image_a, MCGImageRef p_image_b, rei_rectangle_ref_t p_area, CGFloat p_surface_height, rei_visualeffect_parameter_list_ref_t p_parameters)
264266
{
265267
bool t_success = true;
266268

@@ -377,6 +379,7 @@ rei_boolean_t coreimage_visualeffect_begin(rei_handle_t p_handle, MCGImageRef p_
377379
sg_current_filter = t_filter;
378380

379381
sg_current_area = *p_area;
382+
sg_current_height = p_surface_height;
380383
}
381384

382385
NS_HANDLER
@@ -408,7 +411,7 @@ rei_boolean_t coreimage_visualeffect_step(MCStackSurface *p_target, float p_time
408411
t_context = [CIContext contextWithCGContext: t_cg_context options: nil];
409412
CGContextClearRect(t_cg_context, CGRectMake(sg_current_area . x, sg_current_area . y, sg_current_area . width, sg_current_area . height));
410413
[sg_current_filter setValue: [NSNumber numberWithFloat: p_time] forKey: @"inputTime"];
411-
[t_context drawImage: [sg_current_filter valueForKey: @"outputImage"] atPoint: CGPointMake(sg_current_area . x, sg_current_area . y) fromRect: CGRectMake(0, 0, sg_current_area . width, sg_current_area . height)];
414+
[t_context drawImage: [sg_current_filter valueForKey: @"outputImage"] atPoint: CGPointMake(sg_current_area . x, sg_current_height - (sg_current_area . y + sg_current_area . height)) fromRect: CGRectMake(0, 0, sg_current_area . width, sg_current_area . height)];
412415
CGContextFlush(t_cg_context);
413416
NS_HANDLER
414417
t_result = false;

engine/src/osxcoreimage.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static bool s_coreimage_initialized = false;
4848
extern rei_boolean_t coreimage_visualeffect_initialise(void);
4949
extern void coreimage_visualeffect_finalise(void);
5050
extern rei_boolean_t coreimage_visualeffect_lookup(const char *p_name, rei_visualeffect_info_ref_t *r_info);
51-
extern rei_boolean_t coreimage_visualeffect_begin(rei_handle_t p_handle, MCGImageRef p_image_a, MCGImageRef p_image_b, rei_rectangle_ref_t p_area, rei_visualeffect_parameter_list_ref_t p_parameters);
51+
extern rei_boolean_t coreimage_visualeffect_begin(rei_handle_t p_handle, MCGImageRef p_image_a, MCGImageRef p_image_b, rei_rectangle_ref_t p_area, CGFloat p_surface_height, rei_visualeffect_parameter_list_ref_t p_parameters);
5252
extern rei_boolean_t coreimage_visualeffect_step(MCStackSurface *p_target, float p_time);
5353
extern rei_boolean_t coreimage_visualeffect_end(void);
5454

@@ -66,7 +66,8 @@ void MCCoreImageUnregister(void)
6666
}
6767
}
6868

69-
bool MCCoreImageEffectBegin(const char *p_name, MCGImageRef p_source_a, MCGImageRef p_source_b, const MCRectangle& p_rect, MCEffectArgument *p_arguments)
69+
// IM-2013-08-29: [[ RefactorGraphics ]] add surface height param to pass through to coreimage_visualeffect_begin
70+
bool MCCoreImageEffectBegin(const char *p_name, MCGImageRef p_source_a, MCGImageRef p_source_b, const MCRectangle& p_rect, MCGFloat p_surface_height, MCEffectArgument *p_arguments)
7071
{
7172
if (!s_coreimage_initialized)
7273
return false;
@@ -229,7 +230,7 @@ bool MCCoreImageEffectBegin(const char *p_name, MCGImageRef p_source_a, MCGImage
229230
}
230231
else
231232
{
232-
if (!coreimage_visualeffect_begin(t_info -> handle, p_source_a, p_source_b, &t_rect, t_parameters))
233+
if (!coreimage_visualeffect_begin(t_info -> handle, p_source_a, p_source_b, &t_rect, p_surface_height, t_parameters))
233234
return false;
234235
}
235236

engine/src/osxstack.cpp

Lines changed: 25 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ void MCStack::enablewindow(bool p_enable)
900900

901901
// MW-2011-09-11: [[ Redraw ]] Force an immediate update of the window within the given
902902
// region. The actual rendering is done by deferring to the 'redrawwindow' method.
903-
void MCStack::updatewindow(MCRegionRef p_region)
903+
void MCStack::device_updatewindow(MCRegionRef p_region)
904904
{
905905
HIViewRef t_root;
906906
GetRootControl((WindowPtr)window -> handle . window, &t_root);
@@ -910,16 +910,8 @@ void MCStack::updatewindow(MCRegionRef p_region)
910910

911911
// MW-2011-10-07: [[ Bug 9792 ]] If the mask hasn't changed, use the update region,
912912
// else redraw the whole view.
913-
if (!getextendedstate(ECS_MASK_CHANGED))
914-
{
915-
// IM-2013-08-01: [[ ResIndependence ]] Scale update region to device coords
916-
MCRegionRef t_dev_region;
917-
t_dev_region = nil;
918-
/* UNCHECKED */ MCRegionCreate(t_dev_region);
919-
MCRegionSetRect(t_dev_region, MCGRectangleGetIntegerBounds(MCResUserToDeviceRect(MCRegionGetBoundingBox(p_region))));
920-
HIViewSetNeedsDisplayInRegion(t_view, (RgnHandle)t_dev_region, TRUE);
921-
MCRegionDestroy(t_dev_region);
922-
}
913+
if (!getextendedstate(ECS_MASK_CHANGED) || s_update_callback != nil)
914+
HIViewSetNeedsDisplayInRegion(t_view, (RgnHandle)p_region, TRUE);
923915
else
924916
{
925917
HIViewSetNeedsDisplay(t_view, TRUE);
@@ -947,47 +939,16 @@ void MCStack::updatewindow(MCRegionRef p_region)
947939
}
948940
}
949941

950-
void MCStack::updatewindowwithcallback(MCRegionRef p_region, MCStackUpdateCallback p_callback, void *p_context)
942+
void MCStack::device_updatewindowwithcallback(MCRegionRef p_region, MCStackUpdateCallback p_callback, void *p_context)
951943
{
952-
HIViewRef t_root;
953-
GetRootControl((WindowPtr)window -> handle . window, &t_root);
954-
955-
HIViewRef t_view;
956-
GetIndexedSubControl(t_root, 1, &t_view);
957-
958-
// IM-2013-08-01: [[ ResIndependence ]] Scale update region to device coords
959-
MCRegionRef t_dev_region;
960-
t_dev_region = nil;
961-
/* UNCHECKED */ MCRegionCreate(t_dev_region);
962-
MCRegionSetRect(t_dev_region, MCGRectangleGetIntegerBounds(MCResUserToDeviceRect(MCRegionGetBoundingBox(p_region))));
963-
HIViewSetNeedsDisplayInRegion(t_view, (RgnHandle)t_dev_region, TRUE);
964-
MCRegionDestroy(t_dev_region);
965-
966944
// Set the file-local static to the callback to use (stacksurface picks this up!)
967945
s_update_callback = p_callback;
968946
s_update_context = p_context;
969-
HIViewRender(t_view);
947+
// IM-2013-08-29: [[ RefactorGraphics ]] simplify by calling device_updatewindow, which performs the same actions
948+
device_updatewindow(p_region);
970949
// Unset the file-local static.
971950
s_update_callback = nil;
972951
s_update_context = nil;
973-
974-
// MW-2011-10-18: [[ Bug 9798 ]] Make sure we force a screen update after every
975-
// update.
976-
// MW-2012-09-10: [[ Revert Bug 10333 ]] Delayed until IDE issues can be resolved.
977-
// HIWindowFlush((WindowPtr)window -> handle . window);
978-
979-
// Update the shadow, if required.
980-
if (getextendedstate(ECS_MASK_CHANGED))
981-
{
982-
// MW-2012-09-10: [[ Revert Bug 10333 ]] Delayed until IDE issues can be resolved.
983-
HIWindowFlush((WindowPtr)window -> handle . window);
984-
985-
HIWindowInvalidateShadow((WindowPtr)window -> handle . window);
986-
987-
EnableScreenUpdates();
988-
989-
setextendedstate(False, ECS_MASK_CHANGED);
990-
}
991952
}
992953

993954
////////////////////////////////////////////////////////////////////////////////
@@ -1124,17 +1085,19 @@ class MCMacStackSurface: public MCStackSurface
11241085
CGContextRef m_context;
11251086

11261087
int32_t m_surface_height;
1088+
int32_t m_surface_scroll;
11271089

11281090
MCRectangle m_locked_area;
11291091
MCGContextRef m_locked_context;
11301092
void *m_locked_bits;
11311093
uint32_t m_locked_stride;
11321094

11331095
public:
1134-
MCMacStackSurface(MCStack *p_stack, int32_t p_surface_height, MCRegionRef p_region, CGContextRef p_context)
1096+
MCMacStackSurface(MCStack *p_stack, int32_t p_surface_height, int32_t p_surface_scroll, MCRegionRef p_region, CGContextRef p_context)
11351097
{
11361098
m_stack = p_stack;
11371099
m_surface_height = p_surface_height;
1100+
m_surface_scroll = p_surface_scroll;
11381101
m_region = p_region;
11391102
m_context = p_context;
11401103

@@ -1155,15 +1118,17 @@ class MCMacStackSurface: public MCStackSurface
11551118
t_rect = MCRegionGetBoundingBox(m_region);
11561119
CGContextClearRect(m_context, CGRectMake(t_rect . x, m_surface_height - (t_rect . y + t_rect . height), t_rect . width, t_rect . height));
11571120

1158-
// MW-2012-07-25: [[ Bug ]] Make sure we use signed arithmetic to
1159-
// compute the y-origin otherwise it wraps to 2^32!
1160-
int32_t t_mask_height, t_mask_width;
1161-
t_mask_width = (int32_t)CGImageGetWidth(t_mask);
1162-
t_mask_height = (int32_t)CGImageGetHeight(t_mask);
1121+
// IM-2013-08-29: [[ ResIndependence ]] scale mask to device coords
1122+
MCGFloat t_scale;
1123+
t_scale = MCResGetDeviceScale();
1124+
1125+
MCGFloat t_mask_height, t_mask_width;
1126+
t_mask_width = CGImageGetWidth(t_mask) * t_scale;
1127+
t_mask_height = CGImageGetHeight(t_mask) * t_scale;
11631128

11641129
CGRect t_dst_rect;
11651130
t_dst_rect . origin . x = 0;
1166-
t_dst_rect . origin . y = m_surface_height - t_mask_height - (m_stack -> getscroll() * t_scale);
1131+
t_dst_rect . origin . y = m_surface_height - t_mask_height - m_surface_scroll;
11671132
t_dst_rect . size . width = t_mask_width;
11681133
t_dst_rect . size . height = t_mask_height;
11691134
CGContextClipToMask(m_context, t_dst_rect, t_mask);
@@ -1512,11 +1477,15 @@ OSStatus HIRevolutionStackViewHandler(EventHandlerCallRef p_call_ref, EventRef p
15121477
if (t_graphics != nil)
15131478
{
15141479
// IM-2013-08-23: [[ ResIndependence ]] provide surface height in device scale
1515-
MCRectangle t_device_rect;
1516-
t_device_rect = MCGRectangleGetIntegerBounds(MCResUserToDeviceRect(t_context->stack->getcurcard()->getrect()));
1480+
MCGFloat t_scale;
1481+
t_scale = MCResGetDeviceScale();
15171482

15181483
int32_t t_surface_height;
1519-
t_surface_height = t_device_rect.height;
1484+
t_surface_height = floor(t_context->stack->getcurcard()->getrect().height * t_scale);
1485+
1486+
// IM-2013-08-29: [[ ResIndependence ]] also provide scroll value at device scale
1487+
int32_t t_surface_scroll;
1488+
t_surface_scroll = ceil(t_context->stack->getscroll() * t_scale);
15201489

15211490
// HIView gives us a context in top-left origin mode which isn't so good
15221491
// for our CG rendering so, revert back to bottom-left.
@@ -1526,7 +1495,7 @@ OSStatus HIRevolutionStackViewHandler(EventHandlerCallRef p_call_ref, EventRef p
15261495
// Save the context state
15271496
CGContextSaveGState(t_graphics);
15281497

1529-
MCMacStackSurface t_surface(t_context -> stack, t_surface_height, (MCRegionRef)t_dirty_rgn, t_graphics);
1498+
MCMacStackSurface t_surface(t_context -> stack, t_surface_height, t_surface_scroll, (MCRegionRef)t_dirty_rgn, t_graphics);
15301499

15311500
if (t_surface.Lock())
15321501
{

engine/src/srvstack.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ void MCStack::updatemodifiedmark(void)
126126
{
127127
}
128128

129-
void MCStack::updatewindow(MCRegionRef region)
129+
void MCStack::device_updatewindow(MCRegionRef region)
130130
{
131131
}
132132

engine/src/stack.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,10 @@ class MCStack : public MCObject
511511
// MW-2011-09-10: [[ Redraw ]] Request an immediate update of the given region of the
512512
// window. This is a platform-specific method which causes 'redrawwindow' to be
513513
// invoked.
514+
// IM-2013-08-29: [[ ResIndependence ]] add device-specific version of updatewindow.
515+
// device_updatewindow takes a region in device coordinates.
514516
void updatewindow(MCRegionRef region);
517+
void device_updatewindow(MCRegionRef p_region);
515518

516519
// MW-2011-09-13: [[ Redraw ]] Request an immediate update of the given region of the
517520
// window using the presented pixmap. This is a platform-specific method - note that
@@ -521,7 +524,9 @@ class MCStack : public MCObject
521524
// version which uses a callback function to perform the actual drawing using a
522525
// provided MCStackSurface instance. The MCStackSurface class is now responsible
523526
// for handling any window mask present.
524-
void updatewindowwithcallback(MCRegionRef p_region, MCStackUpdateCallback p_callback, void *p_context);
527+
// IM-2013-08-29: [[ ResIndependence ]] change updatewindowwithcallback to device-specific version.
528+
// device_updatewindowwithcallback takes a region in device coordinates.
529+
void device_updatewindowwithcallback(MCRegionRef p_region, MCStackUpdateCallback p_callback, void *p_context);
525530

526531
// MW-2012-08-06: [[ Fibers ]] Ensure the tilecache is updated to reflect the current
527532
// frame.

engine/src/stack2.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2614,3 +2614,21 @@ void MCStack::render(MCContext *p_context, const MCRectangle& p_dirty)
26142614
}
26152615

26162616
////////////////////////////////////////////////////////////////////////////////
2617+
2618+
void MCStack::updatewindow(MCRegionRef p_region)
2619+
{
2620+
MCRectangle t_update_rect;
2621+
t_update_rect = MCRegionGetBoundingBox(p_region);
2622+
2623+
// IM-2013-08-01: [[ ResIndependence ]] Scale update region to device coords
2624+
MCRegionRef t_dev_region;
2625+
t_dev_region = nil;
2626+
/* UNCHECKED */ MCRegionCreate(t_dev_region);
2627+
MCRegionSetRect(t_dev_region, MCGRectangleGetIntegerBounds(MCResUserToDeviceRect(t_update_rect)));
2628+
2629+
device_updatewindow(t_dev_region);
2630+
2631+
MCRegionDestroy(t_dev_region);
2632+
}
2633+
2634+
////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)