• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include "SkiaGpuContext.h"
20 #include "graphite/Recorder.h"
21 
22 #include <android-base/macros.h>
23 
24 namespace android::renderengine::skia {
25 
26 class GraphiteGpuContext : public SkiaGpuContext {
27 public:
28     GraphiteGpuContext(std::unique_ptr<skgpu::graphite::Context> context);
29     ~GraphiteGpuContext() override;
30 
31     std::shared_ptr<skgpu::graphite::Context> graphiteContext() override;
32     std::shared_ptr<skgpu::graphite::Recorder> graphiteRecorder() override;
33 
34     std::unique_ptr<SkiaBackendTexture> makeBackendTexture(AHardwareBuffer* buffer,
35                                                            bool isOutputBuffer) override;
36 
37     sk_sp<SkSurface> createRenderTarget(SkImageInfo imageInfo) override;
38 
39     size_t getMaxRenderTargetSize() const override;
40     size_t getMaxTextureSize() const override;
41     bool isAbandonedOrDeviceLost() override;
42 
43     void setResourceCacheLimit(size_t maxResourceBytes) override;
44     void purgeUnlockedScratchResources() override;
45 
46     // No-op (only applicable to GL).
resetContextIfApplicable()47     void resetContextIfApplicable() override{};
48 
49     void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const override;
50 
51 private:
52     DISALLOW_COPY_AND_ASSIGN(GraphiteGpuContext);
53 
54     std::shared_ptr<skgpu::graphite::Context> mContext;
55     std::shared_ptr<skgpu::graphite::Recorder> mRecorder;
56 };
57 
58 } // namespace android::renderengine::skia
59