RenderSurfaceCreationArgs.h 2.5 KB

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