1 /* 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 26 namespace android { 27 namespace uirenderer { 28 namespace renderthread { 29 30 using namespace android::uirenderer::renderthread; 31 32 using RenderCallback = std::function<void(android::base::unique_fd&&, int)>; 33 34 class RenderProxy; 35 36 class HardwareBufferRenderParams { 37 public: 38 HardwareBufferRenderParams() = default; HardwareBufferRenderParams(int32_t logicalWidth,int32_t logicalHeight,const SkMatrix & transform,const sk_sp<SkColorSpace> & colorSpace,RenderCallback && callback)39 HardwareBufferRenderParams(int32_t logicalWidth, int32_t logicalHeight, 40 const SkMatrix& transform, const sk_sp<SkColorSpace>& colorSpace, 41 RenderCallback&& callback) 42 : mLogicalWidth(logicalWidth) 43 , mLogicalHeight(logicalHeight) 44 , mTransform(transform) 45 , mColorSpace(colorSpace) 46 , mRenderCallback(std::move(callback)) {} getTransform()47 const SkMatrix& getTransform() const { return mTransform; } getColorSpace()48 sk_sp<SkColorSpace> getColorSpace() const { return mColorSpace; } 49 invokeRenderCallback(android::base::unique_fd && fenceFd,int status)50 void invokeRenderCallback(android::base::unique_fd&& fenceFd, int status) { 51 if (mRenderCallback) { 52 std::invoke(mRenderCallback, std::move(fenceFd), status); 53 } 54 } 55 getLogicalWidth()56 int32_t getLogicalWidth() { return mLogicalWidth; } getLogicalHeight()57 int32_t getLogicalHeight() { return mLogicalHeight; } 58 59 private: 60 int32_t mLogicalWidth; 61 int32_t mLogicalHeight; 62 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_ 71