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 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 RestoreCGFillping(Ctx: CGContextRef; Width, Height: Integer); // Width and Height must be negative to restore
public
@ -733,24 +734,42 @@ begin
CGContextSetShouldAntialias(CGContext, CBool(AValue));
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
Params: X, Y - Left, Top
Width, Height
CGImage
BlendMode
Returns: If the function succeeds
Draws CGImage into CGContext
------------------------------------------------------------------------------}
function TCarbonDeviceContext.DrawCGImage(X, Y, Width, Height: Integer;
CGImage: CGImageRef): Boolean;
CGImage: CGImageRef; BlendMode: CGBlendMode): Boolean;
begin
Result := False;
// save dest context
CGContextSaveGState(CGContext);
CGContextSetBlendMode(CGContext, kCGBlendModeNormal);
CGContextSetBlendMode(CGContext, BlendMode);
try
SetCGFillping(CGContext, Width, Height);
if OSError(
@ -1537,7 +1556,7 @@ begin
if not UseLayer then
begin
// Normal drawing
Result := DrawCGImage(X, Y, Width, Height, Image);
Result := DrawCGImage(X, Y, Width, Height, Image, GetBlendModeFromROP(Rop));
end
else
begin