Commit 4afb628e authored by Khushal's avatar Khushal Committed by Commit Bot

gpu/android : Add support for partial swap with surface control.

Add support for PostSubBuffer to GLSurfaceEGLSurfaceControl. This should
allow the display compositor to draw the minimum sub-rect necessary from
the damage tracking in BufferQueue on the client-side, and also to pass
this damage rect to the framework.

R=piman@chromium.org

Bug: 926020
Change-Id: I73d3320cab68250d4c6865bf21c5531682d8bf61
Reviewed-on: https://chromium-review.googlesource.com/c/1457467
Commit-Queue: Khushal <khushalsagar@chromium.org>
Commit-Queue: Antoine Labour <piman@chromium.org>
Reviewed-by: default avatarAntoine Labour <piman@chromium.org>
Auto-Submit: Khushal <khushalsagar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#629852}
parent 9dd1a4b1
...@@ -61,16 +61,6 @@ GLOutputSurfaceBufferQueueAndroid::GLOutputSurfaceBufferQueueAndroid( ...@@ -61,16 +61,6 @@ GLOutputSurfaceBufferQueueAndroid::GLOutputSurfaceBufferQueueAndroid(
GLOutputSurfaceBufferQueueAndroid::~GLOutputSurfaceBufferQueueAndroid() = GLOutputSurfaceBufferQueueAndroid::~GLOutputSurfaceBufferQueueAndroid() =
default; default;
void GLOutputSurfaceBufferQueueAndroid::HandlePartialSwap(
const gfx::Rect& sub_buffer_rect,
uint32_t flags,
gpu::ContextSupport::SwapCompletedCallback swap_callback,
gpu::ContextSupport::PresentationCallback presentation_callback) {
DCHECK(sub_buffer_rect.IsEmpty());
context_provider_->ContextSupport()->CommitOverlayPlanes(
flags, std::move(swap_callback), std::move(presentation_callback));
}
OverlayCandidateValidator* OverlayCandidateValidator*
GLOutputSurfaceBufferQueueAndroid::GetOverlayCandidateValidator() const { GLOutputSurfaceBufferQueueAndroid::GetOverlayCandidateValidator() const {
return overlay_candidate_validator_.get(); return overlay_candidate_validator_.get();
......
...@@ -21,11 +21,6 @@ class GLOutputSurfaceBufferQueueAndroid : public GLOutputSurfaceBufferQueue { ...@@ -21,11 +21,6 @@ class GLOutputSurfaceBufferQueueAndroid : public GLOutputSurfaceBufferQueue {
~GLOutputSurfaceBufferQueueAndroid() override; ~GLOutputSurfaceBufferQueueAndroid() override;
// GLOutputSurfaceBufferQueue implementation: // GLOutputSurfaceBufferQueue implementation:
void HandlePartialSwap(
const gfx::Rect& sub_buffer_rect,
uint32_t flags,
gpu::ContextSupport::SwapCompletedCallback swap_callback,
gpu::ContextSupport::PresentationCallback presentation_callback) override;
OverlayCandidateValidator* GetOverlayCandidateValidator() const override; OverlayCandidateValidator* GetOverlayCandidateValidator() const override;
private: private:
......
...@@ -1194,6 +1194,7 @@ void CompositorImpl::InitializeVizLayerTreeFrameSink( ...@@ -1194,6 +1194,7 @@ void CompositorImpl::InitializeVizLayerTreeFrameSink(
display_client_->GetBoundPtr(task_runner).PassInterface(); display_client_->GetBoundPtr(task_runner).PassInterface();
viz::RendererSettings renderer_settings; viz::RendererSettings renderer_settings;
renderer_settings.partial_swap_enabled = true;
renderer_settings.allow_antialiasing = false; renderer_settings.allow_antialiasing = false;
renderer_settings.highp_threshold_min = 2048; renderer_settings.highp_threshold_min = 2048;
renderer_settings.requires_alpha_channel = requires_alpha_channel_; renderer_settings.requires_alpha_channel = requires_alpha_channel_;
......
...@@ -31,7 +31,11 @@ gfx::Size GetBufferSize(const AHardwareBuffer* buffer) { ...@@ -31,7 +31,11 @@ gfx::Size GetBufferSize(const AHardwareBuffer* buffer) {
GLSurfaceEGLSurfaceControl::GLSurfaceEGLSurfaceControl( GLSurfaceEGLSurfaceControl::GLSurfaceEGLSurfaceControl(
ANativeWindow* window, ANativeWindow* window,
scoped_refptr<base::SingleThreadTaskRunner> task_runner) scoped_refptr<base::SingleThreadTaskRunner> task_runner)
: root_surface_(new SurfaceControl::Surface(window, kRootSurfaceName)), : window_rect_(0,
0,
ANativeWindow_getWidth(window),
ANativeWindow_getHeight(window)),
root_surface_(new SurfaceControl::Surface(window, kRootSurfaceName)),
gpu_task_runner_(std::move(task_runner)), gpu_task_runner_(std::move(task_runner)),
weak_factory_(this) {} weak_factory_(this) {}
...@@ -57,7 +61,7 @@ bool GLSurfaceEGLSurfaceControl::Resize(const gfx::Size& size, ...@@ -57,7 +61,7 @@ bool GLSurfaceEGLSurfaceControl::Resize(const gfx::Size& size,
float scale_factor, float scale_factor,
ColorSpace color_space, ColorSpace color_space,
bool has_alpha) { bool has_alpha) {
// Resizing requires resizing the SurfaceView in the browser. window_rect_ = gfx::Rect(0, 0, size.width(), size.height());
return true; return true;
} }
...@@ -71,31 +75,68 @@ gfx::SwapResult GLSurfaceEGLSurfaceControl::SwapBuffers( ...@@ -71,31 +75,68 @@ gfx::SwapResult GLSurfaceEGLSurfaceControl::SwapBuffers(
return gfx::SwapResult::SWAP_FAILED; return gfx::SwapResult::SWAP_FAILED;
} }
void GLSurfaceEGLSurfaceControl::SwapBuffersAsync( gfx::SwapResult GLSurfaceEGLSurfaceControl::CommitOverlayPlanes(
SwapCompletionCallback completion_callback, PresentationCallback callback) {
PresentationCallback presentation_callback) { NOTREACHED();
CommitPendingTransaction(std::move(completion_callback), return gfx::SwapResult::SWAP_FAILED;
std::move(presentation_callback));
} }
gfx::SwapResult GLSurfaceEGLSurfaceControl::CommitOverlayPlanes( gfx::SwapResult GLSurfaceEGLSurfaceControl::PostSubBuffer(
int x,
int y,
int width,
int height,
PresentationCallback callback) { PresentationCallback callback) {
NOTREACHED(); NOTREACHED();
return gfx::SwapResult::SWAP_FAILED; return gfx::SwapResult::SWAP_FAILED;
} }
void GLSurfaceEGLSurfaceControl::SwapBuffersAsync(
SwapCompletionCallback completion_callback,
PresentationCallback presentation_callback) {
CommitPendingTransaction(window_rect_, std::move(completion_callback),
std::move(presentation_callback));
}
void GLSurfaceEGLSurfaceControl::CommitOverlayPlanesAsync( void GLSurfaceEGLSurfaceControl::CommitOverlayPlanesAsync(
SwapCompletionCallback completion_callback, SwapCompletionCallback completion_callback,
PresentationCallback presentation_callback) { PresentationCallback presentation_callback) {
CommitPendingTransaction(std::move(completion_callback), CommitPendingTransaction(window_rect_, std::move(completion_callback),
std::move(presentation_callback));
}
void GLSurfaceEGLSurfaceControl::PostSubBufferAsync(
int x,
int y,
int width,
int height,
SwapCompletionCallback completion_callback,
PresentationCallback presentation_callback) {
CommitPendingTransaction(gfx::Rect(x, y, width, height),
std::move(completion_callback),
std::move(presentation_callback)); std::move(presentation_callback));
} }
void GLSurfaceEGLSurfaceControl::CommitPendingTransaction( void GLSurfaceEGLSurfaceControl::CommitPendingTransaction(
const gfx::Rect& damage_rect,
SwapCompletionCallback completion_callback, SwapCompletionCallback completion_callback,
PresentationCallback present_callback) { PresentationCallback present_callback) {
DCHECK(pending_transaction_); DCHECK(pending_transaction_);
// Mark the intersection of a surface's rect with the damage rect as the dirty
// rect for that surface.
DCHECK_LE(pending_surfaces_count_, surface_list_.size());
for (size_t i = 0; i < pending_surfaces_count_; ++i) {
const auto& surface_state = surface_list_[i];
if (!surface_state.buffer_updated_in_pending_transaction)
continue;
gfx::Rect surface_damage_rect = surface_state.dst;
surface_damage_rect.Intersect(damage_rect);
pending_transaction_->SetDamageRect(*surface_state.surface,
surface_damage_rect);
}
// Release resources for the current frame once the next frame is acked. // Release resources for the current frame once the next frame is acked.
ResourceRefs resources_to_release; ResourceRefs resources_to_release;
resources_to_release.swap(current_frame_resources_); resources_to_release.swap(current_frame_resources_);
...@@ -167,7 +208,9 @@ bool GLSurfaceEGLSurfaceControl::ScheduleOverlayPlane( ...@@ -167,7 +208,9 @@ bool GLSurfaceEGLSurfaceControl::ScheduleOverlayPlane(
resource_ref.scoped_buffer = std::move(scoped_hardware_buffer); resource_ref.scoped_buffer = std::move(scoped_hardware_buffer);
} }
if (uninitialized || surface_state.hardware_buffer != hardware_buffer) { surface_state.buffer_updated_in_pending_transaction =
uninitialized || surface_state.hardware_buffer != hardware_buffer;
if (surface_state.buffer_updated_in_pending_transaction) {
surface_state.hardware_buffer = hardware_buffer; surface_state.hardware_buffer = hardware_buffer;
if (!fence_fd.is_valid() && gpu_fence && surface_state.hardware_buffer) { if (!fence_fd.is_valid() && gpu_fence && surface_state.hardware_buffer) {
...@@ -220,6 +263,10 @@ void* GLSurfaceEGLSurfaceControl::GetHandle() { ...@@ -220,6 +263,10 @@ void* GLSurfaceEGLSurfaceControl::GetHandle() {
return nullptr; return nullptr;
} }
bool GLSurfaceEGLSurfaceControl::SupportsPostSubBuffer() {
return true;
}
bool GLSurfaceEGLSurfaceControl::SupportsAsyncSwap() { bool GLSurfaceEGLSurfaceControl::SupportsAsyncSwap() {
return true; return true;
} }
...@@ -232,11 +279,6 @@ bool GLSurfaceEGLSurfaceControl::SupportsPresentationCallback() { ...@@ -232,11 +279,6 @@ bool GLSurfaceEGLSurfaceControl::SupportsPresentationCallback() {
return true; return true;
} }
bool GLSurfaceEGLSurfaceControl::SupportsSwapBuffersWithBounds() {
// TODO(khushalsagar): Add support for partial swap.
return false;
}
bool GLSurfaceEGLSurfaceControl::SupportsCommitOverlayPlanes() { bool GLSurfaceEGLSurfaceControl::SupportsCommitOverlayPlanes() {
return true; return true;
} }
......
...@@ -41,13 +41,7 @@ class GL_EXPORT GLSurfaceEGLSurfaceControl : public GLSurfaceEGL { ...@@ -41,13 +41,7 @@ class GL_EXPORT GLSurfaceEGLSurfaceControl : public GLSurfaceEGL {
ColorSpace color_space, ColorSpace color_space,
bool has_alpha) override; bool has_alpha) override;
bool IsOffscreen() override; bool IsOffscreen() override;
gfx::SwapResult SwapBuffers(PresentationCallback callback) override;
void SwapBuffersAsync(SwapCompletionCallback completion_callback,
PresentationCallback presentation_callback) override;
gfx::SwapResult CommitOverlayPlanes(PresentationCallback callback) override;
void CommitOverlayPlanesAsync(
SwapCompletionCallback completion_callback,
PresentationCallback presentation_callback) override;
gfx::Size GetSize() override; gfx::Size GetSize() override;
bool OnMakeCurrent(GLContext* context) override; bool OnMakeCurrent(GLContext* context) override;
bool ScheduleOverlayPlane(int z_order, bool ScheduleOverlayPlane(int z_order,
...@@ -60,10 +54,31 @@ class GL_EXPORT GLSurfaceEGLSurfaceControl : public GLSurfaceEGL { ...@@ -60,10 +54,31 @@ class GL_EXPORT GLSurfaceEGLSurfaceControl : public GLSurfaceEGL {
bool IsSurfaceless() const override; bool IsSurfaceless() const override;
void* GetHandle() override; void* GetHandle() override;
// Sync versions of frame update, should never be used.
gfx::SwapResult SwapBuffers(PresentationCallback callback) override;
gfx::SwapResult CommitOverlayPlanes(PresentationCallback callback) override;
gfx::SwapResult PostSubBuffer(int x,
int y,
int width,
int height,
PresentationCallback callback) override;
void SwapBuffersAsync(SwapCompletionCallback completion_callback,
PresentationCallback presentation_callback) override;
void CommitOverlayPlanesAsync(
SwapCompletionCallback completion_callback,
PresentationCallback presentation_callback) override;
void PostSubBufferAsync(int x,
int y,
int width,
int height,
SwapCompletionCallback completion_callback,
PresentationCallback presentation_callback) override;
bool SupportsAsyncSwap() override; bool SupportsAsyncSwap() override;
bool SupportsPlaneGpuFences() const override; bool SupportsPlaneGpuFences() const override;
bool SupportsPresentationCallback() override; bool SupportsPresentationCallback() override;
bool SupportsSwapBuffersWithBounds() override; bool SupportsPostSubBuffer() override;
bool SupportsCommitOverlayPlanes() override; bool SupportsCommitOverlayPlanes() override;
private: private:
...@@ -84,6 +99,11 @@ class GL_EXPORT GLSurfaceEGLSurfaceControl : public GLSurfaceEGL { ...@@ -84,6 +99,11 @@ class GL_EXPORT GLSurfaceEGLSurfaceControl : public GLSurfaceEGL {
gfx::OverlayTransform transform = gfx::OVERLAY_TRANSFORM_NONE; gfx::OverlayTransform transform = gfx::OVERLAY_TRANSFORM_NONE;
bool opaque = true; bool opaque = true;
// Indicates whether buffer for this layer was updated in the currently
// pending transaction, or the last transaction submitted if there isn't
// one pending.
bool buffer_updated_in_pending_transaction = true;
scoped_refptr<SurfaceControl::Surface> surface; scoped_refptr<SurfaceControl::Surface> surface;
}; };
...@@ -99,7 +119,8 @@ class GL_EXPORT GLSurfaceEGLSurfaceControl : public GLSurfaceEGL { ...@@ -99,7 +119,8 @@ class GL_EXPORT GLSurfaceEGLSurfaceControl : public GLSurfaceEGL {
}; };
using ResourceRefs = base::flat_map<ASurfaceControl*, ResourceRef>; using ResourceRefs = base::flat_map<ASurfaceControl*, ResourceRef>;
void CommitPendingTransaction(SwapCompletionCallback completion_callback, void CommitPendingTransaction(const gfx::Rect& damage_rect,
SwapCompletionCallback completion_callback,
PresentationCallback callback); PresentationCallback callback);
// Called on the |gpu_task_runner_| when a transaction is acked by the // Called on the |gpu_task_runner_| when a transaction is acked by the
...@@ -110,6 +131,9 @@ class GL_EXPORT GLSurfaceEGLSurfaceControl : public GLSurfaceEGL { ...@@ -110,6 +131,9 @@ class GL_EXPORT GLSurfaceEGLSurfaceControl : public GLSurfaceEGL {
ResourceRefs released_resources, ResourceRefs released_resources,
SurfaceControl::TransactionStats transaction_stats); SurfaceControl::TransactionStats transaction_stats);
// The rect of the native window backing this surface.
gfx::Rect window_rect_;
// Holds the surface state changes made since the last call to SwapBuffers. // Holds the surface state changes made since the last call to SwapBuffers.
base::Optional<SurfaceControl::Transaction> pending_transaction_; base::Optional<SurfaceControl::Transaction> pending_transaction_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment