• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.. All rights reserved.
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 SKIA_GPUCONTEXT_H
17 #define SKIA_GPUCONTEXT_H
18 
19 #ifdef NEW_SKIA
20 #include "include/gpu/GrDirectContext.h"
21 #else
22 #include "include/gpu/GrContext.h"
23 #endif
24 #include "include/gpu/GrContextOptions.h"
25 
26 #include "impl_interface/gpu_context_impl.h"
27 #include "image/gpu_context.h"
28 
29 namespace OHOS {
30 namespace Rosen {
31 namespace Drawing {
32 class SkiaPersistentCache : public GrContextOptions::PersistentCache {
33 public:
34     explicit SkiaPersistentCache(GPUContextOptions::PersistentCache* cache);
~SkiaPersistentCache()35     ~SkiaPersistentCache() {}
36 
37     sk_sp<SkData> load(const SkData& key) override;
38     void store(const SkData& key, const SkData& data) override;
39 private:
40     GPUContextOptions::PersistentCache* cache_;
41 };
42 
43 class SkiaGPUContext : public GPUContextImpl {
44 public:
45     static inline constexpr AdapterType TYPE = AdapterType::SKIA_ADAPTER;
46     SkiaGPUContext();
47     ~SkiaGPUContext() override = default;;
48 
GetType()49     AdapterType GetType() const override
50     {
51         return AdapterType::SKIA_ADAPTER;
52     }
53 
54     bool BuildFromGL(const GPUContextOptions& options) override;
55 
56     void Flush() override;
57     void PerformDeferredCleanup(std::chrono::milliseconds msNotUsed) override;
58 
59     void GetResourceCacheLimits(int& maxResource, size_t& maxResourceBytes) const override;
60     void SetResourceCacheLimits(int maxResource, size_t maxResourceBytes) override;
61 
62 #ifdef NEW_SKIA
63     sk_sp<GrDirectContext> GetGrContext() const;
64     void SetGrContext(const sk_sp<GrDirectContext>& grContext);
65 #else
66     sk_sp<GrContext> GetGrContext() const;
67     void SetGrContext(const sk_sp<GrContext>& grContext);
68 #endif
69 
70 private:
71 #ifdef NEW_SKIA
72     sk_sp<GrDirectContext> grContext_;
73 #else
74     sk_sp<GrContext> grContext_;
75 #endif
76     std::shared_ptr<SkiaPersistentCache> skiaPersistentCache_;
77 };
78 } // namespace Drawing
79 } // namespace Rosen
80 } // namespace OHOS
81 #endif // SKIA_GPUCONTEXT_H
82