blob: 8c942d0fa102958ab53abbc05122f5de14b271ba [file] [log] [blame]
Nader Jawada3521852023-01-30 20:23:46 -08001/*
2 * Copyright (C) 2013 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#ifndef HARDWAREBUFFERRENDERER_H_
17#define HARDWAREBUFFERRENDERER_H_
18
19#include <android-base/unique_fd.h>
20#include <android/hardware_buffer.h>
21
22#include "SkColorSpace.h"
23#include "SkMatrix.h"
24#include "SkSurface.h"
25
26namespace android {
27namespace uirenderer {
28namespace renderthread {
29
30using namespace android::uirenderer::renderthread;
31
32using RenderCallback = std::function<void(android::base::unique_fd&&, int)>;
33
34class RenderProxy;
35
36class HardwareBufferRenderParams {
37public:
38 HardwareBufferRenderParams() = default;
Nader Jawad24617222023-03-30 12:29:01 -070039 HardwareBufferRenderParams(int32_t logicalWidth, int32_t logicalHeight,
40 const SkMatrix& transform, const sk_sp<SkColorSpace>& colorSpace,
Nader Jawada3521852023-01-30 20:23:46 -080041 RenderCallback&& callback)
Nader Jawad24617222023-03-30 12:29:01 -070042 : mLogicalWidth(logicalWidth)
43 , mLogicalHeight(logicalHeight)
44 , mTransform(transform)
Nader Jawada3521852023-01-30 20:23:46 -080045 , mColorSpace(colorSpace)
46 , mRenderCallback(std::move(callback)) {}
47 const SkMatrix& getTransform() const { return mTransform; }
48 sk_sp<SkColorSpace> getColorSpace() const { return mColorSpace; }
49
50 void invokeRenderCallback(android::base::unique_fd&& fenceFd, int status) {
51 if (mRenderCallback) {
52 std::invoke(mRenderCallback, std::move(fenceFd), status);
53 }
54 }
55
Nader Jawad24617222023-03-30 12:29:01 -070056 int32_t getLogicalWidth() { return mLogicalWidth; }
57 int32_t getLogicalHeight() { return mLogicalHeight; }
58
Nader Jawada3521852023-01-30 20:23:46 -080059private:
Nader Jawad24617222023-03-30 12:29:01 -070060 int32_t mLogicalWidth;
61 int32_t mLogicalHeight;
Nader Jawada3521852023-01-30 20:23:46 -080062 SkMatrix mTransform = SkMatrix::I();
63 sk_sp<SkColorSpace> mColorSpace = SkColorSpace::MakeSRGB();
64 RenderCallback mRenderCallback = nullptr;
65};
66
67} // namespace renderthread
68} // namespace uirenderer
69} // namespace android
70#endif // HARDWAREBUFFERRENDERER_H_