Skip to content

Commit

Permalink
cc: Rework overlays to not use the ResourceProvider and pass texture …
Browse files Browse the repository at this point in the history
…size

Instead of querying the ResourceProvider, the size & overlay flag are
stored in the quads directly. This eliminates the lookups that were
otherwise required
CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel
TBR=jam (approved interface change)

Review URL: https://codereview.chromium.org/1142343008

Cr-Commit-Position: refs/heads/master@{#333748}
  • Loading branch information
achaulk authored and Commit bot committed Jun 10, 2015
1 parent 20a7d9f commit f89f594
Show file tree
Hide file tree
Showing 36 changed files with 351 additions and 261 deletions.
6 changes: 3 additions & 3 deletions cc/blink/web_external_texture_layer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ bool WebExternalTextureLayerImpl::PrepareTextureMailbox(
if (bitmap) {
*mailbox = cc::TextureMailbox(bitmap->shared_bitmap(), bitmap->size());
} else {
*mailbox =
cc::TextureMailbox(name, GL_TEXTURE_2D, client_mailbox.syncPoint);
// TODO(achaulk): pass a valid size here if allowOverlay is set.
*mailbox = cc::TextureMailbox(name, GL_TEXTURE_2D, client_mailbox.syncPoint,
gfx::Size(), client_mailbox.allowOverlay);
}
mailbox->set_allow_overlay(client_mailbox.allowOverlay);
mailbox->set_nearest_neighbor(client_mailbox.nearestNeighbor);

if (mailbox->IsValid()) {
Expand Down
18 changes: 10 additions & 8 deletions cc/layers/texture_layer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ bool TextureLayerImpl::WillDraw(DrawMode draw_mode,
// hardware draw.
if (!texture_copy_)
texture_copy_ = ScopedResource::Create(resource_provider);
if (texture_copy_->size() != texture_mailbox_.shared_memory_size() ||
if (texture_copy_->size() != texture_mailbox_.size_in_pixels() ||
resource_provider->InUseByConsumer(texture_copy_->id()))
texture_copy_->Free();

if (!texture_copy_->id()) {
texture_copy_->Allocate(texture_mailbox_.shared_memory_size(),
texture_copy_->Allocate(texture_mailbox_.size_in_pixels(),
ResourceProvider::TEXTURE_HINT_IMMUTABLE,
resource_provider->best_texture_format());
}
Expand All @@ -126,12 +126,10 @@ bool TextureLayerImpl::WillDraw(DrawMode draw_mode,
pixels = &swizzled[0];
}

resource_provider->SetPixels(
texture_copy_->id(),
pixels,
gfx::Rect(texture_mailbox_.shared_memory_size()),
gfx::Rect(texture_mailbox_.shared_memory_size()),
gfx::Vector2d());
resource_provider->SetPixels(texture_copy_->id(), pixels,
gfx::Rect(texture_mailbox_.size_in_pixels()),
gfx::Rect(texture_mailbox_.size_in_pixels()),
gfx::Vector2d());

valid_texture_copy_ = true;
}
Expand Down Expand Up @@ -179,6 +177,10 @@ void TextureLayerImpl::AppendQuads(RenderPass* render_pass,
vertex_opacity_,
flipped_,
nearest_neighbor_);
if (!valid_texture_copy_) {
quad->set_resource_size_in_pixels(texture_mailbox_.size_in_pixels());
quad->set_allow_overlay(texture_mailbox_.allow_overlay());
}
ValidateQuadResources(quad);
}

Expand Down
39 changes: 17 additions & 22 deletions cc/layers/video_layer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ bool VideoLayerImpl::WillDraw(DrawMode draw_mode,
external_resources.mailboxes[i],
SingleReleaseCallbackImpl::Create(
external_resources.release_callbacks[i]));
frame_resources_.push_back(resource_id);
frame_resources_.push_back(FrameResource(
resource_id, external_resources.mailboxes[i].size_in_pixels(),
external_resources.mailboxes[i].allow_overlay()));
}

return true;
Expand Down Expand Up @@ -271,8 +273,10 @@ void VideoLayerImpl::AppendQuads(RenderPass* render_pass,
yuv_video_quad->SetNew(
shared_quad_state, quad_rect, opaque_rect, visible_quad_rect,
ya_tex_coord_rect, uv_tex_coord_rect, ya_tex_size, uv_tex_size,
frame_resources_[0], frame_resources_[1], frame_resources_[2],
frame_resources_.size() > 3 ? frame_resources_[3] : 0, color_space);
frame_resources_[0].id, frame_resources_[1].id,
frame_resources_[2].id,
frame_resources_.size() > 3 ? frame_resources_[3].id : 0,
color_space);
ValidateQuadResources(yuv_video_quad);
break;
}
Expand All @@ -290,17 +294,10 @@ void VideoLayerImpl::AppendQuads(RenderPass* render_pass,
bool nearest_neighbor = false;
TextureDrawQuad* texture_quad =
render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>();
texture_quad->SetNew(shared_quad_state,
quad_rect,
opaque_rect,
visible_quad_rect,
frame_resources_[0],
premultiplied_alpha,
uv_top_left,
uv_bottom_right,
SK_ColorTRANSPARENT,
opacity,
flipped,
texture_quad->SetNew(shared_quad_state, quad_rect, opaque_rect,
visible_quad_rect, frame_resources_[0].id,
premultiplied_alpha, uv_top_left, uv_bottom_right,
SK_ColorTRANSPARENT, opacity, flipped,
nearest_neighbor);
ValidateQuadResources(texture_quad);
break;
Expand All @@ -315,7 +312,8 @@ void VideoLayerImpl::AppendQuads(RenderPass* render_pass,
render_pass->CreateAndAppendDrawQuad<StreamVideoDrawQuad>();
stream_video_quad->SetNew(
shared_quad_state, quad_rect, opaque_rect, visible_quad_rect,
frame_resources_[0],
frame_resources_[0].id, frame_resources_[0].size_in_pixels,
frame_resources_[0].allow_overlay,
scale * provider_client_impl_->StreamTextureMatrix());
ValidateQuadResources(stream_video_quad);
break;
Expand All @@ -326,12 +324,9 @@ void VideoLayerImpl::AppendQuads(RenderPass* render_pass,
break;
IOSurfaceDrawQuad* io_surface_quad =
render_pass->CreateAndAppendDrawQuad<IOSurfaceDrawQuad>();
io_surface_quad->SetNew(shared_quad_state,
quad_rect,
opaque_rect,
visible_quad_rect,
visible_rect.size(),
frame_resources_[0],
io_surface_quad->SetNew(shared_quad_state, quad_rect, opaque_rect,
visible_quad_rect, visible_rect.size(),
frame_resources_[0].id,
IOSurfaceDrawQuad::UNFLIPPED);
ValidateQuadResources(io_surface_quad);
break;
Expand Down Expand Up @@ -383,7 +378,7 @@ void VideoLayerImpl::DidDraw(ResourceProvider* resource_provider) {
software_release_callback_.Reset();
} else {
for (size_t i = 0; i < frame_resources_.size(); ++i)
resource_provider->DeleteResource(frame_resources_[i]);
resource_provider->DeleteResource(frame_resources_[i].id);
frame_resources_.clear();
}

Expand Down
11 changes: 10 additions & 1 deletion cc/layers/video_layer_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,16 @@ class CC_EXPORT VideoLayerImpl : public LayerImpl {

scoped_ptr<VideoResourceUpdater> updater_;
VideoFrameExternalResources::ResourceType frame_resource_type_;
std::vector<ResourceId> frame_resources_;
struct FrameResource {
FrameResource(ResourceId id, gfx::Size size_in_pixels, bool allow_overlay)
: id(id),
size_in_pixels(size_in_pixels),
allow_overlay(allow_overlay) {}
ResourceId id;
gfx::Size size_in_pixels;
bool allow_overlay;
};
std::vector<FrameResource> frame_resources_;

// TODO(danakj): Remove these, hide software path inside ResourceProvider and
// ExternalResource (aka TextureMailbox) classes.
Expand Down
3 changes: 1 addition & 2 deletions cc/output/direct_renderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ DirectRenderer::DirectRenderer(RendererClient* client,
: Renderer(client, settings),
output_surface_(output_surface),
resource_provider_(resource_provider),
overlay_processor_(
new OverlayProcessor(output_surface, resource_provider)) {
overlay_processor_(new OverlayProcessor(output_surface)) {
overlay_processor_->Initialize();
}

Expand Down
24 changes: 11 additions & 13 deletions cc/output/gl_renderer_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2029,9 +2029,8 @@ class TestOverlayProcessor : public OverlayProcessor {
OverlayCandidateList* candidates));
};

TestOverlayProcessor(OutputSurface* surface,
ResourceProvider* resource_provider)
: OverlayProcessor(surface, resource_provider) {}
explicit TestOverlayProcessor(OutputSurface* surface)
: OverlayProcessor(surface) {}
~TestOverlayProcessor() override {}
void Initialize() override {
strategy_ = new Strategy();
Expand Down Expand Up @@ -2069,7 +2068,7 @@ TEST_F(GLRendererTest, DontOverlayWithCopyRequests) {
resource_provider.get(), mailbox_deleter.get());

TestOverlayProcessor* processor =
new TestOverlayProcessor(output_surface.get(), resource_provider.get());
new TestOverlayProcessor(output_surface.get());
processor->Initialize();
renderer.SetOverlayProcessor(processor);

Expand All @@ -2084,7 +2083,6 @@ TEST_F(GLRendererTest, DontOverlayWithCopyRequests) {
unsigned sync_point = 0;
TextureMailbox mailbox =
TextureMailbox(gpu::Mailbox::Generate(), GL_TEXTURE_2D, sync_point);
mailbox.set_allow_overlay(true);
scoped_ptr<SingleReleaseCallbackImpl> release_callback =
SingleReleaseCallbackImpl::Create(base::Bind(&MailboxReleased));
ResourceId resource_id = resource_provider->CreateResourceFromTextureMailbox(
Expand All @@ -2101,6 +2099,7 @@ TEST_F(GLRendererTest, DontOverlayWithCopyRequests) {
premultiplied_alpha, gfx::PointF(0, 0),
gfx::PointF(1, 1), SK_ColorTRANSPARENT, vertex_opacity,
flipped, nearest_neighbor);
overlay_quad->set_allow_overlay(true);

// DirectRenderer::DrawFrame calls into OverlayProcessor::ProcessForOverlays.
// Attempt will be called for each strategy in OverlayProcessor. We have
Expand Down Expand Up @@ -2140,13 +2139,12 @@ class SingleOverlayOnTopProcessor : public OverlayProcessor {
}
};

SingleOverlayOnTopProcessor(OutputSurface* surface,
ResourceProvider* resource_provider)
: OverlayProcessor(surface, resource_provider) {}
explicit SingleOverlayOnTopProcessor(OutputSurface* surface)
: OverlayProcessor(surface) {}

void Initialize() override {
strategies_.push_back(scoped_ptr<Strategy>(
new OverlayStrategySingleOnTop(&validator_, resource_provider_)));
strategies_.push_back(
scoped_ptr<Strategy>(new OverlayStrategySingleOnTop(&validator_)));
}

SingleOverlayValidator validator_;
Expand Down Expand Up @@ -2195,8 +2193,8 @@ TEST_F(GLRendererTest, OverlaySyncPointsAreProcessed) {
FakeRendererGL renderer(&renderer_client, &settings, output_surface.get(),
resource_provider.get(), mailbox_deleter.get());

SingleOverlayOnTopProcessor* processor = new SingleOverlayOnTopProcessor(
output_surface.get(), resource_provider.get());
SingleOverlayOnTopProcessor* processor =
new SingleOverlayOnTopProcessor(output_surface.get());
processor->Initialize();
renderer.SetOverlayProcessor(processor);

Expand All @@ -2209,7 +2207,6 @@ TEST_F(GLRendererTest, OverlaySyncPointsAreProcessed) {
unsigned sync_point = TestRenderPass::kSyncPointForMailboxTextureQuad;
TextureMailbox mailbox =
TextureMailbox(gpu::Mailbox::Generate(), GL_TEXTURE_2D, sync_point);
mailbox.set_allow_overlay(true);
scoped_ptr<SingleReleaseCallbackImpl> release_callback =
SingleReleaseCallbackImpl::Create(base::Bind(&MailboxReleased));
ResourceId resource_id = resource_provider->CreateResourceFromTextureMailbox(
Expand All @@ -2230,6 +2227,7 @@ TEST_F(GLRendererTest, OverlaySyncPointsAreProcessed) {
viewport_rect, resource_id, premultiplied_alpha,
uv_top_left, uv_bottom_right, SK_ColorTRANSPARENT,
vertex_opacity, flipped, nearest_neighbor);
overlay_quad->set_allow_overlay(true);

// Verify that overlay_quad actually gets turned into an overlay, and even
// though it's not drawn, that its sync point is waited on.
Expand Down
2 changes: 2 additions & 0 deletions cc/output/overlay_candidate.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class CC_EXPORT OverlayCandidate {
gfx::OverlayTransform transform;
// Format of the buffer to composite.
ResourceFormat format;
// Size of the resource, in pixels.
gfx::Size resource_size_in_pixels;
// Rect on the display to position the overlay to. Implementer must convert
// to integer coordinates if setting |overlay_handled| to true.
gfx::RectF display_rect;
Expand Down
15 changes: 6 additions & 9 deletions cc/output/overlay_processor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,19 @@

namespace cc {

OverlayProcessor::OverlayProcessor(OutputSurface* surface,
ResourceProvider* resource_provider)
: surface_(surface), resource_provider_(resource_provider) {}
OverlayProcessor::OverlayProcessor(OutputSurface* surface) : surface_(surface) {
}

void OverlayProcessor::Initialize() {
DCHECK(surface_);
if (!resource_provider_)
return;

OverlayCandidateValidator* candidates =
surface_->GetOverlayCandidateValidator();
if (candidates) {
strategies_.push_back(scoped_ptr<Strategy>(
new OverlayStrategySingleOnTop(candidates, resource_provider_)));
strategies_.push_back(scoped_ptr<Strategy>(
new OverlayStrategyUnderlay(candidates, resource_provider_)));
strategies_.push_back(
scoped_ptr<Strategy>(new OverlayStrategySingleOnTop(candidates)));
strategies_.push_back(
scoped_ptr<Strategy>(new OverlayStrategyUnderlay(candidates)));
}
}

Expand Down
3 changes: 1 addition & 2 deletions cc/output/overlay_processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class CC_EXPORT OverlayProcessor {
};
typedef ScopedPtrVector<Strategy> StrategyList;

OverlayProcessor(OutputSurface* surface, ResourceProvider* resource_provider);
explicit OverlayProcessor(OutputSurface* surface);
virtual ~OverlayProcessor();
// Virtual to allow testing different strategies.
virtual void Initialize();
Expand All @@ -40,7 +40,6 @@ class CC_EXPORT OverlayProcessor {
protected:
StrategyList strategies_;
OutputSurface* surface_;
ResourceProvider* resource_provider_;

private:
DISALLOW_COPY_AND_ASSIGN(OverlayProcessor);
Expand Down
16 changes: 5 additions & 11 deletions cc/output/overlay_strategy_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,21 @@

namespace cc {

OverlayStrategyCommon::OverlayStrategyCommon(
OverlayCandidateValidator* capability_checker,
ResourceProvider* resource_provider)
: capability_checker_(capability_checker),
resource_provider_(resource_provider) {
OverlayStrategyCommon::OverlayStrategyCommon() {
}

OverlayStrategyCommon::~OverlayStrategyCommon() {
}

bool OverlayStrategyCommon::IsOverlayQuad(const DrawQuad* draw_quad) {
unsigned int resource_id;
switch (draw_quad->material) {
case DrawQuad::TEXTURE_CONTENT:
resource_id = TextureDrawQuad::MaterialCast(draw_quad)->resource_id();
break;
return TextureDrawQuad::MaterialCast(draw_quad)->allow_overlay();
case DrawQuad::STREAM_VIDEO_CONTENT:
resource_id = StreamVideoDrawQuad::MaterialCast(draw_quad)->resource_id();
break;
return StreamVideoDrawQuad::MaterialCast(draw_quad)->allow_overlay();
default:
return false;
}
return resource_provider_->AllowOverlay(resource_id);
}

bool OverlayStrategyCommon::IsInvisibleQuad(const DrawQuad* draw_quad) {
Expand All @@ -64,6 +56,7 @@ bool OverlayStrategyCommon::GetTextureQuadInfo(const TextureDrawQuad& quad,
overlay_transform == gfx::OVERLAY_TRANSFORM_INVALID)
return false;
quad_info->resource_id = quad.resource_id();
quad_info->resource_size_in_pixels = quad.resource_size_in_pixels();
quad_info->transform = overlay_transform;
quad_info->uv_rect = BoundingRect(quad.uv_top_left, quad.uv_bottom_right);
return true;
Expand All @@ -82,6 +75,7 @@ bool OverlayStrategyCommon::GetVideoQuadInfo(const StreamVideoDrawQuad& quad,
return false;
}
quad_info->resource_id = quad.resource_id();
quad_info->resource_size_in_pixels = quad.resource_size_in_pixels();
quad_info->transform = overlay_transform;

gfx::Point3F uv0 = gfx::Point3F(0, 0, 0);
Expand Down
6 changes: 1 addition & 5 deletions cc/output/overlay_strategy_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ class OverlayCandidate;

class CC_EXPORT OverlayStrategyCommon : public OverlayProcessor::Strategy {
public:
OverlayStrategyCommon(OverlayCandidateValidator* capability_checker,
ResourceProvider* resource_provider);
OverlayStrategyCommon();
~OverlayStrategyCommon() override;

protected:
Expand All @@ -38,9 +37,6 @@ class CC_EXPORT OverlayStrategyCommon : public OverlayProcessor::Strategy {
bool GetVideoQuadInfo(const StreamVideoDrawQuad& quad,
OverlayCandidate* quad_info);

OverlayCandidateValidator* capability_checker_;
ResourceProvider* resource_provider_;

private:
DISALLOW_COPY_AND_ASSIGN(OverlayStrategyCommon);
};
Expand Down
5 changes: 2 additions & 3 deletions cc/output/overlay_strategy_single_on_top.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
namespace cc {

OverlayStrategySingleOnTop::OverlayStrategySingleOnTop(
OverlayCandidateValidator* capability_checker,
ResourceProvider* resource_provider)
: OverlayStrategyCommon(capability_checker, resource_provider) {
OverlayCandidateValidator* capability_checker)
: capability_checker_(capability_checker) {
}

bool OverlayStrategySingleOnTop::Attempt(
Expand Down
Loading

0 comments on commit f89f594

Please sign in to comment.