• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved.
3  * Description: Draw area manager for vulkan api partial render extended function.
4  * Create: 2023/11/27
5  */
6 
7 #include "src/gpu/vk/GrVkDrawAreaManager.h"
8 #include "src/image/SkSurface_Gpu.h"
9 #include "src/gpu/BaseDevice.h"
10 #include "src/gpu/GrRenderTargetProxy.h"
11 
bindDrawingArea(SkSurface * surface,const std::vector<SkIRect> & skIRects)12 void GrVkDrawAreaManager::bindDrawingArea(SkSurface* surface, const std::vector<SkIRect>& skIRects) {
13     if (!surface) {
14         return;
15     }
16 
17     auto gpuDevice = static_cast<SkSurface_Gpu*>(surface)->getDevice();
18     if (!gpuDevice) {
19         return;
20     }
21 
22     auto gpuDeviceProxy = gpuDevice->asGpuDevice()->targetProxy();
23     if (!gpuDeviceProxy) {
24         return;
25     }
26 
27     SkAutoMutexExclusive lock(fMutex);
28     fRtmap[gpuDeviceProxy->peekRenderTarget()] = skIRects;
29 }
30 
getDrawingArea(GrRenderTarget * rt)31 std::vector<SkIRect>& GrVkDrawAreaManager::getDrawingArea(GrRenderTarget* rt) {
32     SkAutoMutexExclusive lock(fMutex);
33     std::map<GrRenderTarget*, std::vector<SkIRect>>::iterator iter = fRtmap.find(rt);
34     if (iter != fRtmap.end()) {
35         return iter->second;
36     } else {
37         static std::vector<SkIRect> emptyVec = {};
38         return emptyVec;
39     }
40 }
41 
clearSurface(SkSurface * surface)42 void GrVkDrawAreaManager::clearSurface(SkSurface* surface) {
43     if (!surface) {
44         return;
45     }
46 
47     auto gpuDevice = static_cast<SkSurface_Gpu*>(surface)->getDevice();
48     if (!gpuDevice) {
49         return;
50     }
51 
52     auto gpuDeviceProxy = gpuDevice->asGpuDevice()->targetProxy();
53     if (!gpuDeviceProxy) {
54         return;
55     }
56 
57     SkAutoMutexExclusive lock(fMutex);
58     fRtmap.erase(gpuDeviceProxy->peekRenderTarget());
59 }
60 
clearAll()61 void GrVkDrawAreaManager::clearAll() {
62     SkAutoMutexExclusive lock(fMutex);
63     fRtmap.clear();
64 }