1 /* 2 * Copyright (c) 2021-2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef RENDER_SERVICE_CLIENT_CORE_RENDER_THREAD_RS_RENDER_THREAD_UTIL_H 17 #define RENDER_SERVICE_CLIENT_CORE_RENDER_THREAD_RS_RENDER_THREAD_UTIL_H 18 19 #include "pipeline/rs_surface_render_node.h" 20 #include "utils/rect.h" 21 22 namespace OHOS { 23 namespace Rosen { 24 struct TextureExportBufferDrawParam { 25 #ifdef ROSEN_OHOS 26 sptr<OHOS::SurfaceBuffer> buffer; 27 #endif 28 Drawing::Matrix matrix; // for moving canvas to layer(surface)'s leftTop point. 29 Drawing::Rect srcRect; // surface's bufferSize 30 Drawing::Rect dstRect; // surface's boundsSize 31 }; 32 33 #ifdef ROSEN_OHOS 34 namespace { 35 constexpr uint32_t API_VERSION_MOD = 1000; 36 constexpr uint32_t INVALID_API_COMPATIBLE_VERSION = 0; 37 } // namespace 38 #endif 39 40 class RSRenderThreadUtil { 41 public: 42 static void SrcRectScaleDown(TextureExportBufferDrawParam& params, const RectF& localBounds); 43 static void SrcRectScaleFit(TextureExportBufferDrawParam& params, const RectF& localBounds); 44 static GraphicTransformType GetRotateTransform(GraphicTransformType transform); 45 static GraphicTransformType GetFlipTransform(GraphicTransformType transform); 46 static Drawing::Matrix GetGravityMatrix(Gravity gravity, const RectF& bufferBounds, const RectF& bounds); 47 static Drawing::Matrix GetSurfaceTransformMatrix(GraphicTransformType rotationTransform, const RectF &bufferBounds); 48 static void FlipMatrix(GraphicTransformType transform, TextureExportBufferDrawParam& params); 49 50 #ifdef ROSEN_OHOS 51 static TextureExportBufferDrawParam CreateTextureExportBufferDrawParams( 52 RSSurfaceRenderNode& surfaceNode, GraphicTransformType graphicTransformType, sptr<OHOS::SurfaceBuffer> buffer); 53 static void DealWithSurfaceRotationAndGravity(GraphicTransformType transform, Gravity gravity, 54 RectF& localBounds, TextureExportBufferDrawParam& params); 55 #endif 56 }; 57 } // namespace Rosen 58 } // namespace OHOS 59 60 #endif // RENDER_SERVICE_CLIENT_CORE_RENDER_THREAD_RS_RENDER_THREAD_UTIL_H