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 // No-op (large resources like textures, surfaces, images, etc. created by clients don't count 43 // towards Graphite's internal caching budgets, so adjusting its limits based on display change 44 // events should be unnecessary. Additionally, Graphite doesn't expose many cache tweaking 45 // functions yet, as its design may evolve.) setResourceCacheLimit(size_t maxResourceBytes)46 void setResourceCacheLimit(size_t maxResourceBytes) override{}; 47 48 // TODO: b/293371537 - Triple-check and validate that no cleanup is necessary when switching 49 // contexts. 50 // No-op (unnecessary during context switch for Graphite's client-budgeted memory model). purgeUnlockedScratchResources()51 void purgeUnlockedScratchResources() override{}; 52 // No-op (only applicable to GL). resetContextIfApplicable()53 void resetContextIfApplicable() override{}; 54 55 void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const override; 56 57 private: 58 DISALLOW_COPY_AND_ASSIGN(GraphiteGpuContext); 59 60 std::shared_ptr<skgpu::graphite::Context> mContext; 61 std::shared_ptr<skgpu::graphite::Recorder> mRecorder; 62 }; 63 64 } // namespace android::renderengine::skia 65