1 /* 2 * Copyright 2019 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 #pragma once 18 19 #include <cstdint> 20 #include <memory> 21 22 #include <compositionengine/DisplaySurface.h> 23 #include <utils/StrongPointer.h> 24 25 struct ANativeWindow; 26 27 namespace android { 28 29 namespace compositionengine { 30 31 class Display; 32 33 /** 34 * A parameter object for creating RenderSurface instances 35 */ 36 struct RenderSurfaceCreationArgs { 37 // The initial width of the surface 38 int32_t displayWidth; 39 40 // The initial height of the surface 41 int32_t displayHeight; 42 43 // The ANativeWindow for the buffer queue for this surface 44 sp<ANativeWindow> nativeWindow; 45 46 // The DisplaySurface for this surface 47 sp<DisplaySurface> displaySurface; 48 }; 49 50 /** 51 * A helper for setting up a RenderSurfaceCreationArgs value in-line. 52 * Prefer this builder over raw structure initialization. 53 * 54 * Instead of: 55 * 56 * RenderSurfaceCreationArgs{1000, 1000, nativeWindow, displaySurface} 57 * 58 * Prefer: 59 * 60 * RenderSurfaceCreationArgsBuilder().setDisplayWidth(1000).setDisplayHeight(1000) 61 * .setNativeWindow(nativeWindow).setDisplaySurface(displaySurface).Build(); 62 */ 63 class RenderSurfaceCreationArgsBuilder { 64 public: build()65 RenderSurfaceCreationArgs build() { return std::move(mArgs); } 66 setDisplayWidth(int32_t displayWidth)67 RenderSurfaceCreationArgsBuilder& setDisplayWidth(int32_t displayWidth) { 68 mArgs.displayWidth = displayWidth; 69 return *this; 70 } setDisplayHeight(int32_t displayHeight)71 RenderSurfaceCreationArgsBuilder& setDisplayHeight(int32_t displayHeight) { 72 mArgs.displayHeight = displayHeight; 73 return *this; 74 } setNativeWindow(sp<ANativeWindow> nativeWindow)75 RenderSurfaceCreationArgsBuilder& setNativeWindow(sp<ANativeWindow> nativeWindow) { 76 mArgs.nativeWindow = nativeWindow; 77 return *this; 78 } setDisplaySurface(sp<DisplaySurface> displaySurface)79 RenderSurfaceCreationArgsBuilder& setDisplaySurface(sp<DisplaySurface> displaySurface) { 80 mArgs.displaySurface = displaySurface; 81 return *this; 82 } 83 84 private: 85 RenderSurfaceCreationArgs mArgs; 86 }; 87 88 } // namespace compositionengine 89 } // namespace android 90