xref: /aosp_15_r20/external/skia/src/gpu/ganesh/GrCanvas.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2023 Google LLC
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 #include "src/gpu/ganesh/GrCanvas.h"
8 
9 #include "include/android/SkCanvasAndroid.h"
10 #include "include/core/SkRect.h"
11 #include "include/gpu/ganesh/GrBackendSurface.h"
12 #include "src/core/SkCanvasPriv.h"
13 #include "src/core/SkDevice.h"
14 #include "src/gpu/ganesh/Device.h"
15 #include "src/gpu/ganesh/GrRenderTarget.h"
16 #include "src/gpu/ganesh/GrRenderTargetProxy.h"
17 
18 namespace skgpu::ganesh {
19 
TopDeviceSurfaceDrawContext(const SkCanvas * canvas)20 SurfaceDrawContext* TopDeviceSurfaceDrawContext(const SkCanvas* canvas) {
21     if (auto gpuDevice = SkCanvasPriv::TopDevice(canvas)->asGaneshDevice()) {
22         return gpuDevice->surfaceDrawContext();
23     }
24     return nullptr;
25 }
26 
TopDeviceSurfaceFillContext(const SkCanvas * canvas)27 SurfaceFillContext* TopDeviceSurfaceFillContext(const SkCanvas* canvas) {
28     if (auto gpuDevice = SkCanvasPriv::TopDevice(canvas)->asGaneshDevice()) {
29         return gpuDevice->surfaceFillContext();
30     }
31     return nullptr;
32 }
33 
TopDeviceTargetProxy(const SkCanvas * canvas)34 GrRenderTargetProxy* TopDeviceTargetProxy(const SkCanvas* canvas) {
35     if (auto gpuDevice = SkCanvasPriv::TopDevice(canvas)->asGaneshDevice()) {
36         return gpuDevice->targetProxy();
37     }
38     return nullptr;
39 }
40 
TopLayerBounds(const SkCanvas * canvas)41 SkIRect TopLayerBounds(const SkCanvas* canvas) {
42     return SkCanvasPriv::TopDevice(canvas)->getGlobalBounds();
43 }
44 
TopLayerBackendRenderTarget(const SkCanvas * canvas)45 GrBackendRenderTarget TopLayerBackendRenderTarget(const SkCanvas* canvas) {
46     auto proxy = TopDeviceTargetProxy(canvas);
47     if (!proxy) {
48         return {};
49     }
50     const GrRenderTarget* renderTarget = proxy->peekRenderTarget();
51     return renderTarget ? renderTarget->getBackendRenderTarget() : GrBackendRenderTarget();
52 }
53 
54 }  // namespace skgpu::ganesh
55