@@ -32,6 +32,8 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
3232#include " graphics_util.h"
3333#include " globals.h"
3434
35+ #include " region.h"
36+
3537/* ================================================================
3638 * Stack initialisation
3739 * ================================================================ */
@@ -109,34 +111,83 @@ MCStack::release_window_buffer()
109111 * View management
110112 * ================================================================ */
111113
114+ static MCStackUpdateCallback s_updatewindow_callback = nullptr ;
115+ static void *s_updatewindow_context = nullptr ;
116+
112117bool MCStack::view_platform_dirtyviewonresize () const
113118{
114119 return true ;
115120}
116121
117- void
118- MCStack::view_platform_updatewindow (MCRegionRef p_dirty_region)
122+ void MCStack::view_platform_updatewindowwithcallback (MCRegionRef p_region, MCStackUpdateCallback p_callback, void *p_context)
123+ {
124+ s_updatewindow_callback = p_callback;
125+ s_updatewindow_context = p_context;
126+
127+ view_platform_updatewindow (p_region);
128+
129+ s_updatewindow_callback = nil;
130+ s_updatewindow_context = nil;
131+ }
132+
133+ void MCStack::view_platform_updatewindow (MCRegionRef p_dirty_region)
119134{
120- /* FIXME implement HiDPI support */
135+ MCRegionRef t_scaled_region;
136+ t_scaled_region = nil;
137+
138+ MCRegionRef t_screen_region;
139+ t_screen_region = nil;
140+
141+ MCGFloat t_scale;
142+ t_scale = MCResGetPixelScale ();
143+
144+ if (t_scale != 1.0 )
145+ {
146+ /* UNCHECKED */ MCRegionTransform (p_dirty_region, MCGAffineTransformMakeScale (t_scale, t_scale), t_scaled_region);
147+ t_screen_region = t_scaled_region;
148+ }
149+ else
150+ t_screen_region = p_dirty_region;
151+
152+ view_device_updatewindow (t_screen_region);
153+
154+ if (t_scaled_region != nil)
155+ MCRegionDestroy (t_scaled_region);
156+ }
121157
158+ void MCStack::view_device_updatewindow (MCRegionRef p_region)
159+ {
122160 /* dirtyrect() calls that occur prior to configure() being called
123161 * for the first time will result in an update region being too
124162 * big. Restrict to a valid region. */
125163
126164 uint32_t t_window = reinterpret_cast <uint32_t >(window);
127165
128- MCGRegionRef t_region = MCGRegionRef (p_dirty_region );
129- MCRectangle t_valid = MCEmscriptenGetWindowRect (t_window );
130- t_valid .x = t_valid .y = 0 ;
166+ MCRectangle t_window_rect = MCEmscriptenGetWindowRect (t_window );
167+ MCRectangle t_canvas_rect = MCRectangleGetScaledCeilingRect (t_window_rect, MCResGetPixelScale () );
168+ t_canvas_rect .x = t_canvas_rect .y = 0 ;
131169
132- MCGRegionIntersectRect ( t_region, MCRectangleToMCGIntegerRectangle (t_valid) );
170+ MCGRegionRef t_region = MCGRegionRef (p_region );
133171
134- MCGIntegerRectangle t_rect = MCGRegionGetBounds (t_region);
172+ MCGRegionIntersectRect (t_region, MCRectangleToMCGIntegerRectangle (t_canvas_rect) );
135173
136- MCEmscriptenSyncCanvasSize (t_window, t_valid.width , t_valid.height );
137-
138- MCHtmlCanvasStackSurface t_surface (t_window, t_rect);
139- view_surface_redrawwindow (&t_surface, t_region);
174+ MCGIntegerRectangle t_rect = MCGRegionGetBounds (t_region);
175+ MCEmscriptenSyncCanvasSize (t_window, t_canvas_rect.width , t_canvas_rect.height );
176+
177+ // IM-2014-01-30: [[ HiDPI ]] Ensure stack backing scale is set
178+ view_setbackingscale (MCResGetPixelScale ());
179+
180+ MCHtmlCanvasStackSurface t_surface (t_window, MCGRegionGetBounds (t_region));
181+ if (t_surface.Lock ())
182+ {
183+ // IM-2014-01-31: [[ HiDPI ]] If a callback is given then use it to render to the surface
184+ if (s_updatewindow_callback != nil)
185+ s_updatewindow_callback (&t_surface, (MCRegionRef)t_region, s_updatewindow_context);
186+ else
187+ view_surface_redrawwindow (&t_surface, t_region);
188+
189+ t_surface.Unlock ();
190+ }
140191}
141192
142193MCRectangle
0 commit comments