Skip to content

Commit

Permalink
Don't use GLRepresentation for overlays
Browse files Browse the repository at this point in the history
All relevant backing should support Overlay representation by now.

Change-Id: I0f06a6e9641c3e5c5c056d7f7111a26494894342
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3225866
Reviewed-by: Peng Huang <penghuang@chromium.org>
Commit-Queue: Vasiliy Telezhnikov <vasilyt@chromium.org>
Cr-Commit-Position: refs/heads/main@{#932593}
  • Loading branch information
vasilyt authored and Chromium LUCI CQ committed Oct 18, 2021
1 parent 7973741 commit b8db09a
Showing 1 changed file with 6 additions and 39 deletions.
45 changes: 6 additions & 39 deletions components/viz/service/display_embedder/output_presenter_gl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,8 @@ class PresenterImageGL : public OutputPresenter::Image {
private:
std::unique_ptr<gpu::SharedImageRepresentationOverlay>
overlay_representation_;
std::unique_ptr<gpu::SharedImageRepresentationGLTexture> gl_representation_;
std::unique_ptr<gpu::SharedImageRepresentationOverlay::ScopedReadAccess>
scoped_overlay_read_access_;
std::unique_ptr<gpu::SharedImageRepresentationGLTexture::ScopedAccess>
scoped_gl_read_access_;

int present_count_ = 0;
};
Expand All @@ -99,14 +96,8 @@ bool PresenterImageGL::Initialize(

overlay_representation_ = representation_factory->ProduceOverlay(mailbox);

// If the backing doesn't support overlay, then fallback to GL.
if (!overlay_representation_) {
LOG(ERROR) << "ProduceOverlay() failed";
gl_representation_ = representation_factory->ProduceGLTexture(mailbox);
}

if (!overlay_representation_ && !gl_representation_) {
LOG(ERROR) << "ProduceOverlay() and ProduceGLTexture() failed.";
return false;
}

Expand All @@ -115,39 +106,27 @@ bool PresenterImageGL::Initialize(

void PresenterImageGL::BeginPresent() {
if (++present_count_ != 1) {
DCHECK(scoped_overlay_read_access_ || scoped_gl_read_access_);
DCHECK(scoped_overlay_read_access_);
return;
}

DCHECK(!sk_surface());
DCHECK(!scoped_overlay_read_access_);

if (overlay_representation_) {
scoped_overlay_read_access_ =
overlay_representation_->BeginScopedReadAccess(
true /* need_gl_image */);
DCHECK(scoped_overlay_read_access_);
return;
}

scoped_gl_read_access_ = gl_representation_->BeginScopedAccess(
GL_SHARED_IMAGE_ACCESS_MODE_READ_CHROMIUM,
gpu::SharedImageRepresentation::AllowUnclearedAccess::kNo);
DCHECK(scoped_gl_read_access_);
}

void PresenterImageGL::EndPresent(gfx::GpuFenceHandle release_fence) {
DCHECK(present_count_);
if (--present_count_)
return;

// Check there is no release fence if we have a non-overlay read access.
DCHECK(!scoped_gl_read_access_ || release_fence.is_null());
if (scoped_overlay_read_access_)
scoped_overlay_read_access_->SetReleaseFence(std::move(release_fence));
scoped_overlay_read_access_->SetReleaseFence(std::move(release_fence));

scoped_overlay_read_access_.reset();
scoped_gl_read_access_.reset();
}

int PresenterImageGL::GetPresentCount() const {
Expand All @@ -157,27 +136,15 @@ int PresenterImageGL::GetPresentCount() const {
void PresenterImageGL::OnContextLost() {
if (overlay_representation_)
overlay_representation_->OnContextLost();
if (gl_representation_)
gl_representation_->OnContextLost();
}

gl::GLImage* PresenterImageGL::GetGLImage(
std::unique_ptr<gfx::GpuFence>* fence) {
if (scoped_overlay_read_access_) {
if (fence) {
*fence = TakeGpuFence(scoped_overlay_read_access_->TakeAcquireFences());
}
return scoped_overlay_read_access_->gl_image();
}

DCHECK(scoped_gl_read_access_);

if (gl::GLFence::IsGpuFenceSupported() && fence) {
if (auto gl_fence = gl::GLFence::CreateForGpuFence())
*fence = gl_fence->GetGpuFence();
DCHECK(scoped_overlay_read_access_);
if (fence) {
*fence = TakeGpuFence(scoped_overlay_read_access_->TakeAcquireFences());
}
auto* texture = gl_representation_->GetTexture();
return texture->GetLevelImage(texture->target(), 0);
return scoped_overlay_read_access_->gl_image();
}

} // namespace
Expand Down

0 comments on commit b8db09a

Please sign in to comment.