• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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::compositionengine {
28 
29 /**
30  * A parameter object for creating RenderSurface instances
31  */
32 struct RenderSurfaceCreationArgs {
33     // The initial width of the surface
34     int32_t displayWidth = -1;
35 
36     // The initial height of the surface
37     int32_t displayHeight = -1;
38 
39     // The ANativeWindow for the buffer queue for this surface
40     sp<ANativeWindow> nativeWindow;
41 
42     // The DisplaySurface for this surface
43     sp<DisplaySurface> displaySurface;
44 
45     // The maximum size of the renderengine::ExternalTexture cache
46     size_t maxTextureCacheSize = 0;
47 
48 private:
49     friend class RenderSurfaceCreationArgsBuilder;
50 
51     // Not defaulted to disable aggregate initialization.
RenderSurfaceCreationArgsRenderSurfaceCreationArgs52     RenderSurfaceCreationArgs() {}
53 };
54 
55 class RenderSurfaceCreationArgsBuilder {
56 public:
build()57     RenderSurfaceCreationArgs build() { return std::move(mArgs); }
58 
setDisplayWidth(int32_t displayWidth)59     RenderSurfaceCreationArgsBuilder& setDisplayWidth(int32_t displayWidth) {
60         mArgs.displayWidth = displayWidth;
61         return *this;
62     }
setDisplayHeight(int32_t displayHeight)63     RenderSurfaceCreationArgsBuilder& setDisplayHeight(int32_t displayHeight) {
64         mArgs.displayHeight = displayHeight;
65         return *this;
66     }
setNativeWindow(sp<ANativeWindow> nativeWindow)67     RenderSurfaceCreationArgsBuilder& setNativeWindow(sp<ANativeWindow> nativeWindow) {
68         mArgs.nativeWindow = std::move(nativeWindow);
69         return *this;
70     }
setDisplaySurface(sp<DisplaySurface> displaySurface)71     RenderSurfaceCreationArgsBuilder& setDisplaySurface(sp<DisplaySurface> displaySurface) {
72         mArgs.displaySurface = std::move(displaySurface);
73         return *this;
74     }
75 
setMaxTextureCacheSize(size_t maxTextureCacheSize)76     RenderSurfaceCreationArgsBuilder& setMaxTextureCacheSize(size_t maxTextureCacheSize) {
77         mArgs.maxTextureCacheSize = maxTextureCacheSize;
78         return *this;
79     }
80 
81 private:
82     RenderSurfaceCreationArgs mArgs;
83 };
84 
85 } // namespace android::compositionengine
86