Skip to content

Commit

Permalink
Overlay promotion on android is tricky, in that one must know in
Browse files Browse the repository at this point in the history
advance whether to use a SurfaceView for the overlay or not.  If the
overlay turns out to be skipped for promotion by chrome's overlay
processor, then it simply won't be visible.

This CL adds functionality for a resource to request a hint about
whether it would be promoted or not, even though it's not backed by
a SurfaceView.  This allows the producer of the resource to decide
whether SurfaceView is appropriate or not.

Initial use case will be AndroidVideoDecodeAccelerator, which likes
to promote to SV as much as possible for power savings.

BUG=671354
CQ_INCLUDE_TRYBOTS=master.tryserver.blink:linux_trusty_blink_rel

Review-Url: https://codereview.chromium.org/2508203004
Cr-Commit-Position: refs/heads/master@{#437643}
  • Loading branch information
liberato-at-chromium authored and Commit bot committed Dec 9, 2016
1 parent 0a0648a commit 304dc19
Show file tree
Hide file tree
Showing 29 changed files with 503 additions and 53 deletions.
2 changes: 2 additions & 0 deletions cc/base/resource_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
#define CC_BASE_RESOURCE_ID_H_

#include <stdint.h>
#include <unordered_set>

namespace cc {

using ResourceId = uint32_t;
using ResourceIdSet = std::unordered_set<ResourceId>;

} // namespace cc

Expand Down
4 changes: 4 additions & 0 deletions cc/ipc/cc_param_traits_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ IPC_STRUCT_TRAITS_BEGIN(cc::TransferableResource)
IPC_STRUCT_TRAITS_MEMBER(is_software)
IPC_STRUCT_TRAITS_MEMBER(is_overlay_candidate)
IPC_STRUCT_TRAITS_MEMBER(color_space)
#if defined(OS_ANDROID)
IPC_STRUCT_TRAITS_MEMBER(is_backed_by_surface_texture)
IPC_STRUCT_TRAITS_MEMBER(wants_promotion_hint)
#endif
IPC_STRUCT_TRAITS_END()

IPC_STRUCT_TRAITS_BEGIN(cc::ReturnedResource)
Expand Down
12 changes: 12 additions & 0 deletions cc/ipc/cc_param_traits_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ class CCParamTraitsTest : public testing::Test {
EXPECT_EQ(a.mailbox_holder.texture_target, b.mailbox_holder.texture_target);
EXPECT_EQ(a.mailbox_holder.sync_token, b.mailbox_holder.sync_token);
EXPECT_EQ(a.is_overlay_candidate, b.is_overlay_candidate);
#if defined(OS_ANDROID)
EXPECT_EQ(a.is_backed_by_surface_texture, b.is_backed_by_surface_texture);
EXPECT_EQ(a.wants_promotion_hint, b.wants_promotion_hint);
#endif
}
};

Expand Down Expand Up @@ -569,6 +573,10 @@ TEST_F(CCParamTraitsTest, Resources) {
arbitrary_resource1.mailbox_holder.texture_target = GL_TEXTURE_2D;
arbitrary_resource1.mailbox_holder.sync_token = arbitrary_token1;
arbitrary_resource1.is_overlay_candidate = true;
#if defined(OS_ANDROID)
arbitrary_resource1.is_backed_by_surface_texture = true;
arbitrary_resource1.wants_promotion_hint = true;
#endif

TransferableResource arbitrary_resource2;
arbitrary_resource2.id = 789132;
Expand All @@ -579,6 +587,10 @@ TEST_F(CCParamTraitsTest, Resources) {
arbitrary_resource2.mailbox_holder.texture_target = GL_TEXTURE_EXTERNAL_OES;
arbitrary_resource2.mailbox_holder.sync_token = arbitrary_token2;
arbitrary_resource2.is_overlay_candidate = false;
#if defined(OS_ANDROID)
arbitrary_resource2.is_backed_by_surface_texture = false;
arbitrary_resource2.wants_promotion_hint = false;
#endif

std::unique_ptr<RenderPass> renderpass_in = RenderPass::Create();
renderpass_in->SetNew(1, gfx::Rect(), gfx::Rect(), gfx::Transform());
Expand Down
2 changes: 2 additions & 0 deletions cc/ipc/transferable_resource.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ struct TransferableResource {
bool read_lock_fences_enabled;
bool is_software;
bool is_overlay_candidate;
bool is_backed_by_surface_texture;
bool wants_promotion_hint;
};
4 changes: 4 additions & 0 deletions cc/ipc/transferable_resource_struct_traits.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ bool StructTraits<cc::mojom::TransferableResourceDataView,
out->read_lock_fences_enabled = data.read_lock_fences_enabled();
out->is_software = data.is_software();
out->is_overlay_candidate = data.is_overlay_candidate();
#if defined(OS_ANDROID)
out->is_backed_by_surface_texture = data.is_backed_by_surface_texture();
out->wants_promotion_hint = data.wants_promotion_hint();
#endif
return true;
}

Expand Down
21 changes: 21 additions & 0 deletions cc/ipc/transferable_resource_struct_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,27 @@ struct StructTraits<cc::mojom::TransferableResourceDataView,
return resource.is_overlay_candidate;
}

static bool is_backed_by_surface_texture(
const cc::TransferableResource& resource) {
#if defined(OS_ANDROID)
// TransferableResource has this in an #ifdef, but mojo doesn't let us.
// TODO(https://crbug.com/671901)
return resource.is_backed_by_surface_texture;
#else
return false;
#endif
}

static bool wants_promotion_hint(const cc::TransferableResource& resource) {
#if defined(OS_ANDROID)
// TransferableResource has this in an #ifdef, but mojo doesn't let us.
// TODO(https://crbug.com/671901)
return resource.wants_promotion_hint;
#else
return false;
#endif
}

static bool Read(cc::mojom::TransferableResourceDataView data,
cc::TransferableResource* out);
};
Expand Down
27 changes: 26 additions & 1 deletion cc/output/overlay_candidate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,14 @@ OverlayCandidate::OverlayCandidate()
is_clipped(false),
use_output_surface_for_resource(false),
resource_id(0),
#if defined(OS_ANDROID)
is_backed_by_surface_texture(false),
is_promotable_hint(false),
#endif
plane_z_order(0),
is_unoccluded(false),
overlay_handled(false) {}
overlay_handled(false) {
}

OverlayCandidate::OverlayCandidate(const OverlayCandidate& other) = default;

Expand Down Expand Up @@ -282,6 +287,10 @@ bool OverlayCandidate::FromStreamVideoQuad(ResourceProvider* resource_provider,
candidate->resource_id = quad->resource_id();
candidate->resource_size_in_pixels = quad->resource_size_in_pixels();
candidate->transform = overlay_transform;
#if defined(OS_ANDROID)
candidate->is_backed_by_surface_texture =
resource_provider->IsBackedBySurfaceTexture(quad->resource_id());
#endif

gfx::Point3F uv0 = gfx::Point3F(0, 0, 0);
gfx::Point3F uv1 = gfx::Point3F(1, 1, 0);
Expand Down Expand Up @@ -310,4 +319,20 @@ bool OverlayCandidate::FromStreamVideoQuad(ResourceProvider* resource_provider,
return true;
}

OverlayCandidateList::OverlayCandidateList() {}

OverlayCandidateList::OverlayCandidateList(const OverlayCandidateList& other) =
default;

OverlayCandidateList::OverlayCandidateList(OverlayCandidateList&& other) =
default;

OverlayCandidateList::~OverlayCandidateList() {}

OverlayCandidateList& OverlayCandidateList::operator=(
const OverlayCandidateList& other) = default;

OverlayCandidateList& OverlayCandidateList::operator=(
OverlayCandidateList&& other) = default;

} // namespace cc
28 changes: 27 additions & 1 deletion cc/output/overlay_candidate.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <vector>

#include "cc/base/cc_export.h"
#include "cc/base/resource_id.h"
#include "cc/quads/render_pass.h"
#include "cc/resources/resource_format.h"
#include "ui/gfx/geometry/rect.h"
Expand Down Expand Up @@ -70,6 +71,18 @@ class CC_EXPORT OverlayCandidate {
bool use_output_surface_for_resource;
// Texture resource to present in an overlay.
unsigned resource_id;

#if defined(OS_ANDROID)
// For candidates from StreamVideoDrawQuads, this records whether the quad is
// marked as being backed by a SurfaceTexture or not. If so, it's not really
// promotable to an overlay.
bool is_backed_by_surface_texture;

// Filled in by the OverlayCandidateValidator to indicate whether this is a
// promotable candidate or not.
bool is_promotable_hint;
#endif

// Stacking order of the overlay plane relative to the main surface,
// which is 0. Signed to allow for "underlays".
int plane_z_order;
Expand All @@ -91,7 +104,20 @@ class CC_EXPORT OverlayCandidate {
OverlayCandidate* candidate);
};

typedef std::vector<OverlayCandidate> OverlayCandidateList;
class CC_EXPORT OverlayCandidateList : public std::vector<OverlayCandidate> {
public:
OverlayCandidateList();
OverlayCandidateList(const OverlayCandidateList&);
OverlayCandidateList(OverlayCandidateList&&);
~OverlayCandidateList();

OverlayCandidateList& operator=(const OverlayCandidateList&);
OverlayCandidateList& operator=(OverlayCandidateList&&);

// For android, this provides a set of resources that could be promoted to
// overlay, if one backs them with a SurfaceView.
ResourceIdSet promotable_resource_hints_;
};

} // namespace cc

Expand Down
33 changes: 33 additions & 0 deletions cc/output/overlay_processor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,35 @@
#include "cc/output/overlay_strategy_single_on_top.h"
#include "cc/output/overlay_strategy_underlay.h"
#include "cc/quads/draw_quad.h"
#include "cc/resources/resource_provider.h"
#include "ui/gfx/geometry/rect_conversions.h"
#include "ui/gfx/transform.h"

namespace {

#if defined(OS_ANDROID)
// Utility class to make sure that we notify resource that they're promotable
// before returning from ProcessForOverlays.
class SendPromotionHintsBeforeReturning {
public:
SendPromotionHintsBeforeReturning(cc::ResourceProvider* resource_provider,
cc::OverlayCandidateList* candidates)
: resource_provider_(resource_provider), candidates_(candidates) {}
~SendPromotionHintsBeforeReturning() {
resource_provider_->SendPromotionHints(
candidates_->promotable_resource_hints_);
}

private:
cc::ResourceProvider* resource_provider_;
cc::OverlayCandidateList* candidates_;

DISALLOW_COPY_AND_ASSIGN(SendPromotionHintsBeforeReturning);
};
#endif

} // namespace

namespace cc {

OverlayProcessor::OverlayProcessor(OutputSurface* surface) : surface_(surface) {
Expand Down Expand Up @@ -62,6 +88,13 @@ void OverlayProcessor::ProcessForOverlays(ResourceProvider* resource_provider,
OverlayCandidateList* candidates,
CALayerOverlayList* ca_layer_overlays,
gfx::Rect* damage_rect) {
#if defined(OS_ANDROID)
// Be sure to send out notifications, regardless of whether we get to
// processing for overlays or not. If we don't, then we should notify that
// they are not promotable.
SendPromotionHintsBeforeReturning notifier(resource_provider, candidates);
#endif

// If we have any copy requests, we can't remove any quads for overlays or
// CALayers because the framebuffer would be missing the removed quads'
// contents.
Expand Down
12 changes: 12 additions & 0 deletions cc/output/overlay_strategy_underlay.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,19 @@ bool OverlayStrategyUnderlay::Attempt(ResourceProvider* resource_provider,
replacement->SetAll(shared_quad_state, rect, rect, rect, false,
SK_ColorTRANSPARENT, true);
candidate_list->swap(new_candidate_list);

// This quad will be promoted. We clear the promotable hints here, since
// we can only promote a single quad. Otherwise, somebody might try to
// back one of the promotable quads with a SurfaceView, and either it or
// |candidate| would have to fall back to a texture.
candidate_list->promotable_resource_hints_.clear();
candidate_list->promotable_resource_hints_.insert(candidate.resource_id);
return true;
} else {
// If |candidate| should get a promotion hint, then rememeber that now.
candidate_list->promotable_resource_hints_.insert(
new_candidate_list.promotable_resource_hints_.begin(),
new_candidate_list.promotable_resource_hints_.end());
}
}

Expand Down
Loading

0 comments on commit 304dc19

Please sign in to comment.