blob: eb098cb0ace9ff228d1237d565a9a31d0f63214e [file] [log] [blame]
John Reck67b1e2b2020-08-26 13:17:24 -07001/*
2 * Copyright 2020 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#ifndef SF_SKIAGLRENDERENGINE_H_
18#define SF_SKIAGLRENDERENGINE_H_
19
20#include <sys/types.h>
21#include <mutex>
22#include <unordered_map>
23
24#include <android-base/thread_annotations.h>
25#include <renderengine/RenderEngine.h>
26
27#include <GrDirectContext.h>
28#include <SkSurface.h>
29
30#include "SkiaRenderEngine.h"
31
32namespace android {
33namespace renderengine {
34namespace skia {
35
36class SkiaGLRenderEngine : public skia::SkiaRenderEngine {
37public:
38 static std::unique_ptr<SkiaGLRenderEngine> create(const RenderEngineCreationArgs& args);
39 SkiaGLRenderEngine(const RenderEngineCreationArgs& args, EGLDisplay display, EGLConfig config,
40 EGLContext ctxt, EGLSurface placeholder, EGLContext protectedContext,
41 EGLSurface protectedPlaceholder);
42 ~SkiaGLRenderEngine() override{};
43
44 void unbindExternalTextureBuffer(uint64_t bufferId) override;
45 status_t drawLayers(const DisplaySettings& display,
46 const std::vector<const LayerSettings*>& layers,
47 const sp<GraphicBuffer>& buffer, const bool useFramebufferCache,
48 base::unique_fd&& bufferFence, base::unique_fd* drawFence) override;
49 void cleanFramebufferCache() override;
50
51protected:
52 void dump(std::string& /*result*/) override{};
53 size_t getMaxTextureSize() const override;
54 size_t getMaxViewportDims() const override;
55
56private:
57 static EGLConfig chooseEglConfig(EGLDisplay display, int format, bool logConfig);
58 static EGLContext createEglContext(EGLDisplay display, EGLConfig config,
59 EGLContext shareContext, bool useContextPriority,
60 Protection protection);
61 static EGLSurface createPlaceholderEglPbufferSurface(EGLDisplay display, EGLConfig config,
62 int hwcFormat, Protection protection);
63
64 base::unique_fd flush();
65 bool waitFence(base::unique_fd fenceFd);
66
67 EGLDisplay mEGLDisplay;
68 EGLConfig mEGLConfig;
69 EGLContext mEGLContext;
70 EGLSurface mPlaceholderSurface;
71 EGLContext mProtectedEGLContext;
72 EGLSurface mProtectedPlaceholderSurface;
73
74 // Cache of GL images that we'll store per GraphicBuffer ID
75 std::unordered_map<uint64_t, sk_sp<SkImage>> mImageCache GUARDED_BY(mRenderingMutex);
76 // Mutex guarding rendering operations, so that:
77 // 1. GL operations aren't interleaved, and
78 // 2. Internal state related to rendering that is potentially modified by
79 // multiple threads is guaranteed thread-safe.
80 std::mutex mRenderingMutex;
81
82 sp<Fence> mLastDrawFence;
83
84 sk_sp<GrDirectContext> mGrContext;
85
86 std::unordered_map<uint64_t, sk_sp<SkSurface>> mSurfaceCache;
87};
88
89} // namespace skia
90} // namespace renderengine
91} // namespace android
92
93#endif /* SF_GLESRENDERENGINE_H_ */