Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 26bff38b authored by Biswarup Pal's avatar Biswarup Pal
Browse files

Allow max texture size as VirtualCameraStreamConfig size upper bound

Test: atest VirtualCameraConfigTest
Bug: 291736219
Change-Id: Ifc381661af475837f68a90f8afbc1f1426568b66
parent 57090a06
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@

#include <cstring>

#include "EglDisplayContext.h"
#include "GLES/gl.h"
#include "log/log.h"

@@ -27,6 +28,9 @@ namespace android {
namespace companion {
namespace virtualcamera {

// Lower bound for maximum supported texture size is at least 2048x2048
constexpr int kDefaultMaxTextureSize = 2048;

bool checkEglError(const char* operation) {
  GLenum err = glGetError();
  if (err == GL_NO_ERROR) {
@@ -45,6 +49,20 @@ bool isGlExtensionSupported(const char* extension) {
  return strstr(extensions, extension) != nullptr;
}

int getMaximumTextureSize() {
  static const int kMaxTextureSize = [] {
    EglDisplayContext displayContext;
    displayContext.makeCurrent();
    int maxTextureSize = -1;
    glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
    return maxTextureSize;
  }();
  if (kMaxTextureSize <= 0) {
    return kDefaultMaxTextureSize;
  }
  return kMaxTextureSize;
}

}  // namespace virtualcamera
}  // namespace companion
}  // namespace android
+2 −0
Original line number Diff line number Diff line
@@ -27,6 +27,8 @@ bool checkEglError(const char* operation = "EGL operation");
// Returns true if the GL extension is supported, false otherwise.
bool isGlExtensionSupported(const char* extension);

int getMaximumTextureSize();

}  // namespace virtualcamera
}  // namespace companion
}  // namespace android
+4 −7
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
#include <cstdint>
#include <memory>

#include "EglUtil.h"
#include "android/hardware_buffer.h"
#include "jpeglib.h"
#include "ui/GraphicBuffer.h"
@@ -35,11 +36,6 @@ namespace virtualcamera {
using ::aidl::android::companion::virtualcamera::Format;
using ::aidl::android::hardware::common::NativeHandle;

// Lower bound for maximal supported texture size is at least 2048x2048
// but on most platforms will be more.
// TODO(b/301023410) - Query actual max texture size.
constexpr int kMaxTextureSize = 2048;
constexpr int kLibJpegDctSize = DCTSIZE;
constexpr int kMaxFpsUpperLimit = 60;

constexpr std::array<Format, 2> kSupportedFormats{Format::YUV_420_888,
@@ -141,8 +137,9 @@ bool isFormatSupportedForInput(const int width, const int height,
    return false;
  }

  if (width <= 0 || height <= 0 || width > kMaxTextureSize ||
      height > kMaxTextureSize) {
  int maxTextureSize = getMaximumTextureSize();
  if (width <= 0 || height <= 0 || width > maxTextureSize ||
      height > maxTextureSize) {
    return false;
  }