1 /* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "src/gpu/vk/GrVkDrawAreaManager.h" 17 #include "src/gpu/ganesh/Device.h" 18 #include "src/gpu/ganesh/GrRenderTargetProxy.h" 19 #include "src/gpu/ganesh/surface/SkSurface_Ganesh.h" 20 bindDrawingArea(SkSurface * surface,const std::vector<SkIRect> & skIRects)21void GrVkDrawAreaManager::bindDrawingArea(SkSurface* surface, const std::vector<SkIRect>& skIRects) 22 { 23 if (!surface) { 24 return; 25 } 26 27 auto gpuDevice = static_cast<SkSurface_Ganesh*>(surface)->getDevice(); 28 if (!gpuDevice) { 29 return; 30 } 31 32 auto gpuDeviceProxy = gpuDevice->targetProxy(); 33 if (!gpuDeviceProxy) { 34 return; 35 } 36 37 SkAutoMutexExclusive lock(fMutex); 38 fRtmap[gpuDeviceProxy->peekRenderTarget()] = skIRects; 39 } 40 getDrawingArea(GrRenderTarget * rt)41std::vector<SkIRect>& GrVkDrawAreaManager::getDrawingArea(GrRenderTarget* rt) 42 { 43 SkAutoMutexExclusive lock(fMutex); 44 std::map<GrRenderTarget*, std::vector<SkIRect>>::iterator iter = fRtmap.find(rt); 45 if (iter != fRtmap.end()) { 46 return iter->second; 47 } else { 48 static std::vector<SkIRect> emptyVec = {}; 49 return emptyVec; 50 } 51 } 52 clearSurface(SkSurface * surface)53void GrVkDrawAreaManager::clearSurface(SkSurface* surface) 54 { 55 if (!surface) { 56 return; 57 } 58 59 auto gpuDevice = static_cast<SkSurface_Ganesh*>(surface)->getDevice(); 60 if (!gpuDevice) { 61 return; 62 } 63 64 auto gpuDeviceProxy = gpuDevice->targetProxy(); 65 if (!gpuDeviceProxy) { 66 return; 67 } 68 69 SkAutoMutexExclusive lock(fMutex); 70 fRtmap.erase(gpuDeviceProxy->peekRenderTarget()); 71 } 72 clearAll()73void GrVkDrawAreaManager::clearAll() 74 { 75 SkAutoMutexExclusive lock(fMutex); 76 fRtmap.clear(); 77 }