@@ -162,17 +162,21 @@ TSkCanvasCustomClass = class of TSkCanvasCustom;
162
162
163
163
TSkBitmapHandle = class
164
164
private
165
- FPixels: Pointer;
165
+ function GetPixels : Pointer; overload;
166
+ function GetPixels (AInitializeToZero: Boolean): Pointer; overload; inline;
166
167
strict private
167
168
FHeight: Integer;
168
169
FPixelFormat: TPixelFormat;
170
+ FPixels: Pointer;
171
+ FPixelsBytes: NativeUInt;
169
172
FWidth: Integer;
170
173
public
171
174
constructor Create(const AWidth, AHeight: Integer; const APixelFormat: TPixelFormat);
172
175
destructor Destroy; override;
173
176
property Height: Integer read FHeight;
174
177
property PixelFormat: TPixelFormat read FPixelFormat;
175
- property Pixels: Pointer read FPixels;
178
+ property Pixels: Pointer read GetPixels;
179
+ property PixelsBytes: NativeUInt read FPixelsBytes;
176
180
property Width: Integer read FWidth;
177
181
end ;
178
182
@@ -2460,6 +2464,8 @@ constructor TSkBitmapHandle.Create(const AWidth, AHeight: Integer;
2460
2464
FWidth := AWidth;
2461
2465
FHeight := AHeight;
2462
2466
FPixelFormat := APixelFormat;
2467
+ if (AWidth > 0 ) and (AHeight > 0 ) and (PixelFormatBytes[APixelFormat] > 0 ) then
2468
+ FPixelsBytes := NativeUInt(AWidth) * NativeUInt(AHeight) * NativeUInt(PixelFormatBytes[APixelFormat]);
2463
2469
end ;
2464
2470
2465
2471
destructor TSkBitmapHandle.Destroy;
@@ -2468,6 +2474,23 @@ destructor TSkBitmapHandle.Destroy;
2468
2474
inherited ;
2469
2475
end ;
2470
2476
2477
+ function TSkBitmapHandle.GetPixels (AInitializeToZero: Boolean): Pointer;
2478
+ begin
2479
+ if (FPixels = nil ) and (FPixelsBytes > 0 ) then
2480
+ begin
2481
+ if AInitializeToZero then
2482
+ FPixels := AllocMem(FPixelsBytes)
2483
+ else
2484
+ GetMem(FPixels, FPixelsBytes);
2485
+ end ;
2486
+ Result := FPixels;
2487
+ end ;
2488
+
2489
+ function TSkBitmapHandle.GetPixels : Pointer;
2490
+ begin
2491
+ Result := GetPixels(True);
2492
+ end ;
2493
+
2471
2494
{ TSkCanvasBase }
2472
2495
2473
2496
function TSkCanvasBase.BeginCanvas (const AContextHandle: THandle): ISkCanvas;
@@ -2484,8 +2507,6 @@ function TSkCanvasBase.BeginCanvas(const AContextHandle: THandle): ISkCanvas;
2484
2507
else if Bitmap <> nil then
2485
2508
begin
2486
2509
LBitmap := TSkBitmapHandle(Bitmap.Handle);
2487
- if LBitmap.Pixels = nil then
2488
- LBitmap.FPixels := AllocMem(NativeInt(LBitmap.Width) * LBitmap.Height * PixelFormatBytes[LBitmap.PixelFormat]);
2489
2510
FBitmapSurface := TSkSurface.MakeRasterDirect(TSkImageInfo.Create(LBitmap.Width, LBitmap.Height, SkFmxColorType[LBitmap.PixelFormat]), LBitmap.Pixels, LBitmap.Width * PixelFormatBytes[LBitmap.PixelFormat]);
2490
2511
Result := FBitmapSurface.Canvas;
2491
2512
end
@@ -2550,14 +2571,7 @@ class function TSkCanvasBase.DoMapBitmap(const ABitmapHandle: THandle;
2550
2571
LBitmap: TSkBitmapHandle;
2551
2572
begin
2552
2573
LBitmap := TSkBitmapHandle(ABitmapHandle);
2553
- if LBitmap.Pixels = nil then
2554
- begin
2555
- if AAccess = TMapAccess.Write then
2556
- GetMem(LBitmap.FPixels, LBitmap.Width * LBitmap.Height * PixelFormatBytes[LBitmap.PixelFormat])
2557
- else
2558
- LBitmap.FPixels := AllocMem(LBitmap.Width * LBitmap.Height * PixelFormatBytes[LBitmap.PixelFormat]);
2559
- end ;
2560
- ABitmapData.Data := LBitmap.Pixels;
2574
+ ABitmapData.Data := LBitmap.GetPixels(AAccess <> TMapAccess.Write);
2561
2575
ABitmapData.Pitch := LBitmap.Width * PixelFormatBytes[LBitmap.PixelFormat];
2562
2576
Result := True;
2563
2577
end ;
@@ -2652,13 +2666,15 @@ function TGrSharedContext.GetGrDirectContext: TGrDirectContext;
2652
2666
Result := TGrDirectContext(FGrDirectContext);
2653
2667
end ;
2654
2668
2655
- procedure TGrSharedContext.InitializeTextureCache (
2656
- const ABitmap: TGrBitmapHandle);
2669
+ procedure TGrSharedContext.InitializeTextureCache (const ABitmap: TGrBitmapHandle);
2657
2670
var
2658
2671
LImage: ISkImage;
2659
2672
begin
2660
- LImage := TSkImage.MakeFromRaster(TSkImageInfo.Create(ABitmap.Width, ABitmap.Height, SkFmxColorType[ABitmap.PixelFormat]), ABitmap.Pixels, ABitmap.Width * PixelFormatBytes[ABitmap.PixelFormat]);
2661
- ABitmap.Cache := LImage.MakeTextureImage(ABitmap.SharedContext.GrDirectContext);
2673
+ LImage := TSkImage.MakeFromRaster(
2674
+ TSkImageInfo.Create(ABitmap.Width, ABitmap.Height, SkFmxColorType[ABitmap.PixelFormat]),
2675
+ ABitmap.Pixels, ABitmap.Width * PixelFormatBytes[ABitmap.PixelFormat]);
2676
+ if LImage <> nil then
2677
+ ABitmap.Cache := LImage.MakeTextureImage(ABitmap.SharedContext.GrDirectContext);
2662
2678
end ;
2663
2679
2664
2680
procedure TGrSharedContext.RefreshContext ;
0 commit comments