132a6e48fSopenharmony_ci/*
232a6e48fSopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd.
332a6e48fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
432a6e48fSopenharmony_ci * you may not use this file except in compliance with the License.
532a6e48fSopenharmony_ci * You may obtain a copy of the License at
632a6e48fSopenharmony_ci *
732a6e48fSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
832a6e48fSopenharmony_ci *
932a6e48fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1032a6e48fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1132a6e48fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1232a6e48fSopenharmony_ci * See the License for the specific language governing permissions and
1332a6e48fSopenharmony_ci * limitations under the License.
1432a6e48fSopenharmony_ci */
1532a6e48fSopenharmony_ci
1632a6e48fSopenharmony_ci#ifndef INTERFACES_INNERKITS_SURFACE_SURFACE_UTILS_H
1732a6e48fSopenharmony_ci#define INTERFACES_INNERKITS_SURFACE_SURFACE_UTILS_H
1832a6e48fSopenharmony_ci
1932a6e48fSopenharmony_ci#include <unordered_map>
2032a6e48fSopenharmony_ci#include <mutex>
2132a6e48fSopenharmony_ci#include "surface.h"
2232a6e48fSopenharmony_ci
2332a6e48fSopenharmony_cinamespace OHOS {
2432a6e48fSopenharmony_ciclass SurfaceUtils {
2532a6e48fSopenharmony_cipublic:
2632a6e48fSopenharmony_ci    static SurfaceUtils* GetInstance();
2732a6e48fSopenharmony_ci
2832a6e48fSopenharmony_ci    // get surface by uniqueId.
2932a6e48fSopenharmony_ci    sptr<Surface> GetSurface(uint64_t uniqueId);
3032a6e48fSopenharmony_ci    // maintenance map with uniqueId and surface.
3132a6e48fSopenharmony_ci    SurfaceError Add(uint64_t uniqueId, const wptr<Surface> &surface);
3232a6e48fSopenharmony_ci    // remove surface by uniqueId.
3332a6e48fSopenharmony_ci    SurfaceError Remove(uint64_t uniqueId);
3432a6e48fSopenharmony_ci    // Compute transform matrix
3532a6e48fSopenharmony_ci    void ComputeTransformMatrix(float matrix[16], uint32_t matrixSize,
3632a6e48fSopenharmony_ci        sptr<SurfaceBuffer>& buffer, GraphicTransformType& transform, Rect& crop);
3732a6e48fSopenharmony_ci    void ComputeTransformMatrixV2(float matrix[16], uint32_t matrixSize,
3832a6e48fSopenharmony_ci        sptr<SurfaceBuffer>& buffer, GraphicTransformType& transform, Rect& crop);
3932a6e48fSopenharmony_ci
4032a6e48fSopenharmony_ci    void* GetNativeWindow(uint64_t uniqueId);
4132a6e48fSopenharmony_ci    SurfaceError AddNativeWindow(uint64_t uniqueId, void *nativeWidow);
4232a6e48fSopenharmony_ci    SurfaceError RemoveNativeWindow(uint64_t uniqueId);
4332a6e48fSopenharmony_ci
4432a6e48fSopenharmony_ciprivate:
4532a6e48fSopenharmony_ci    SurfaceUtils() = default;
4632a6e48fSopenharmony_ci    virtual ~SurfaceUtils();
4732a6e48fSopenharmony_ci    std::array<float, 16> MatrixProduct(const std::array<float, 16>& lMat, const std::array<float, 16>& rMat);
4832a6e48fSopenharmony_ci    static constexpr int32_t TRANSFORM_MATRIX_ELE_COUNT = 16;
4932a6e48fSopenharmony_ci    void ComputeTransformByMatrix(GraphicTransformType& transform,
5032a6e48fSopenharmony_ci        std::array<float, TRANSFORM_MATRIX_ELE_COUNT> *transformMatrix);
5132a6e48fSopenharmony_ci    void ComputeTransformByMatrixV2(GraphicTransformType& transform,
5232a6e48fSopenharmony_ci        std::array<float, TRANSFORM_MATRIX_ELE_COUNT> *transformMatrix);
5332a6e48fSopenharmony_ci
5432a6e48fSopenharmony_ci    std::unordered_map<uint64_t, wptr<Surface>> surfaceCache_;
5532a6e48fSopenharmony_ci    std::mutex mutex_;
5632a6e48fSopenharmony_ci    std::unordered_map<uint64_t, void*> nativeWindowCache_;
5732a6e48fSopenharmony_ci};
5832a6e48fSopenharmony_ci} // namespace OHOS
5932a6e48fSopenharmony_ci
6032a6e48fSopenharmony_ci#endif // INTERFACES_INNERKITS_SURFACE_SURFACE_UTILS_H
61