Carbon: Optimize TCarbonControlContext drawing. Issue #21767, patch from David Jenkins & AlexeyT.

git-svn-id: trunk@54602 -
This commit is contained in:
juha 2017-04-10 20:09:35 +00:00
parent 57f917a297
commit de867c7b05
2 changed files with 23 additions and 15 deletions

View File

@ -186,12 +186,14 @@ type
TCarbonControlContext = class(TCarbonDeviceContext) TCarbonControlContext = class(TCarbonDeviceContext)
private private
FOwner: TCarbonWidget; // owner widget FOwner: TCarbonWidget; // owner widget
FClipShapeRef: HIShapeRef;
protected protected
function GetSize: TPoint; override; function GetSize: TPoint; override;
public public
constructor Create(AOwner: TCarbonWidget); constructor Create(AOwner: TCarbonWidget);
function IsInClipRegion(ARect: TRect): Boolean;
property Owner: TCarbonWidget read FOwner; property Owner: TCarbonWidget read FOwner;
property ClipShapeRef: HIShapeRef read FClipShapeRef write FClipShapeRef;
end; end;
{ TCarbonBitmapContext } { TCarbonBitmapContext }
@ -1303,12 +1305,12 @@ end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
Method: TCarbonDeviceContext.PolyBezier Method: TCarbonDeviceContext.PolyBezier
Params: Points - Points defining the cubic Bézier curve Params: Points - Points defining the cubic Bézier curve
NumPts - Number of points passed NumPts - Number of points passed
Filled - Fill the drawed shape Filled - Fill the drawed shape
Continous - Connect Bézier curves Continous - Connect Bézier curves
Draws a cubic Bézier curves. The first curve is drawn from the first point to Draws a cubic Bézier curves. The first curve is drawn from the first point to
the fourth point with the second and third points being the control points. the fourth point with the second and third points being the control points.
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
procedure TCarbonDeviceContext.PolyBezier(Points: PPoint; NumPts: Integer; procedure TCarbonDeviceContext.PolyBezier(Points: PPoint; NumPts: Integer;
@ -1744,6 +1746,13 @@ begin
Reset; Reset;
end; end;
function TCarbonControlContext.IsInClipRegion(ARect: TRect): Boolean;
begin
Result := True;
if ClipShapeRef <> nil then
Result := HIShapeIntersectsRect(ClipShapeRef, RectToCGRect(ARect));
end;
{ TCarbonBitmapContext } { TCarbonBitmapContext }
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------

View File

@ -50,8 +50,8 @@ var
AStruct : PPaintStruct; AStruct : PPaintStruct;
Win : WindowRef; Win : WindowRef;
Content : HIViewRef; Content : HIViewRef;
Hnd : RgnHandle; ClpShape: HIShapeRef;
mr : MacOSAll.Rect; mr : CGRect;
invr : TRect; invr : TRect;
begin begin
if isRepaint then if isRepaint then
@ -74,18 +74,17 @@ begin
SizeOf(CGContextRef), nil, @(AWidget.Context.CGContext)), SizeOf(CGContextRef), nil, @(AWidget.Context.CGContext)),
'CarbonCommon_Draw', SGetEvent, 'kEventParamCGContextRef') then Exit; 'CarbonCommon_Draw', SGetEvent, 'kEventParamCGContextRef') then Exit;
if GetEventParameter(AEvent, kEventParamShape, typeHIShapeRef, nil,
if GetEventParameter(AEvent, kEventParamRgnHandle, typeQDRgnHandle, nil, SizeOf(ClpShape), nil, @ClpShape)=noErr then
SizeOf(Hnd), nil, @Hnd)=noErr then
begin begin
GetRegionBounds(RgnHandle(Hnd), mr{%H-}); HIShapeGetBounds(ClpShape, mr);
invr.Left:=mr.left; invr := CGRectToRect(mr);
invr.Top:=mr.top; TCarbonControlContext(AWidget.Context).ClipShapeRef := ClpShape;
invr.Right:=mr.right;
invr.Bottom:=mr.bottom;
end end
else else begin
AWidget.GetBounds(invr); AWidget.GetBounds(invr);
TCarbonControlContext(AWidget.Context).ClipShapeRef := nil;
end;
AWidget.Context.Reset; AWidget.Context.Reset;