bool LockPixels(MCRegionRef p_area, MCGRaster& r_raster) { if (m_bitmap == nil || m_locked) return false; MCRectangle t_bounds = MCRegionGetBoundingBox(m_region); MCRectangle t_actual_area; t_actual_area = MCU_intersect_rect(MCRegionGetBoundingBox(p_area), t_bounds); if (MCU_empty_rect(t_actual_area)) return false; /* UNCHECKED */ MCRegionIncludeRect(m_redraw_region, t_actual_area); uint8_t *t_bits = (uint8_t*)m_raster.pixels + (t_actual_area.y - t_bounds.y) * m_raster.stride + (t_actual_area.x - t_bounds.x) * sizeof(uint32_t); m_locked_area = t_actual_area; r_raster . format = kMCGRasterFormat_ARGB; r_raster . width = t_actual_area . width; r_raster . height = t_actual_area . height; r_raster . stride = m_raster.stride; r_raster . pixels = t_bits; m_locked = true; return true; }
bool LockGraphics(MCRegionRef p_area, MCContext*& r_context) { MCRectangle t_actual_area; t_actual_area = MCU_intersect_rect(MCRegionGetBoundingBox(p_area), MCRegionGetBoundingBox(m_region)); if (MCU_empty_rect(t_actual_area)) return false; m_locked_pixmap = MCscreen -> createpixmap(t_actual_area . width, t_actual_area . height, 0, False); if (m_locked_pixmap != nil) { m_locked_context = MCscreen -> createcontext(m_locked_pixmap, False, False); if (m_locked_context != nil) { m_locked_context -> setorigin(t_actual_area . x, t_actual_area . y); m_locked_context -> setclip(t_actual_area); m_locked_area = t_actual_area; r_context = m_locked_context; return true; } MCscreen -> freepixmap(m_locked_pixmap); } return false; }
void MCStack::updatewindowwithbuffer(Pixmap p_buffer, MCRegionRef p_region) { s_update_pixmap = p_buffer; s_update_rect = MCRegionGetBoundingBox(p_region); updatewindow(p_region); s_update_pixmap = nil; }
bool LockPixmap(MCRegionRef p_area, Pixmap& r_pixmap) { MCRectangle t_actual_area; t_actual_area = MCU_intersect_rect(MCRegionGetBoundingBox(p_area), MCRegionGetBoundingBox(m_region)); if (MCU_empty_rect(t_actual_area)) return false; m_locked_pixmap = MCscreen -> createpixmap(t_actual_area . width, t_actual_area . height, 0, False); if (m_locked_pixmap == nil) return false; m_locked_area = t_actual_area; r_pixmap = m_locked_pixmap; return true; }
bool MCRegionCalculateMask(MCRegionRef region, int32_t width, int32_t height, MCBitmap*& r_mask) { MCRectangle t_rect; t_rect = MCRegionGetBoundingBox(region); MCBitmap *t_mask; t_mask = MCscreen -> createimage(1, width, height, True, 255, False, False); for(int y = 0; y < MCMin(t_rect . y, height); y++) memset(t_mask -> data + t_mask -> bytes_per_line * y, 0, t_mask -> bytes_per_line); if (t_rect . x > 0 || t_rect . x + t_rect . width < width) { for(int y = MCMin(t_rect . y, height); y < MCMin(t_rect . y + t_rect . height, height); y++) { char *t_row; t_row = t_mask -> data + t_mask -> bytes_per_line * y; for(int x = 0; x < MCMin(t_rect . x, width); x++) t_row[x / 8] &= ~(1 << (7 - (x & 7))); for(int x = MCMin(t_rect . x + t_rect . width, width); x < width; x++) t_row[x / 8] &= ~(1 << (7 - (x & 7))); } } for(int y = MCMin(t_rect . y + t_rect . height, height); y < height; y++) memset(t_mask -> data + t_mask -> bytes_per_line * y, 0, t_mask -> bytes_per_line); r_mask = t_mask; return true; }
void MCStack::device_updatewindowwithcallback(MCRegionRef p_region, MCStackUpdateCallback p_callback, void *p_context) { s_update_callback = p_callback; s_update_context = p_context; s_update_rect = MCRegionGetBoundingBox(p_region); device_updatewindow(p_region); s_update_callback = nil; s_update_context = nil; }
bool LockPixels(MCRegionRef p_area, void*& r_bits, uint32_t& r_stride) { MCRectangle t_actual_area; t_actual_area = MCU_intersect_rect(MCRegionGetBoundingBox(p_area), MCRegionGetBoundingBox(m_region)); if (MCU_empty_rect(t_actual_area)) return false; m_locked_bits = malloc(t_actual_area . width * t_actual_area . height * sizeof(uint32_t)); if (m_locked_bits != nil) { m_locked_area = t_actual_area; r_bits = m_locked_bits; r_stride = t_actual_area . width * sizeof(uint32_t); return true; } return false; }
bool LockPixels(MCRegionRef p_area, void*& r_bits, uint32_t& r_stride) { if (MCscreen -> lockpixmap(m_pixmap, m_locked_bits, m_locked_stride)) { m_locked_area = MCRegionGetBoundingBox(p_area); r_bits = (uint8_t *)m_locked_bits + m_locked_area . y * m_locked_stride + m_locked_area . x * sizeof(uint32_t); r_stride = m_locked_stride; return true; } return false; }
bool LockGraphics(MCRegionRef p_area, MCContext*& r_context) { m_locked_context = MCscreen -> createcontext(m_pixmap, False, True); if (m_locked_context != nil) { m_locked_area = MCRegionGetBoundingBox(p_area); m_locked_context -> setorigin(0, 0); m_locked_context -> setclip(m_locked_area); r_context = m_locked_context; return true; } return false; }
bool LockPixels(MCRegionRef p_area, MCGRaster &r_raster) { m_locked_bits = m_raster.pixels; m_locked_stride = m_raster.stride; m_locked_area = MCRegionGetBoundingBox(p_area); // restrict locked area to intersection with raster m_locked_area = MCU_intersect_rect(m_locked_area, MCU_make_rect(0, 0, m_raster.width, m_raster.height)); /* UNCHECKED */ MCRegionIncludeRect(m_redraw_region, m_locked_area); r_raster.width = m_locked_area.width; r_raster.height = m_locked_area.height; r_raster.pixels = (uint8_t *)m_locked_bits + m_locked_area . y * m_locked_stride + m_locked_area . x * sizeof(uint32_t); r_raster.stride = m_locked_stride; r_raster.format = m_raster.format; return true; }
bool Lock(void) { if (m_bitmap != nil) return false; MCRectangle t_actual_area; t_actual_area = MCRegionGetBoundingBox(m_region); if (MCU_empty_rect(t_actual_area)) return false; bool t_success = true; void *t_bits = nil; if (t_success) t_success = MCRegionCreate(m_redraw_region); if (t_success) t_success = create_temporary_dib(m_dc, t_actual_area . width, t_actual_area . height, m_bitmap, t_bits); if (t_success) { m_raster . format = kMCGRasterFormat_ARGB; m_raster . width = t_actual_area . width; m_raster . height = t_actual_area . height; m_raster . stride = t_actual_area . width * sizeof(uint32_t); m_raster . pixels = t_bits; m_area = t_actual_area; return true; } MCRegionDestroy(m_redraw_region); m_redraw_region = nil; if (m_bitmap != nil) DeleteObject(m_bitmap); m_bitmap = nil; return false; }
bool LockTarget(MCStackSurfaceTargetType p_type, void*& r_context) { if (p_type != kMCStackSurfaceTargetCoreGraphics) return false; CGImageRef t_mask; t_mask = nil; if (m_stack -> getwindowshape() != nil) t_mask = (CGImageRef)m_stack -> getwindowshape() -> handle; if (t_mask != nil) { MCRectangle t_card_rect; t_card_rect = m_stack -> getcurcard() -> getrect(); MCRectangle t_rect; t_rect = MCRegionGetBoundingBox(m_region); CGContextClearRect(m_context, CGRectMake(t_rect . x, t_card_rect . height - (t_rect . y + t_rect . height), t_rect . width, t_rect . height)); // MW-2012-07-25: [[ Bug ]] Make sure we use signed arithmetic to // compute the y-origin otherwise it wraps to 2^32! int32_t t_mask_height, t_mask_width; t_mask_width = (int32_t)CGImageGetWidth(t_mask); t_mask_height = (int32_t)CGImageGetHeight(t_mask); CGRect t_dst_rect; t_dst_rect . origin . x = 0; t_dst_rect . origin . y = ((int32_t)t_card_rect . height) - t_mask_height - m_stack -> getscroll(); t_dst_rect . size . width = t_mask_width; t_dst_rect . size . height = t_mask_height; CGContextClipToMask(m_context, t_dst_rect, t_mask); } CGContextSaveGState(m_context); r_context = m_context; return true; }
bool MCTileCacheSoftwareCompositor_BeginFrame(void *p_context, MCStackSurface *p_surface, MCRegionRef p_dirty) { MCTileCacheSoftwareCompositorContext *self; self = (MCTileCacheSoftwareCompositorContext *)p_context; MCGRaster t_raster; if (!p_surface -> LockPixels(p_dirty, t_raster)) return false; self -> bits = t_raster . pixels; self -> stride = t_raster . stride; MCMemoryDeallocate(self -> tile_row); self -> tile_row = nil; self -> tile_row_color = 0; self -> tile_size = MCTileCacheGetTileSize(self -> tilecache); self -> dirty = MCRegionGetBoundingBox(p_dirty); self -> clip = self -> dirty; self -> combiner = s_surface_combiners_nda[GXcopy]; self -> opacity = 255; return true; }
OSStatus HIRevolutionStackViewHandler(EventHandlerCallRef p_call_ref, EventRef p_event, void *p_data) { OSStatus t_status; t_status = eventNotHandledErr; UInt32 t_event_class; t_event_class = GetEventClass(p_event); UInt32 t_event_kind; t_event_kind = GetEventKind(p_event); HIRevolutionStackViewData *t_context; t_context = (HIRevolutionStackViewData *)p_data; switch(t_event_class) { case 'revo': switch(t_event_kind) { case 'rlnk': GetEventParameter(p_event, 'Stak', typeVoidPtr, NULL, sizeof(void *), NULL, &t_context -> stack); break; } break; case kEventClassHIObject: switch(t_event_kind) { case kEventHIObjectConstruct: { HIRevolutionStackViewData *t_data; t_data = new HIRevolutionStackViewData; t_data -> stack = NULL; GetEventParameter(p_event, kEventParamHIObjectInstance, typeHIObjectRef, NULL, sizeof(HIObjectRef), NULL, (HIObjectRef *)&t_data -> view); SetEventParameter(p_event, kEventParamHIObjectInstance, typeVoidPtr, sizeof(HIRevolutionStackViewData *), &t_data); t_status = noErr; } break; case kEventHIObjectInitialize: { GetEventParameter(p_event, 'Stak', typeVoidPtr, NULL, sizeof(void *), NULL, &t_context -> stack); Rect t_bounds; t_bounds . left = 0; // MW-2011-09-12: [[ MacScroll ]] Make sure the top of the HIView takes into // account the scroll. t_bounds . top = -t_context -> stack -> getscroll(); t_bounds . right = t_context -> stack -> getrect() . width; t_bounds . bottom = t_context -> stack -> getrect() . height; SetControlBounds((ControlRef)t_context -> view, &t_bounds); t_status = noErr; } break; case kEventHIObjectDestruct: { delete t_context; t_status = noErr; } break; } break; case kEventClassControl: switch(t_event_kind) { case kEventControlInitialize: { t_status = noErr; } break; case kEventControlDraw: { CGContextRef t_graphics; GetEventParameter(p_event, kEventParamCGContextRef, typeCGContextRef, NULL, sizeof(CGContextRef), NULL, &t_graphics); RgnHandle t_dirty_rgn; GetEventParameter(p_event, kEventParamRgnHandle, typeQDRgnHandle, NULL, sizeof(RgnHandle), NULL, &t_dirty_rgn); if (t_context -> stack != NULL) { // Compute the clip region for players. RgnHandle t_clip_rgn, t_rect_rgn; t_clip_rgn = NULL; t_rect_rgn = NULL; for(MCPlayer *t_player = MCplayers; t_player != NULL; t_player = t_player -> getnextplayer()) if (t_player -> isvisible() && t_player -> getcard() == t_context -> stack -> getcurcard() && !t_player -> isbuffering()) { MCRectangle t_rect; Rect t_mac_rect; t_rect = t_player -> getactiverect(); if (t_clip_rgn == NULL) { t_clip_rgn = NewRgn(); CopyRgn((RgnHandle)t_dirty_rgn, t_clip_rgn); t_rect_rgn = NewRgn(); } SetRect(&t_mac_rect, t_rect . x, t_rect . y, t_rect . x + t_rect . width, t_rect . y + t_rect . height); RectRgn(t_rect_rgn, &t_mac_rect); DiffRgn(t_clip_rgn, t_rect_rgn, t_clip_rgn); } // We don't need the rect rgn anymore. if (t_rect_rgn != NULL) DisposeRgn(t_rect_rgn); // If the clip region is non-nil, then apply it. if (t_clip_rgn != NULL) { // As we can't clip to empty path, if the region is empty, we set the context // to nil. if (!EmptyRgn(t_clip_rgn)) { HIShapeRef t_shape; t_shape = HIShapeCreateWithQDRgn(t_clip_rgn); HIShapeReplacePathInCGContext(t_shape, t_graphics); CGContextClip(t_graphics); CFRelease(t_shape); } else t_graphics = nil; DisposeRgn(t_clip_rgn); } // If the graphics context is non-nil (i.e. we aren't completely occluded) then // draw something. if (t_graphics != nil) { // HIView gives us a context in top-left origin mode which isn't so good // for our CG rendering so, revert back to bottom-left. CGContextScaleCTM(t_graphics, 1.0, -1.0); CGContextTranslateCTM(t_graphics, 0.0, -t_context -> stack -> getcurcard() -> getrect() . height); // Save the context state CGContextSaveGState(t_graphics); // If we don't have an update pixmap, then use redrawwindow. if (s_update_pixmap == nil) { MCMacStackSurface t_surface(t_context -> stack, (MCRegionRef)t_dirty_rgn, t_graphics); t_context -> stack -> redrawwindow(&t_surface, (MCRegionRef)t_dirty_rgn); } else { int32_t t_height; t_height = t_context -> stack -> getcurcard() -> getrect() . height; MCRectangle t_rect; t_rect = MCRegionGetBoundingBox((MCRegionRef)t_dirty_rgn); CGRect t_area; t_area = CGRectMake(t_rect . x, t_height - (t_rect . y + t_rect . height), t_rect . width, t_rect . height); CGContextClearRect(t_graphics, t_area); void *t_bits; uint32_t t_stride; MCscreen -> lockpixmap(s_update_pixmap, t_bits, t_stride); MCMacRenderBitsToCG(t_graphics, t_area, t_bits, t_stride, t_context -> stack -> getwindowshape() != nil ? true : false); MCscreen -> unlockpixmap(s_update_pixmap, t_bits, t_stride); } // Restore the context state CGContextRestoreGState(t_graphics); } // MW-2011-11-23: [[ Bug ]] Force a redraw of the players on the stack // after we've drawn the rest of the content. This ensures players // which are just appearing don't disappear behind said content. for(MCPlayer *t_player = MCplayers; t_player != NULL; t_player = t_player -> getnextplayer()) if (t_player -> isvisible() && t_player -> getcard() == t_context -> stack -> getcurcard() && !t_player -> isbuffering()) MCDoAction((MovieController)t_player -> getMovieController(), mcActionDraw, t_context -> stack -> getqtwindow()); } t_status = noErr; } break; case kEventControlHitTest: break; case kEventControlGetPartRegion: { ControlPartCode t_part; GetEventParameter(p_event, kEventParamControlPart, typeControlPartCode, NULL, sizeof(ControlPartCode), NULL, &t_part); RgnHandle t_region; GetEventParameter(p_event, kEventParamControlRegion, typeQDRgnHandle, NULL, sizeof(RgnHandle), NULL, &t_region); } break; case kEventControlHiliteChanged: break; case kEventControlActivate: break; case kEventControlDeactivate: break; } break; } return t_status; }