Commit 7b1edda6 authored by boliu's avatar boliu Committed by Commit bot

aw: Refactor to move FrameFuture into ChildFrame

Instead of have the parallel FrameFuture be held in RenderThreadManager
and have the logic for waiting on the frame split between different
places.

BUG=662096

Review-Url: https://codereview.chromium.org/2481573002
Cr-Commit-Position: refs/heads/master@{#430309}
parent a0da430a
......@@ -252,14 +252,14 @@ bool BrowserViewRenderer::OnDrawHardware() {
allow_async_draw_ = true;
std::unique_ptr<ChildFrame> child_frame = base::MakeUnique<ChildFrame>(
frame.compositor_frame_sink_id, std::move(frame.frame), compositor_id_,
viewport_rect_for_tile_priority.IsEmpty(), transform_for_tile_priority,
offscreen_pre_raster_, external_draw_constraints_.is_layer);
std::move(future), frame.compositor_frame_sink_id, std::move(frame.frame),
compositor_id_, viewport_rect_for_tile_priority.IsEmpty(),
transform_for_tile_priority, offscreen_pre_raster_,
external_draw_constraints_.is_layer);
ReturnUnusedResource(
current_compositor_frame_consumer_->PassUncommittedFrameOnUI());
current_compositor_frame_consumer_->SetFrameOnUI(std::move(child_frame),
std::move(future));
current_compositor_frame_consumer_->SetFrameOnUI(std::move(child_frame));
return true;
}
......
......@@ -4,18 +4,24 @@
#include "android_webview/browser/child_frame.h"
#include <utility>
#include "base/trace_event/trace_event.h"
#include "cc/output/compositor_frame.h"
namespace android_webview {
ChildFrame::ChildFrame(uint32_t compositor_frame_sink_id,
std::unique_ptr<cc::CompositorFrame> frame,
const CompositorID& compositor_id,
bool viewport_rect_for_tile_priority_empty,
const gfx::Transform& transform_for_tile_priority,
bool offscreen_pre_raster,
bool is_layer)
: compositor_frame_sink_id(compositor_frame_sink_id),
ChildFrame::ChildFrame(
scoped_refptr<content::SynchronousCompositor::FrameFuture> frame_future,
uint32_t compositor_frame_sink_id,
std::unique_ptr<cc::CompositorFrame> frame,
const CompositorID& compositor_id,
bool viewport_rect_for_tile_priority_empty,
const gfx::Transform& transform_for_tile_priority,
bool offscreen_pre_raster,
bool is_layer)
: frame_future(std::move(frame_future)),
compositor_frame_sink_id(compositor_frame_sink_id),
frame(std::move(frame)),
compositor_id(compositor_id),
viewport_rect_for_tile_priority_empty(
......@@ -27,4 +33,18 @@ ChildFrame::ChildFrame(uint32_t compositor_frame_sink_id,
ChildFrame::~ChildFrame() {
}
void ChildFrame::WaitOnFutureIfNeeded() {
if (!frame_future)
return;
TRACE_EVENT0("android_webview", "GetFrame");
DCHECK(!frame);
auto frame_ptr = frame_future->GetFrame();
if (frame_ptr) {
compositor_frame_sink_id = frame_ptr->compositor_frame_sink_id;
frame = std::move(frame_ptr->frame);
}
frame_future = nullptr;
}
} // namespace webview
......@@ -9,6 +9,7 @@
#include "android_webview/browser/compositor_id.h"
#include "base/macros.h"
#include "content/public/browser/android/synchronous_compositor.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/transform.h"
......@@ -21,15 +22,23 @@ namespace android_webview {
class ChildFrame {
public:
ChildFrame(uint32_t compositor_frame_sink_id,
std::unique_ptr<cc::CompositorFrame> frame,
const CompositorID& compositor_id,
bool viewport_rect_for_tile_priority_empty,
const gfx::Transform& transform_for_tile_priority,
bool offscreen_pre_raster,
bool is_layer);
ChildFrame(
scoped_refptr<content::SynchronousCompositor::FrameFuture> frame_future,
uint32_t compositor_frame_sink_id,
std::unique_ptr<cc::CompositorFrame> frame,
const CompositorID& compositor_id,
bool viewport_rect_for_tile_priority_empty,
const gfx::Transform& transform_for_tile_priority,
bool offscreen_pre_raster,
bool is_layer);
~ChildFrame();
// Helper to move frame from |frame_future| to |frame|.
void WaitOnFutureIfNeeded();
// This is used in async ondraw path. The frame is either in |frame_future|
// or |frame|. It's illegal if both are non-null.
scoped_refptr<content::SynchronousCompositor::FrameFuture> frame_future;
// These two fields are not const to make async path easier.
uint32_t compositor_frame_sink_id;
std::unique_ptr<cc::CompositorFrame> frame;
......
......@@ -40,10 +40,7 @@ class CompositorFrameConsumer {
virtual void SetCompositorFrameProducer(
CompositorFrameProducer* compositor_frame_producer) = 0;
virtual void SetScrollOffsetOnUI(gfx::Vector2d scroll_offset) = 0;
virtual void SetFrameOnUI(
std::unique_ptr<ChildFrame> frame,
const scoped_refptr<content::SynchronousCompositor::FrameFuture>&
frame_future) = 0;
virtual void SetFrameOnUI(std::unique_ptr<ChildFrame> frame);
virtual void InitializeHardwareDrawIfNeededOnUI() = 0;
virtual ParentCompositorDrawConstraints GetParentDrawConstraintsOnUI()
const = 0;
......
......@@ -62,30 +62,14 @@ void HardwareRenderer::CommitFrame() {
if (!child_frame.get())
return;
ReturnResourcesInChildFrame();
frame_future_ = render_thread_manager_->PassFrameFutureOnRT();
child_frame_ = std::move(child_frame);
}
void HardwareRenderer::DrawGL(AwDrawGLInfo* draw_info) {
TRACE_EVENT0("android_webview", "HardwareRenderer::DrawGL");
if (frame_future_) {
TRACE_EVENT0("android_webview", "GetFrame");
DCHECK(child_frame_);
DCHECK(!child_frame_->frame);
std::unique_ptr<content::SynchronousCompositor::Frame> frame =
frame_future_->GetFrame();
if (frame) {
child_frame_->compositor_frame_sink_id = frame->compositor_frame_sink_id;
child_frame_->frame = std::move(frame->frame);
} else {
child_frame_.reset();
}
frame_future_ = nullptr;
}
if (child_frame_) {
child_frame_->WaitOnFutureIfNeeded();
last_committed_compositor_frame_sink_id_ =
child_frame_->compositor_frame_sink_id;
}
......
......@@ -13,7 +13,6 @@
#include "cc/surfaces/frame_sink_id.h"
#include "cc/surfaces/surface_factory_client.h"
#include "cc/surfaces/surface_id.h"
#include "content/public/browser/android/synchronous_compositor.h"
struct AwDrawGLInfo;
......@@ -67,8 +66,6 @@ class HardwareRenderer : public cc::SurfaceFactoryClient {
// SurfaceFactory.
std::unique_ptr<ChildFrame> child_frame_;
scoped_refptr<content::SynchronousCompositor::FrameFuture> frame_future_;
const scoped_refptr<SurfacesInstance> surfaces_;
cc::FrameSinkId frame_sink_id_;
const std::unique_ptr<cc::SurfaceIdAllocator> surface_id_allocator_;
......
......@@ -180,32 +180,10 @@ gfx::Vector2d RenderThreadManager::GetScrollOffsetOnRT() {
return scroll_offset_;
}
void RenderThreadManager::SetFrameOnUI(
std::unique_ptr<ChildFrame> frame,
const scoped_refptr<content::SynchronousCompositor::FrameFuture>&
frame_future) {
void RenderThreadManager::SetFrameOnUI(std::unique_ptr<ChildFrame> frame) {
base::AutoLock lock(lock_);
DCHECK(!child_frame_.get());
child_frame_ = std::move(frame);
frame_future_ = std::move(frame_future);
}
std::unique_ptr<ChildFrame> RenderThreadManager::GetSynchronousCompositorFrame(
scoped_refptr<content::SynchronousCompositor::FrameFuture> frame_future,
std::unique_ptr<ChildFrame> child_frame) {
if (!frame_future)
return nullptr;
DCHECK(!child_frame->frame.get());
std::unique_ptr<content::SynchronousCompositor::Frame> frame =
frame_future->GetFrame();
std::unique_ptr<cc::CompositorFrame> compositor_frame =
std::move(frame->frame);
return base::MakeUnique<ChildFrame>(
frame->compositor_frame_sink_id, std::move(compositor_frame),
child_frame->compositor_id,
child_frame->viewport_rect_for_tile_priority_empty,
child_frame->transform_for_tile_priority,
child_frame->offscreen_pre_raster, child_frame->is_layer);
}
std::unique_ptr<ChildFrame> RenderThreadManager::PassFrameOnRT() {
......@@ -215,18 +193,10 @@ std::unique_ptr<ChildFrame> RenderThreadManager::PassFrameOnRT() {
return std::move(child_frame_);
}
scoped_refptr<content::SynchronousCompositor::FrameFuture>
RenderThreadManager::PassFrameFutureOnRT() {
base::AutoLock lock(lock_);
return std::move(frame_future_);
}
std::unique_ptr<ChildFrame> RenderThreadManager::PassUncommittedFrameOnUI() {
base::AutoLock lock(lock_);
if (async_on_draw_hardware_ && child_frame_.get()) {
return GetSynchronousCompositorFrame(std::move(frame_future_),
std::move(child_frame_));
}
if (child_frame_)
child_frame_->WaitOnFutureIfNeeded();
return std::move(child_frame_);
}
......
......@@ -47,10 +47,7 @@ class RenderThreadManager : public CompositorFrameConsumer {
void SetCompositorFrameProducer(
CompositorFrameProducer* compositor_frame_producer) override;
void SetScrollOffsetOnUI(gfx::Vector2d scroll_offset) override;
void SetFrameOnUI(
std::unique_ptr<ChildFrame> frame,
const scoped_refptr<content::SynchronousCompositor::FrameFuture>&
frame_future) override;
void SetFrameOnUI(std::unique_ptr<ChildFrame> frame) override;
void InitializeHardwareDrawIfNeededOnUI() override;
ParentCompositorDrawConstraints GetParentDrawConstraintsOnUI() const override;
void SwapReturnedResourcesOnUI(
......@@ -63,8 +60,6 @@ class RenderThreadManager : public CompositorFrameConsumer {
// Render thread methods.
gfx::Vector2d GetScrollOffsetOnRT();
std::unique_ptr<ChildFrame> PassFrameOnRT();
scoped_refptr<content::SynchronousCompositor::FrameFuture>
PassFrameFutureOnRT();
void DrawGL(AwDrawGLInfo* draw_info);
void PostExternalDrawConstraintsToChildCompositorOnRT(
const ParentCompositorDrawConstraints& parent_draw_constraints);
......@@ -117,7 +112,6 @@ class RenderThreadManager : public CompositorFrameConsumer {
gfx::Vector2d scroll_offset_;
std::unique_ptr<ChildFrame> child_frame_;
const bool async_on_draw_hardware_;
scoped_refptr<content::SynchronousCompositor::FrameFuture> frame_future_;
bool inside_hardware_release_;
ParentCompositorDrawConstraints parent_draw_constraints_;
ReturnedResourcesMap returned_resources_map_;
......
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