blob: 3da7f25d2c66d22bcbadbdc0ee1ddf85afab201f [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);
Alec Mouri081be4c2020-09-16 10:24:47 -070039 SkiaGLRenderEngine(EGLDisplay display, EGLConfig config, EGLContext ctxt,
40 EGLSurface placeholder, EGLContext protectedContext,
John Reck67b1e2b2020-08-26 13:17:24 -070041 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);
Lucas Dupin3f11e922020-09-22 17:31:04 -070063 inline SkRect getSkRect(const FloatRect& layer);
64 inline SkRect getSkRect(const Rect& layer);
Lucas Dupin21f348e2020-09-16 17:31:26 -070065 inline SkRRect getRoundedRect(const LayerSettings* layer);
Lucas Dupin3f11e922020-09-22 17:31:04 -070066 inline SkColor getSkColor(const vec4& color);
Lucas Dupinbb1a1d42020-09-18 15:17:02 -070067 inline SkM44 getSkM44(const mat4& matrix);
Lucas Dupin3f11e922020-09-22 17:31:04 -070068 inline SkPoint3 getSkPoint3(const vec3& vector);
John Reck67b1e2b2020-08-26 13:17:24 -070069
70 base::unique_fd flush();
71 bool waitFence(base::unique_fd fenceFd);
Lucas Dupin3f11e922020-09-22 17:31:04 -070072 void drawShadow(SkCanvas* canvas, const SkRect& casterRect, float casterCornerRadius,
73 const ShadowSettings& shadowSettings);
John Reck67b1e2b2020-08-26 13:17:24 -070074
75 EGLDisplay mEGLDisplay;
76 EGLConfig mEGLConfig;
77 EGLContext mEGLContext;
78 EGLSurface mPlaceholderSurface;
79 EGLContext mProtectedEGLContext;
80 EGLSurface mProtectedPlaceholderSurface;
81
82 // Cache of GL images that we'll store per GraphicBuffer ID
83 std::unordered_map<uint64_t, sk_sp<SkImage>> mImageCache GUARDED_BY(mRenderingMutex);
84 // Mutex guarding rendering operations, so that:
85 // 1. GL operations aren't interleaved, and
86 // 2. Internal state related to rendering that is potentially modified by
87 // multiple threads is guaranteed thread-safe.
88 std::mutex mRenderingMutex;
89
90 sp<Fence> mLastDrawFence;
91
92 sk_sp<GrDirectContext> mGrContext;
93
94 std::unordered_map<uint64_t, sk_sp<SkSurface>> mSurfaceCache;
95};
96
97} // namespace skia
98} // namespace renderengine
99} // namespace android
100
101#endif /* SF_GLESRENDERENGINE_H_ */