carbon: Patch from issue #31014: Carbon: Implement TCopyMode.cmSrcInvert in TCarbonDeviceContext.Draw()

git-svn-id: trunk@54463 -
This commit is contained in:
sekelsenmat 2017-03-22 09:42:32 +00:00
parent d564bdfaca
commit 6a06cf769b

View File

@ -114,7 +114,8 @@ type
procedure EndTextRender(var ALayout: TCarbonTextLayout); procedure EndTextRender(var ALayout: TCarbonTextLayout);
procedure SetAntialiasing(AValue: Boolean); procedure SetAntialiasing(AValue: Boolean);
function DrawCGImage(X, Y, Width, Height: Integer; CGImage: CGImageRef): Boolean; function GetBlendModeFromROP(ROP: DWORD) : CGBlendMode;
function DrawCGImage(X, Y, Width, Height: Integer; CGImage: CGImageRef; BlendMode: CGBlendMode = kCGBlendModeNormal): Boolean;
procedure SetCGFillping(Ctx: CGContextRef; Width, Height: Integer); // Width and Height must be negative to flip the image procedure SetCGFillping(Ctx: CGContextRef; Width, Height: Integer); // Width and Height must be negative to flip the image
procedure RestoreCGFillping(Ctx: CGContextRef; Width, Height: Integer); // Width and Height must be negative to restore procedure RestoreCGFillping(Ctx: CGContextRef; Width, Height: Integer); // Width and Height must be negative to restore
public public
@ -733,24 +734,42 @@ begin
CGContextSetShouldAntialias(CGContext, CBool(AValue)); CGContextSetShouldAntialias(CGContext, CBool(AValue));
end; end;
{------------------------------------------------------------------------------
Method: TCarbonDeviceContext.GetBlendModeFromROP
Params: ROP - The raster operation. See TCopyMode
Returns: The CGBlendMode corresponding to this operation if such mode exists,
the default kCGBlendModeNormal otherwise
Converts a TCopoyMode raster operation to a BlendMode
------------------------------------------------------------------------------}
function TCarbonDeviceContext.GetBlendModeFromROP(ROP: DWORD) : CGBlendMode;
begin
case ROP of
cmSrcPaint : result := kCGBlendModeNormal;
cmSrcInvert : result := kCGBlendModeExclusion;
else result := kCGBlendModeNormal;
end;
end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
Method: TCarbonDeviceContext.DrawCGImage Method: TCarbonDeviceContext.DrawCGImage
Params: X, Y - Left, Top Params: X, Y - Left, Top
Width, Height Width, Height
CGImage CGImage
BlendMode
Returns: If the function succeeds Returns: If the function succeeds
Draws CGImage into CGContext Draws CGImage into CGContext
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
function TCarbonDeviceContext.DrawCGImage(X, Y, Width, Height: Integer; function TCarbonDeviceContext.DrawCGImage(X, Y, Width, Height: Integer;
CGImage: CGImageRef): Boolean; CGImage: CGImageRef; BlendMode: CGBlendMode): Boolean;
begin begin
Result := False; Result := False;
// save dest context // save dest context
CGContextSaveGState(CGContext); CGContextSaveGState(CGContext);
CGContextSetBlendMode(CGContext, kCGBlendModeNormal); CGContextSetBlendMode(CGContext, BlendMode);
try try
SetCGFillping(CGContext, Width, Height); SetCGFillping(CGContext, Width, Height);
if OSError( if OSError(
@ -1537,7 +1556,7 @@ begin
if not UseLayer then if not UseLayer then
begin begin
// Normal drawing // Normal drawing
Result := DrawCGImage(X, Y, Width, Height, Image); Result := DrawCGImage(X, Y, Width, Height, Image, GetBlendModeFromROP(Rop));
end end
else else
begin begin