1 /* 2 * Copyright (c) 2023 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 #ifndef GPU_CONTEXT_IMPL_H 17 #define GPU_CONTEXT_IMPL_H 18 19 #include <chrono> 20 21 #include "base_impl.h" 22 #include "image/trace_memory_dump.h" 23 #ifdef RS_ENABLE_VK 24 #include "include/gpu/vk/GrVkBackendContext.h" 25 #endif 26 27 namespace OHOS { 28 namespace Rosen { 29 namespace Drawing { 30 struct GPUResourceTag; 31 class GPUContext; 32 class GPUContextOptions; 33 class GPUContextImpl : public BaseImpl { 34 public: GPUContextImpl()35 GPUContextImpl() {}; ~GPUContextImpl()36 ~GPUContextImpl() override {}; 37 38 virtual bool BuildFromGL(const GPUContextOptions& options) = 0; 39 #ifdef RS_ENABLE_VK 40 virtual bool BuildFromVK(const GrVkBackendContext& context) = 0; 41 virtual bool BuildFromVK(const GrVkBackendContext& context, const GPUContextOptions& options) = 0; 42 #endif 43 virtual void Flush() = 0; 44 virtual void FlushAndSubmit(bool syncCpu) = 0; 45 virtual void Submit() = 0; 46 virtual void PerformDeferredCleanup(std::chrono::milliseconds msNotUsed) = 0; 47 48 virtual void GetResourceCacheLimits(int* maxResource, size_t* maxResourceBytes) const = 0; 49 virtual void SetResourceCacheLimits(int maxResource, size_t maxResourceBytes) = 0; 50 51 virtual void GetResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const = 0; 52 53 virtual void FreeGpuResources() = 0; 54 55 virtual void DumpGpuStats(std::string& out) = 0; 56 57 virtual void ReleaseResourcesAndAbandonContext() = 0; 58 59 virtual void PurgeUnlockedResources(bool scratchResourcesOnly) = 0; 60 61 virtual void PurgeUnlockedResourcesByTag(bool scratchResourcesOnly, const GPUResourceTag &tag) = 0; 62 63 virtual void PurgeUnlockAndSafeCacheGpuResources() = 0; 64 65 virtual void ReleaseByTag(const GPUResourceTag &tag) = 0; 66 67 virtual void DumpMemoryStatisticsByTag(TraceMemoryDump* traceMemoryDump, GPUResourceTag &tag) = 0; 68 69 virtual void DumpMemoryStatistics(TraceMemoryDump* traceMemoryDump) = 0; 70 71 virtual void SetCurrentGpuResourceTag(const GPUResourceTag &tag) = 0; 72 73 #ifdef RS_ENABLE_VK 74 virtual void StoreVkPipelineCacheData() = 0; 75 #endif 76 }; 77 } // namespace Drawing 78 } // namespace Rosen 79 } // namespace OHOS 80 #endif // GPU_CONTEXT_IMPL_H 81