Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 63 additions & 50 deletions host/color_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,21 +87,21 @@ class ColorBuffer::Impl : public LazySnapshotObj<ColorBuffer::Impl> {
std::optional<BlobDescriptorInfo> exportBlob();

#if GFXSTREAM_ENABLE_HOST_GLES
GLuint glOpGetTexture();
bool canUseGlOps();
bool glOpBlitFromCurrentReadBuffer();
bool glOpBindToTexture();
bool glOpBindToTexture2();
bool glOpBindToRenderbuffer();
void glOpReadback(unsigned char* img, bool readbackBgra);
void glOpReadbackAsync(GLuint buffer, bool readbackBgra);
bool glOpReadback(unsigned char* img, bool readbackBgra);
bool glOpReadbackAsync(GLuint buffer, bool readbackBgra);
bool glOpImportEglNativePixmap(void* pixmap, bool preserveContent);
void glOpSwapYuvTexturesAndUpdate(GLenum format, GLenum type, GfxstreamFormat texturesFormat,
bool glOpSwapYuvTexturesAndUpdate(GLenum format, GLenum type, GfxstreamFormat texturesFormat,
GLuint* textures);
bool glOpReadContents(size_t* outNumBytes, void* outContents);
bool glOpIsFastBlitSupported() const;
void glOpPostLayer(const ComposeLayer& l, int frameWidth, int frameHeight,
bool glOpPostLayer(const ComposeLayer& l, int frameWidth, int frameHeight,
const std::optional<std::array<float, 16>>& colorTransform);
void glOpPostViewportScaledWithOverlay(
bool glOpPostViewportScaledWithOverlay(
float rotation, float dx, float dy, float scaleX, float scaleY,
const std::optional<std::array<float, 16>>& colorTransform);
#endif
Expand Down Expand Up @@ -268,7 +268,7 @@ void ColorBuffer::Impl::readToBytes(
return;
}

GFXSTREAM_FATAL("No ColorBuffer impl");
GFXSTREAM_FATAL("%s: No ColorBuffer impl", __func__);
}

void ColorBuffer::Impl::readToBytesScaled(
Expand All @@ -289,7 +289,7 @@ void ColorBuffer::Impl::readToBytesScaled(
return;
}

GFXSTREAM_FATAL("%s: Unimplemented", __func__);
GFXSTREAM_FATAL("%s: No ColorBuffer impl", __func__);
}

void ColorBuffer::Impl::readYuvToBytes(int x, int y, int width, int height, void* outPixels,
Expand All @@ -308,7 +308,7 @@ void ColorBuffer::Impl::readYuvToBytes(int x, int y, int width, int height, void
return;
}

GFXSTREAM_FATAL("No ColorBuffer impl");
GFXSTREAM_FATAL("%s: No ColorBuffer impl", __func__);
}

bool ColorBuffer::Impl::updateFromBytes(int x, int y, int width, int height, GfxstreamFormat pixelsFormat,
Expand All @@ -329,7 +329,7 @@ bool ColorBuffer::Impl::updateFromBytes(int x, int y, int width, int height, Gfx
return mColorBufferVk->updateFromBytes(x, y, width, height, pixels);
}

GFXSTREAM_FATAL("No ColorBuffer impl");
GFXSTREAM_FATAL("%s: No ColorBuffer impl", __func__);
return false;
}

Expand All @@ -351,19 +351,21 @@ std::unique_ptr<BorrowedImageInfo> ColorBuffer::Impl::borrowForComposition(UsedA
case UsedApi::kGl: {
#if GFXSTREAM_ENABLE_HOST_GLES
if (!mColorBufferGl) {
GFXSTREAM_FATAL("ColorBufferGl not available");
GFXSTREAM_ERROR("%s: ColorBufferGl not available", __func__);
return nullptr;
}
return mColorBufferGl->getBorrowedImageInfo();
#endif
}
case UsedApi::kVk: {
if (!mColorBufferVk) {
GFXSTREAM_FATAL("ColorBufferVk not available");
GFXSTREAM_ERROR("%s: ColorBufferVk not available", __func__);
return nullptr;
}
return mColorBufferVk->borrowForComposition(isTarget);
}
}
GFXSTREAM_FATAL("%s: Unimplemented", __func__);
GFXSTREAM_ERROR("%s: Unimplemented", __func__);
return nullptr;
}

Expand All @@ -372,19 +374,21 @@ std::unique_ptr<BorrowedImageInfo> ColorBuffer::Impl::borrowForDisplay(UsedApi a
case UsedApi::kGl: {
#if GFXSTREAM_ENABLE_HOST_GLES
if (!mColorBufferGl) {
GFXSTREAM_FATAL("ColorBufferGl not available");
GFXSTREAM_ERROR("%s: ColorBufferGl not available", __func__);
return nullptr;
}
return mColorBufferGl->getBorrowedImageInfo();
#endif
}
case UsedApi::kVk: {
if (!mColorBufferVk) {
GFXSTREAM_FATAL("ColorBufferVk not available");
GFXSTREAM_ERROR("%s: ColorBufferVk not available", __func__);
return nullptr;
}
return mColorBufferVk->borrowForDisplay();
}
}
GFXSTREAM_FATAL("%s: Unimplemented", __func__);
GFXSTREAM_ERROR("%s: Unimplemented", __func__);
return nullptr;
}

Expand Down Expand Up @@ -511,9 +515,14 @@ std::optional<BlobDescriptorInfo> ColorBuffer::Impl::exportBlob() {
}

#if GFXSTREAM_ENABLE_HOST_GLES
bool ColorBuffer::Impl::canUseGlOps() {
return (mColorBufferGl != nullptr);
}

bool ColorBuffer::Impl::glOpBlitFromCurrentReadBuffer() {
if (!mColorBufferGl) {
GFXSTREAM_FATAL("ColorBufferGl not available");
GFXSTREAM_ERROR("%s: ColorBufferGl not available", __func__);
return false;
}

touch();
Expand All @@ -523,7 +532,8 @@ bool ColorBuffer::Impl::glOpBlitFromCurrentReadBuffer() {

bool ColorBuffer::Impl::glOpBindToTexture() {
if (!mColorBufferGl) {
GFXSTREAM_FATAL("ColorBufferGl not available");
GFXSTREAM_ERROR("%s: ColorBufferGl not available", __func__);
return false;
}

touch();
Expand All @@ -533,65 +543,61 @@ bool ColorBuffer::Impl::glOpBindToTexture() {

bool ColorBuffer::Impl::glOpBindToTexture2() {
if (!mColorBufferGl) {
GFXSTREAM_FATAL("ColorBufferGl not available");
GFXSTREAM_ERROR("%s: ColorBufferGl not available", __func__);
return false;
}

return mColorBufferGl->bindToTexture2();
}

bool ColorBuffer::Impl::glOpBindToRenderbuffer() {
if (!mColorBufferGl) {
GFXSTREAM_FATAL("ColorBufferGl not available");
GFXSTREAM_ERROR("%s: ColorBufferGl not available", __func__);
return false;
}

touch();

return mColorBufferGl->bindToRenderbuffer();
}

GLuint ColorBuffer::Impl::glOpGetTexture() {
if (!mColorBufferGl) {
GFXSTREAM_FATAL("ColorBufferGl not available");
}

touch();

return mColorBufferGl->getTexture();
}

void ColorBuffer::Impl::glOpReadback(unsigned char* img, bool readbackBgra) {
bool ColorBuffer::Impl::glOpReadback(unsigned char* img, bool readbackBgra) {
if (!mColorBufferGl) {
GFXSTREAM_FATAL("ColorBufferGl not available");
GFXSTREAM_ERROR("%s: ColorBufferGl not available", __func__);
return false;
}

touch();

return mColorBufferGl->readback(img, readbackBgra);
}

void ColorBuffer::Impl::glOpReadbackAsync(GLuint buffer, bool readbackBgra) {
bool ColorBuffer::Impl::glOpReadbackAsync(GLuint buffer, bool readbackBgra) {
if (!mColorBufferGl) {
GFXSTREAM_FATAL("ColorBufferGl not available");
GFXSTREAM_ERROR("%s: ColorBufferGl not available", __func__);
return false;
}

touch();

mColorBufferGl->readbackAsync(buffer, readbackBgra);
return mColorBufferGl->readbackAsync(buffer, readbackBgra);
}

bool ColorBuffer::Impl::glOpImportEglNativePixmap(void* pixmap, bool preserveContent) {
if (!mColorBufferGl) {
GFXSTREAM_FATAL("ColorBufferGl not available");
GFXSTREAM_ERROR("%s: ColorBufferGl not available", __func__);
return false;
}

return mColorBufferGl->importEglNativePixmap(pixmap, preserveContent);
}

void ColorBuffer::Impl::glOpSwapYuvTexturesAndUpdate(GLenum format, GLenum type,
bool ColorBuffer::Impl::glOpSwapYuvTexturesAndUpdate(GLenum format, GLenum type,
GfxstreamFormat texturesFormat,
GLuint* textures) {
if (!mColorBufferGl) {
GFXSTREAM_FATAL("ColorBufferGl not available");
GFXSTREAM_ERROR("%s: ColorBufferGl not available", __func__);
return false;
}

mColorBufferGl->swapYUVTextures(texturesFormat, textures);
Expand All @@ -601,41 +607,48 @@ void ColorBuffer::Impl::glOpSwapYuvTexturesAndUpdate(GLenum format, GLenum type,
mColorBufferGl->subUpdate(0, 0, mWidth, mHeight, texturesFormat, /*pixels=*/nullptr);

flushFromGl();
return true;
}

bool ColorBuffer::Impl::glOpReadContents(size_t* outNumBytes, void* outContents) {
if (!mColorBufferGl) {
GFXSTREAM_FATAL("ColorBufferGl not available");
GFXSTREAM_ERROR("%s: ColorBufferGl not available", __func__);
return false;
}

return mColorBufferGl->readContents(outNumBytes, outContents);
}

bool ColorBuffer::Impl::glOpIsFastBlitSupported() const {
if (!mColorBufferGl) {
GFXSTREAM_FATAL("ColorBufferGl not available");
GFXSTREAM_ERROR("%s: ColorBufferGl not available", __func__);
return false;
}

return mColorBufferGl->isFastBlitSupported();
}

void ColorBuffer::Impl::glOpPostLayer(const ComposeLayer& l, int frameWidth, int frameHeight,
bool ColorBuffer::Impl::glOpPostLayer(const ComposeLayer& l, int frameWidth, int frameHeight,
const std::optional<std::array<float, 16>>& colorTransform) {
if (!mColorBufferGl) {
GFXSTREAM_FATAL("ColorBufferGl not available");
GFXSTREAM_ERROR("%s: ColorBufferGl not available", __func__);
return false;
}

mColorBufferGl->postLayer(l, frameWidth, frameHeight, colorTransform);
return true;
}

void ColorBuffer::Impl::glOpPostViewportScaledWithOverlay(
bool ColorBuffer::Impl::glOpPostViewportScaledWithOverlay(
float rotation, float dx, float dy, float scaleX, float scaleY,
const std::optional<std::array<float, 16>>& colorTransform) {
if (!mColorBufferGl) {
GFXSTREAM_FATAL("ColorBufferGl not available");
GFXSTREAM_ERROR("%s: ColorBufferGl not available", __func__);
return false;
}

mColorBufferGl->postViewportScaledWithOverlay(rotation, dx, dy, scaleX, scaleY, colorTransform);
return true;
}
#endif

Expand Down Expand Up @@ -737,7 +750,7 @@ bool ColorBuffer::invalidateForVk() { return mImpl->invalidateForVk(); }
std::optional<BlobDescriptorInfo> ColorBuffer::exportBlob() { return mImpl->exportBlob(); }

#if GFXSTREAM_ENABLE_HOST_GLES
GLuint ColorBuffer::glOpGetTexture() { return mImpl->glOpGetTexture(); }
bool ColorBuffer::canUseGlOps() { return mImpl->canUseGlOps(); }

bool ColorBuffer::glOpBlitFromCurrentReadBuffer() { return mImpl->glOpBlitFromCurrentReadBuffer(); }

Expand All @@ -747,19 +760,19 @@ bool ColorBuffer::glOpBindToTexture2() { return mImpl->glOpBindToTexture2(); }

bool ColorBuffer::glOpBindToRenderbuffer() { return mImpl->glOpBindToRenderbuffer(); }

void ColorBuffer::glOpReadback(unsigned char* img, bool readbackBgra) {
bool ColorBuffer::glOpReadback(unsigned char* img, bool readbackBgra) {
return mImpl->glOpReadback(img, readbackBgra);
}

void ColorBuffer::glOpReadbackAsync(GLuint buffer, bool readbackBgra) {
bool ColorBuffer::glOpReadbackAsync(GLuint buffer, bool readbackBgra) {
return mImpl->glOpReadbackAsync(buffer, readbackBgra);
}

bool ColorBuffer::glOpImportEglNativePixmap(void* pixmap, bool preserveContent) {
return mImpl->glOpImportEglNativePixmap(pixmap, preserveContent);
}

void ColorBuffer::glOpSwapYuvTexturesAndUpdate(GLenum format, GLenum type,
bool ColorBuffer::glOpSwapYuvTexturesAndUpdate(GLenum format, GLenum type,
GfxstreamFormat texturesFormat, GLuint* textures) {
return mImpl->glOpSwapYuvTexturesAndUpdate(format, type, texturesFormat, textures);
}
Expand All @@ -770,12 +783,12 @@ bool ColorBuffer::glOpReadContents(size_t* outNumBytes, void* outContents) {

bool ColorBuffer::glOpIsFastBlitSupported() const { return mImpl->glOpIsFastBlitSupported(); }

void ColorBuffer::glOpPostLayer(const ComposeLayer& l, int frameWidth, int frameHeight,
bool ColorBuffer::glOpPostLayer(const ComposeLayer& l, int frameWidth, int frameHeight,
const std::optional<std::array<float, 16>>& colorTransform) {
return mImpl->glOpPostLayer(l, frameWidth, frameHeight, colorTransform);
}

void ColorBuffer::glOpPostViewportScaledWithOverlay(
bool ColorBuffer::glOpPostViewportScaledWithOverlay(
float rotation, float dx, float dy, float scaleX, float scaleY,
const std::optional<std::array<float, 16>>& colorTransform) {
return mImpl->glOpPostViewportScaledWithOverlay(rotation, dx, dy, scaleX, scaleY,
Expand Down
12 changes: 6 additions & 6 deletions host/color_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,21 +105,21 @@ class ColorBuffer : public LazySnapshotObj<ColorBuffer> {
std::optional<BlobDescriptorInfo> exportBlob();

#if GFXSTREAM_ENABLE_HOST_GLES
GLuint glOpGetTexture();
bool canUseGlOps();
bool glOpBlitFromCurrentReadBuffer();
bool glOpBindToTexture();
bool glOpBindToTexture2();
bool glOpBindToRenderbuffer();
void glOpReadback(unsigned char* img, bool readbackBgra);
void glOpReadbackAsync(GLuint buffer, bool readbackBgra);
bool glOpReadback(unsigned char* img, bool readbackBgra);
bool glOpReadbackAsync(GLuint buffer, bool readbackBgra);
bool glOpImportEglNativePixmap(void* pixmap, bool preserveContent);
void glOpSwapYuvTexturesAndUpdate(GLenum format, GLenum type, GfxstreamFormat texturesFormat,
bool glOpSwapYuvTexturesAndUpdate(GLenum format, GLenum type, GfxstreamFormat texturesFormat,
GLuint* textures);
bool glOpReadContents(size_t* outNumBytes, void* outContents);
bool glOpIsFastBlitSupported() const;
void glOpPostLayer(const ComposeLayer& l, int frameWidth, int frameHeight,
bool glOpPostLayer(const ComposeLayer& l, int frameWidth, int frameHeight,
const std::optional<std::array<float, 16>>& colorTransform);
void glOpPostViewportScaledWithOverlay(
bool glOpPostViewportScaledWithOverlay(
float rotation, float dx, float dy, float scaleX, float scaleY,
const std::optional<std::array<float, 16>>& colorTransform);
#endif
Expand Down
10 changes: 10 additions & 0 deletions host/frame_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4742,6 +4742,16 @@ bool FrameBuffer::Impl::bindColorBufferToTexture2(HandleType p_colorbuffer) {
return false;
}

if (!colorBuffer->canUseGlOps()) {
// cannot call glOpBindToTexture2 without a valid gl colorbuffer
static bool errorReported = false;
if (!errorReported) {
GFXSTREAM_ERROR("%s: Cannot use GL colorbuffer operations", __func__);
errorReported = true;
}
return false;
}

return colorBuffer->glOpBindToTexture2();
}

Expand Down
Loading
Loading