diff options
author | achaulk <achaulk@chromium.org> | 2015-06-10 10:01:35 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-06-10 17:02:07 +0000 |
commit | f89f594219da597c20b749fee195977052c6f709 (patch) | |
tree | f66bfd03b24b36698dd800323e86a160bd20e051 | |
parent | 20a7d9f7cf570609d5314fbc6ab3b1514b9e3308 (diff) | |
download | chromium_src-f89f594219da597c20b749fee195977052c6f709.zip chromium_src-f89f594219da597c20b749fee195977052c6f709.tar.gz chromium_src-f89f594219da597c20b749fee195977052c6f709.tar.bz2 |
cc: Rework overlays to not use the ResourceProvider and pass texture 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}
36 files changed, 351 insertions, 261 deletions
diff --git a/cc/blink/web_external_texture_layer_impl.cc b/cc/blink/web_external_texture_layer_impl.cc index 0b6bbdb..a9c132b 100644 --- a/cc/blink/web_external_texture_layer_impl.cc +++ b/cc/blink/web_external_texture_layer_impl.cc @@ -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()) { diff --git a/cc/layers/texture_layer_impl.cc b/cc/layers/texture_layer_impl.cc index 63d0549..d0e6b19 100644 --- a/cc/layers/texture_layer_impl.cc +++ b/cc/layers/texture_layer_impl.cc @@ -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()); } @@ -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; } @@ -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); } diff --git a/cc/layers/video_layer_impl.cc b/cc/layers/video_layer_impl.cc index 754a2f2..eb9eaca 100644 --- a/cc/layers/video_layer_impl.cc +++ b/cc/layers/video_layer_impl.cc @@ -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; @@ -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; } @@ -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; @@ -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; @@ -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; @@ -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(); } diff --git a/cc/layers/video_layer_impl.h b/cc/layers/video_layer_impl.h index 5b3d955..58c0e12 100644 --- a/cc/layers/video_layer_impl.h +++ b/cc/layers/video_layer_impl.h @@ -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. diff --git a/cc/output/direct_renderer.cc b/cc/output/direct_renderer.cc index 23801db..058c53b 100644 --- a/cc/output/direct_renderer.cc +++ b/cc/output/direct_renderer.cc @@ -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(); } diff --git a/cc/output/gl_renderer_unittest.cc b/cc/output/gl_renderer_unittest.cc index 62c5e74..4b133c9 100644 --- a/cc/output/gl_renderer_unittest.cc +++ b/cc/output/gl_renderer_unittest.cc @@ -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(); @@ -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); @@ -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( @@ -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 @@ -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_; @@ -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); @@ -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( @@ -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. diff --git a/cc/output/overlay_candidate.h b/cc/output/overlay_candidate.h index 3639635..b3e7fb3 100644 --- a/cc/output/overlay_candidate.h +++ b/cc/output/overlay_candidate.h @@ -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; diff --git a/cc/output/overlay_processor.cc b/cc/output/overlay_processor.cc index 0f5ec56..baae69d 100644 --- a/cc/output/overlay_processor.cc +++ b/cc/output/overlay_processor.cc @@ -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))); } } diff --git a/cc/output/overlay_processor.h b/cc/output/overlay_processor.h index e50972e..e37816c 100644 --- a/cc/output/overlay_processor.h +++ b/cc/output/overlay_processor.h @@ -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(); @@ -40,7 +40,6 @@ class CC_EXPORT OverlayProcessor { protected: StrategyList strategies_; OutputSurface* surface_; - ResourceProvider* resource_provider_; private: DISALLOW_COPY_AND_ASSIGN(OverlayProcessor); diff --git a/cc/output/overlay_strategy_common.cc b/cc/output/overlay_strategy_common.cc index 6fa778a..f95b373 100644 --- a/cc/output/overlay_strategy_common.cc +++ b/cc/output/overlay_strategy_common.cc @@ -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) { @@ -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; @@ -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); diff --git a/cc/output/overlay_strategy_common.h b/cc/output/overlay_strategy_common.h index 515a106..2dc6075 100644 --- a/cc/output/overlay_strategy_common.h +++ b/cc/output/overlay_strategy_common.h @@ -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: @@ -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); }; diff --git a/cc/output/overlay_strategy_single_on_top.cc b/cc/output/overlay_strategy_single_on_top.cc index 921dba7..e188916 100644 --- a/cc/output/overlay_strategy_single_on_top.cc +++ b/cc/output/overlay_strategy_single_on_top.cc @@ -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( diff --git a/cc/output/overlay_strategy_single_on_top.h b/cc/output/overlay_strategy_single_on_top.h index eeecd32..cacc023 100644 --- a/cc/output/overlay_strategy_single_on_top.h +++ b/cc/output/overlay_strategy_single_on_top.h @@ -19,12 +19,14 @@ class TextureDrawQuad; class CC_EXPORT OverlayStrategySingleOnTop : public OverlayStrategyCommon { public: - OverlayStrategySingleOnTop(OverlayCandidateValidator* capability_checker, - ResourceProvider* resource_provider); + explicit OverlayStrategySingleOnTop( + OverlayCandidateValidator* capability_checker); bool Attempt(RenderPassList* render_passes_in_draw_order, OverlayCandidateList* candidate_list) override; private: + OverlayCandidateValidator* capability_checker_; + DISALLOW_COPY_AND_ASSIGN(OverlayStrategySingleOnTop); }; diff --git a/cc/output/overlay_strategy_underlay.cc b/cc/output/overlay_strategy_underlay.cc index a88997a..2e794d6 100644 --- a/cc/output/overlay_strategy_underlay.cc +++ b/cc/output/overlay_strategy_underlay.cc @@ -11,9 +11,8 @@ namespace cc { OverlayStrategyUnderlay::OverlayStrategyUnderlay( - OverlayCandidateValidator* capability_checker, - ResourceProvider* resource_provider) - : OverlayStrategyCommon(capability_checker, resource_provider) { + OverlayCandidateValidator* capability_checker) + : capability_checker_(capability_checker) { } bool OverlayStrategyUnderlay::Attempt( diff --git a/cc/output/overlay_strategy_underlay.h b/cc/output/overlay_strategy_underlay.h index 881e170..d8351ef 100644 --- a/cc/output/overlay_strategy_underlay.h +++ b/cc/output/overlay_strategy_underlay.h @@ -18,12 +18,14 @@ class TextureDrawQuad; // are fully opaque. class CC_EXPORT OverlayStrategyUnderlay : public OverlayStrategyCommon { public: - OverlayStrategyUnderlay(OverlayCandidateValidator* capability_checker, - ResourceProvider* resource_provider); + explicit OverlayStrategyUnderlay( + OverlayCandidateValidator* capability_checker); bool Attempt(RenderPassList* render_passes_in_draw_order, OverlayCandidateList* candidate_list) override; private: + OverlayCandidateValidator* capability_checker_; + DISALLOW_COPY_AND_ASSIGN(OverlayStrategyUnderlay); }; diff --git a/cc/output/overlay_unittest.cc b/cc/output/overlay_unittest.cc index a0c1643..448d04d 100644 --- a/cc/output/overlay_unittest.cc +++ b/cc/output/overlay_unittest.cc @@ -78,11 +78,9 @@ void SingleOverlayValidator::CheckOverlaySupport( template <typename OverlayStrategyType> class SingleOverlayProcessor : public OverlayProcessor { public: - SingleOverlayProcessor(OutputSurface* surface, - ResourceProvider* resource_provider) - : OverlayProcessor(surface, resource_provider) { + explicit SingleOverlayProcessor(OutputSurface* surface) + : OverlayProcessor(surface) { EXPECT_EQ(surface, surface_); - EXPECT_EQ(resource_provider, resource_provider_); } // Virtual to allow testing different strategies. @@ -90,22 +88,20 @@ class SingleOverlayProcessor : public OverlayProcessor { OverlayCandidateValidator* candidates = surface_->GetOverlayCandidateValidator(); ASSERT_TRUE(candidates != NULL); - strategies_.push_back(scoped_ptr<Strategy>( - new OverlayStrategyType(candidates, resource_provider_))); + strategies_.push_back( + scoped_ptr<Strategy>(new OverlayStrategyType(candidates))); } }; class DefaultOverlayProcessor : public OverlayProcessor { public: - DefaultOverlayProcessor(OutputSurface* surface, - ResourceProvider* resource_provider); + explicit DefaultOverlayProcessor(OutputSurface* surface); size_t GetStrategyCount(); }; -DefaultOverlayProcessor::DefaultOverlayProcessor( - OutputSurface* surface, - ResourceProvider* resource_provider) - : OverlayProcessor(surface, resource_provider) {} +DefaultOverlayProcessor::DefaultOverlayProcessor(OutputSurface* surface) + : OverlayProcessor(surface) { +} size_t DefaultOverlayProcessor::GetStrategyCount() { return strategies_.size(); @@ -157,7 +153,6 @@ ResourceId CreateResource(ResourceProvider* resource_provider) { 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)); @@ -185,6 +180,8 @@ TextureDrawQuad* CreateCandidateQuadAt(ResourceProvider* resource_provider, bool flipped = false; bool nearest_neighbor = false; float vertex_opacity[4] = {1.0f, 1.0f, 1.0f, 1.0f}; + gfx::Size resource_size_in_pixels = gfx::Size(64, 64); + bool allow_overlay = true; TextureDrawQuad* overlay_quad = render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>(); @@ -200,6 +197,8 @@ TextureDrawQuad* CreateCandidateQuadAt(ResourceProvider* resource_provider, vertex_opacity, flipped, nearest_neighbor); + overlay_quad->set_allow_overlay(allow_overlay); + overlay_quad->set_resource_size_in_pixels(resource_size_in_pixels); return overlay_quad; } @@ -211,11 +210,13 @@ StreamVideoDrawQuad* CreateCandidateVideoQuadAt( const gfx::Rect& rect, const gfx::Transform& transform) { ResourceId resource_id = CreateResource(resource_provider); + gfx::Size resource_size_in_pixels = gfx::Size(64, 64); + bool allow_overlay = true; StreamVideoDrawQuad* overlay_quad = render_pass->CreateAndAppendDrawQuad<StreamVideoDrawQuad>(); overlay_quad->SetNew(shared_quad_state, rect, rect, rect, resource_id, - transform); + resource_size_in_pixels, allow_overlay, transform); return overlay_quad; } @@ -306,7 +307,7 @@ TEST(OverlayTest, OverlaysProcessorHasStrategy) { &output_surface, shared_bitmap_manager.get()); scoped_ptr<DefaultOverlayProcessor> overlay_processor( - new DefaultOverlayProcessor(&output_surface, resource_provider.get())); + new DefaultOverlayProcessor(&output_surface)); overlay_processor->Initialize(); EXPECT_GE(2U, overlay_processor->GetStrategyCount()); } @@ -325,8 +326,8 @@ class OverlayTest : public testing::Test { resource_provider_ = FakeResourceProvider::Create( output_surface_.get(), shared_bitmap_manager_.get()); - overlay_processor_.reset(new SingleOverlayProcessor<OverlayStrategyType>( - output_surface_.get(), resource_provider_.get())); + overlay_processor_.reset( + new SingleOverlayProcessor<OverlayStrategyType>(output_surface_.get())); overlay_processor_->Initialize(); } diff --git a/cc/quads/draw_quad_unittest.cc b/cc/quads/draw_quad_unittest.cc index 055b7d9..5bce42e 100644 --- a/cc/quads/draw_quad_unittest.cc +++ b/cc/quads/draw_quad_unittest.cc @@ -330,6 +330,15 @@ void CompareDrawQuad(DrawQuad* quad, } \ SETUP_AND_COPY_QUAD_NEW(Type, quad_new); +#define CREATE_QUAD_10_ALL(Type, a, b, c, d, e, f, g, h, i, j) \ + Type* quad_all = render_pass->CreateAndAppendDrawQuad<Type>(); \ + { \ + QUAD_DATA quad_all->SetAll(shared_state, quad_rect, quad_opaque_rect, \ + quad_visible_rect, needs_blending, a, b, c, d, \ + e, f, g, h, i, j); \ + } \ + SETUP_AND_COPY_QUAD_ALL(Type, quad_all); + #define CREATE_QUAD_11_NEW(Type, a, b, c, d, e, f, g, h, i, j, k) \ Type* quad_new = render_pass->CreateAndAppendDrawQuad<Type>(); \ { \ @@ -508,20 +517,27 @@ TEST(DrawQuadTest, CopyStreamVideoDrawQuad) { gfx::Rect opaque_rect(33, 47, 10, 12); gfx::Rect visible_rect(40, 50, 30, 20); ResourceId resource_id = 64; + gfx::Size resource_size_in_pixels = gfx::Size(40, 41); + bool allow_overlay = true; gfx::Transform matrix = gfx::Transform(0.5, 0.25, 1, 0.75, 0, 1); CREATE_SHARED_STATE(); - CREATE_QUAD_4_NEW( - StreamVideoDrawQuad, opaque_rect, visible_rect, resource_id, matrix); + CREATE_QUAD_6_NEW(StreamVideoDrawQuad, opaque_rect, visible_rect, resource_id, + resource_size_in_pixels, allow_overlay, matrix); EXPECT_EQ(DrawQuad::STREAM_VIDEO_CONTENT, copy_quad->material); EXPECT_EQ(visible_rect, copy_quad->visible_rect); EXPECT_EQ(opaque_rect, copy_quad->opaque_rect); EXPECT_EQ(resource_id, copy_quad->resource_id()); + EXPECT_EQ(allow_overlay, copy_quad->allow_overlay()); + EXPECT_EQ(resource_size_in_pixels, copy_quad->resource_size_in_pixels()); EXPECT_EQ(matrix, copy_quad->matrix); - CREATE_QUAD_2_ALL(StreamVideoDrawQuad, resource_id, matrix); + CREATE_QUAD_4_ALL(StreamVideoDrawQuad, resource_id, resource_size_in_pixels, + allow_overlay, matrix); EXPECT_EQ(DrawQuad::STREAM_VIDEO_CONTENT, copy_quad->material); EXPECT_EQ(resource_id, copy_quad->resource_id()); + EXPECT_EQ(allow_overlay, copy_quad->allow_overlay()); + EXPECT_EQ(resource_size_in_pixels, copy_quad->resource_size_in_pixels()); EXPECT_EQ(matrix, copy_quad->matrix); } @@ -545,6 +561,8 @@ TEST(DrawQuadTest, CopyTextureDrawQuad) { gfx::Rect opaque_rect(33, 47, 10, 12); gfx::Rect visible_rect(40, 50, 30, 20); unsigned resource_id = 82; + gfx::Size resource_size_in_pixels = gfx::Size(40, 41); + bool allow_overlay = true; bool premultiplied_alpha = true; gfx::PointF uv_top_left(0.5f, 224.f); gfx::PointF uv_bottom_right(51.5f, 260.f); @@ -575,17 +593,14 @@ TEST(DrawQuadTest, CopyTextureDrawQuad) { EXPECT_EQ(y_flipped, copy_quad->y_flipped); EXPECT_EQ(nearest_neighbor, copy_quad->nearest_neighbor); - CREATE_QUAD_8_ALL(TextureDrawQuad, - resource_id, - premultiplied_alpha, - uv_top_left, - uv_bottom_right, - SK_ColorTRANSPARENT, - vertex_opacity, - y_flipped, - nearest_neighbor); + CREATE_QUAD_10_ALL(TextureDrawQuad, resource_id, resource_size_in_pixels, + allow_overlay, premultiplied_alpha, uv_top_left, + uv_bottom_right, SK_ColorTRANSPARENT, vertex_opacity, + y_flipped, nearest_neighbor); EXPECT_EQ(DrawQuad::TEXTURE_CONTENT, copy_quad->material); EXPECT_EQ(resource_id, copy_quad->resource_id()); + EXPECT_EQ(allow_overlay, copy_quad->allow_overlay()); + EXPECT_EQ(resource_size_in_pixels, copy_quad->resource_size_in_pixels()); EXPECT_EQ(premultiplied_alpha, copy_quad->premultiplied_alpha); EXPECT_EQ(uv_top_left, copy_quad->uv_top_left); EXPECT_EQ(uv_bottom_right, copy_quad->uv_bottom_right); @@ -831,12 +846,16 @@ TEST_F(DrawQuadIteratorTest, StreamVideoDrawQuad) { gfx::Rect opaque_rect(33, 47, 10, 12); gfx::Rect visible_rect(40, 50, 30, 20); ResourceId resource_id = 64; + gfx::Size resource_size_in_pixels = gfx::Size(40, 41); + bool allow_overlay = true; gfx::Transform matrix = gfx::Transform(0.5, 0.25, 1, 0.75, 0, 1); CREATE_SHARED_STATE(); - CREATE_QUAD_4_NEW( - StreamVideoDrawQuad, opaque_rect, visible_rect, resource_id, matrix); + CREATE_QUAD_6_NEW(StreamVideoDrawQuad, opaque_rect, visible_rect, resource_id, + resource_size_in_pixels, allow_overlay, matrix); EXPECT_EQ(resource_id, quad_new->resource_id()); + EXPECT_EQ(allow_overlay, quad_new->allow_overlay()); + EXPECT_EQ(resource_size_in_pixels, quad_new->resource_size_in_pixels()); EXPECT_EQ(1, IterateAndCount(quad_new)); EXPECT_EQ(resource_id + 1, quad_new->resource_id()); } diff --git a/cc/quads/stream_video_draw_quad.cc b/cc/quads/stream_video_draw_quad.cc index 3ab9928..c25e5d5 100644 --- a/cc/quads/stream_video_draw_quad.cc +++ b/cc/quads/stream_video_draw_quad.cc @@ -19,11 +19,15 @@ void StreamVideoDrawQuad::SetNew(const SharedQuadState* shared_quad_state, const gfx::Rect& opaque_rect, const gfx::Rect& visible_rect, unsigned resource_id, + gfx::Size resource_size_in_pixels, + bool allow_overlay, const gfx::Transform& matrix) { bool needs_blending = false; DrawQuad::SetAll(shared_quad_state, DrawQuad::STREAM_VIDEO_CONTENT, rect, opaque_rect, visible_rect, needs_blending); resources.ids[kResourceIdIndex] = resource_id; + overlay_resources.size_in_pixels[kResourceIdIndex] = resource_size_in_pixels; + overlay_resources.allow_overlay[kResourceIdIndex] = allow_overlay; resources.count = 1; this->matrix = matrix; } @@ -34,10 +38,14 @@ void StreamVideoDrawQuad::SetAll(const SharedQuadState* shared_quad_state, const gfx::Rect& visible_rect, bool needs_blending, unsigned resource_id, + gfx::Size resource_size_in_pixels, + bool allow_overlay, const gfx::Transform& matrix) { DrawQuad::SetAll(shared_quad_state, DrawQuad::STREAM_VIDEO_CONTENT, rect, opaque_rect, visible_rect, needs_blending); resources.ids[kResourceIdIndex] = resource_id; + overlay_resources.size_in_pixels[kResourceIdIndex] = resource_size_in_pixels; + overlay_resources.allow_overlay[kResourceIdIndex] = allow_overlay; resources.count = 1; this->matrix = matrix; } @@ -54,4 +62,9 @@ void StreamVideoDrawQuad::ExtendValue( MathUtil::AddToTracedValue("matrix", matrix, value); } +StreamVideoDrawQuad::OverlayResources::OverlayResources() { + for (size_t i = 0; i < Resources::kMaxResourceIdCount; ++i) + allow_overlay[i] = false; +} + } // namespace cc diff --git a/cc/quads/stream_video_draw_quad.h b/cc/quads/stream_video_draw_quad.h index faffd20..519c353 100644 --- a/cc/quads/stream_video_draw_quad.h +++ b/cc/quads/stream_video_draw_quad.h @@ -21,6 +21,8 @@ class CC_EXPORT StreamVideoDrawQuad : public DrawQuad { const gfx::Rect& opaque_rect, const gfx::Rect& visible_rect, unsigned resource_id, + gfx::Size resource_size_in_pixels, + bool allow_overlay, const gfx::Transform& matrix); void SetAll(const SharedQuadState* shared_quad_state, @@ -29,13 +31,29 @@ class CC_EXPORT StreamVideoDrawQuad : public DrawQuad { const gfx::Rect& visible_rect, bool needs_blending, unsigned resource_id, + gfx::Size resource_size_in_pixels, + bool allow_overlay, const gfx::Transform& matrix); gfx::Transform matrix; + struct OverlayResources { + OverlayResources(); + + gfx::Size size_in_pixels[Resources::kMaxResourceIdCount]; + bool allow_overlay[Resources::kMaxResourceIdCount]; + }; + OverlayResources overlay_resources; + static const StreamVideoDrawQuad* MaterialCast(const DrawQuad*); ResourceId resource_id() const { return resources.ids[kResourceIdIndex]; } + const gfx::Size& resource_size_in_pixels() const { + return overlay_resources.size_in_pixels[kResourceIdIndex]; + } + bool allow_overlay() const { + return overlay_resources.allow_overlay[kResourceIdIndex]; + } private: static const size_t kResourceIdIndex = 0; diff --git a/cc/quads/texture_draw_quad.cc b/cc/quads/texture_draw_quad.cc index 7106af5e..c469c87 100644 --- a/cc/quads/texture_draw_quad.cc +++ b/cc/quads/texture_draw_quad.cc @@ -59,6 +59,8 @@ void TextureDrawQuad::SetAll(const SharedQuadState* shared_quad_state, const gfx::Rect& visible_rect, bool needs_blending, unsigned resource_id, + gfx::Size resource_size_in_pixels, + bool allow_overlay, bool premultiplied_alpha, const gfx::PointF& uv_top_left, const gfx::PointF& uv_bottom_right, @@ -69,6 +71,8 @@ void TextureDrawQuad::SetAll(const SharedQuadState* shared_quad_state, DrawQuad::SetAll(shared_quad_state, DrawQuad::TEXTURE_CONTENT, rect, opaque_rect, visible_rect, needs_blending); resources.ids[kResourceIdIndex] = resource_id; + overlay_resources.size_in_pixels[kResourceIdIndex] = resource_size_in_pixels; + overlay_resources.allow_overlay[kResourceIdIndex] = allow_overlay; resources.count = 1; this->premultiplied_alpha = premultiplied_alpha; this->uv_top_left = uv_top_left; @@ -105,4 +109,9 @@ void TextureDrawQuad::ExtendValue(base::trace_event::TracedValue* value) const { value->SetBoolean("nearest_neighbor", nearest_neighbor); } +TextureDrawQuad::OverlayResources::OverlayResources() { + for (size_t i = 0; i < Resources::kMaxResourceIdCount; ++i) + allow_overlay[i] = false; +} + } // namespace cc diff --git a/cc/quads/texture_draw_quad.h b/cc/quads/texture_draw_quad.h index 3f85920..40c7623 100644 --- a/cc/quads/texture_draw_quad.h +++ b/cc/quads/texture_draw_quad.h @@ -35,6 +35,8 @@ class CC_EXPORT TextureDrawQuad : public DrawQuad { const gfx::Rect& visible_rect, bool needs_blending, unsigned resource_id, + gfx::Size resource_size_in_pixels, + bool allow_overlay, bool premultiplied_alpha, const gfx::PointF& uv_top_left, const gfx::PointF& uv_bottom_right, @@ -51,7 +53,27 @@ class CC_EXPORT TextureDrawQuad : public DrawQuad { bool y_flipped; bool nearest_neighbor; + struct OverlayResources { + OverlayResources(); + + gfx::Size size_in_pixels[Resources::kMaxResourceIdCount]; + bool allow_overlay[Resources::kMaxResourceIdCount]; + }; + OverlayResources overlay_resources; + ResourceId resource_id() const { return resources.ids[kResourceIdIndex]; } + const gfx::Size& resource_size_in_pixels() const { + return overlay_resources.size_in_pixels[kResourceIdIndex]; + } + void set_resource_size_in_pixels(const gfx::Size& size_in_pixels) { + overlay_resources.size_in_pixels[kResourceIdIndex] = size_in_pixels; + } + bool allow_overlay() const { + return overlay_resources.allow_overlay[kResourceIdIndex]; + } + void set_allow_overlay(bool allow_overlay) { + overlay_resources.allow_overlay[kResourceIdIndex] = allow_overlay; + } static const TextureDrawQuad* MaterialCast(const DrawQuad*); diff --git a/cc/resources/resource_provider.cc b/cc/resources/resource_provider.cc index 449e04b..087f0fe 100644 --- a/cc/resources/resource_provider.cc +++ b/cc/resources/resource_provider.cc @@ -278,7 +278,6 @@ ResourceProvider::Resource::Resource(GLuint texture_id, allocated(false), read_lock_fences_enabled(false), has_shared_bitmap_id(false), - allow_overlay(false), read_lock_fence(NULL), size(size), origin(origin), @@ -322,7 +321,6 @@ ResourceProvider::Resource::Resource(uint8_t* pixels, allocated(false), read_lock_fences_enabled(false), has_shared_bitmap_id(!!bitmap), - allow_overlay(false), read_lock_fence(NULL), size(size), origin(origin), @@ -367,7 +365,6 @@ ResourceProvider::Resource::Resource(const SharedBitmapId& bitmap_id, allocated(false), read_lock_fences_enabled(false), has_shared_bitmap_id(true), - allow_overlay(false), read_lock_fence(NULL), size(size), origin(origin), @@ -451,11 +448,6 @@ bool ResourceProvider::IsLost(ResourceId id) { return resource->lost; } -bool ResourceProvider::AllowOverlay(ResourceId id) { - Resource* resource = GetResource(id); - return resource->allow_overlay; -} - ResourceId ResourceProvider::CreateResource(const gfx::Size& size, GLint wrap_mode, TextureHint hint, @@ -575,7 +567,7 @@ ResourceId ResourceProvider::CreateResourceFromTextureMailbox( uint8_t* pixels = shared_bitmap->pixels(); DCHECK(pixels); resource = InsertResource( - id, Resource(pixels, shared_bitmap, mailbox.shared_memory_size(), + id, Resource(pixels, shared_bitmap, mailbox.size_in_pixels(), Resource::EXTERNAL, GL_LINEAR, GL_CLAMP_TO_EDGE)); } resource->allocated = true; @@ -583,7 +575,6 @@ ResourceId ResourceProvider::CreateResourceFromTextureMailbox( resource->release_callback_impl = base::Bind(&SingleReleaseCallbackImpl::Run, base::Owned(release_callback_impl.release())); - resource->allow_overlay = mailbox.allow_overlay(); return id; } @@ -1389,7 +1380,6 @@ void ResourceProvider::ReceiveFromChild( // Don't allocate a texture for a child. resource->allocated = true; resource->imported_count = 1; - resource->allow_overlay = it->allow_overlay; child_info.parent_to_child_map[local_id] = it->id; child_info.child_to_parent_map[it->id] = local_id; } @@ -1493,7 +1483,6 @@ void ResourceProvider::TransferResource(GLES2Interface* gl, resource->filter = source->filter; resource->size = source->size; resource->is_repeated = (source->wrap_mode == GL_REPEAT); - resource->allow_overlay = source->allow_overlay; if (source->type == RESOURCE_TYPE_BITMAP) { resource->mailbox_holder.mailbox = source->shared_bitmap_id; diff --git a/cc/resources/resource_provider.h b/cc/resources/resource_provider.h index 2130bb7..efcb632 100644 --- a/cc/resources/resource_provider.h +++ b/cc/resources/resource_provider.h @@ -107,7 +107,6 @@ class CC_EXPORT ResourceProvider { bool InUseByConsumer(ResourceId id); bool IsLost(ResourceId id); - bool AllowOverlay(ResourceId id); // Producer interface. @@ -503,7 +502,6 @@ class CC_EXPORT ResourceProvider { bool allocated : 1; bool read_lock_fences_enabled : 1; bool has_shared_bitmap_id : 1; - bool allow_overlay : 1; scoped_refptr<Fence> read_lock_fence; gfx::Size size; Origin origin; diff --git a/cc/resources/resource_provider_unittest.cc b/cc/resources/resource_provider_unittest.cc index 7ad0e86..2982a3d 100644 --- a/cc/resources/resource_provider_unittest.cc +++ b/cc/resources/resource_provider_unittest.cc @@ -1045,55 +1045,6 @@ TEST_P(ResourceProviderTest, ReadLockCountStopsReturnToChildOrDelete) { resource_provider_->DestroyChild(child_id); } -TEST_P(ResourceProviderTest, AllowOverlayTransfersToParent) { - // Overlays only supported on the GL path. - if (GetParam() != ResourceProvider::RESOURCE_TYPE_GL_TEXTURE) - return; - - uint32 sync_point = 0; - TextureMailbox mailbox(gpu::Mailbox::Generate(), GL_TEXTURE_2D, sync_point); - mailbox.set_allow_overlay(true); - scoped_ptr<SingleReleaseCallbackImpl> release_callback = - SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback)); - ResourceId id1 = child_resource_provider_->CreateResourceFromTextureMailbox( - mailbox, release_callback.Pass()); - - TextureMailbox mailbox2(gpu::Mailbox::Generate(), GL_TEXTURE_2D, sync_point); - mailbox2.set_allow_overlay(false); - scoped_ptr<SingleReleaseCallbackImpl> release_callback2 = - SingleReleaseCallbackImpl::Create(base::Bind(&EmptyReleaseCallback)); - ResourceId id2 = child_resource_provider_->CreateResourceFromTextureMailbox( - mailbox2, release_callback2.Pass()); - - ReturnedResourceArray returned_to_child; - int child_id = - resource_provider_->CreateChild(GetReturnCallback(&returned_to_child)); - - // Transfer some resources to the parent. - ResourceProvider::ResourceIdArray resource_ids_to_transfer; - resource_ids_to_transfer.push_back(id1); - resource_ids_to_transfer.push_back(id2); - TransferableResourceArray list; - child_resource_provider_->PrepareSendToParent(resource_ids_to_transfer, - &list); - ASSERT_EQ(2u, list.size()); - resource_provider_->ReceiveFromChild(child_id, list); - EXPECT_TRUE(resource_provider_->AllowOverlay(list[0].id)); - EXPECT_FALSE(resource_provider_->AllowOverlay(list[1].id)); - - resource_provider_->DeclareUsedResourcesFromChild( - child_id, ResourceProvider::ResourceIdSet()); - - EXPECT_EQ(2u, returned_to_child.size()); - child_resource_provider_->ReceiveReturnsFromParent(returned_to_child); - - child_resource_provider_->DeleteResource(id1); - child_resource_provider_->DeleteResource(id2); - EXPECT_EQ(0u, child_resource_provider_->num_resources()); - - resource_provider_->DestroyChild(child_id); -} - TEST_P(ResourceProviderTest, TransferSoftwareResources) { if (GetParam() != ResourceProvider::RESOURCE_TYPE_BITMAP) return; diff --git a/cc/resources/texture_mailbox.cc b/cc/resources/texture_mailbox.cc index 9bf242e..7e4dd29 100644 --- a/cc/resources/texture_mailbox.cc +++ b/cc/resources/texture_mailbox.cc @@ -28,15 +28,28 @@ TextureMailbox::TextureMailbox(const gpu::Mailbox& mailbox, nearest_neighbor_(false) { } +TextureMailbox::TextureMailbox(const gpu::Mailbox& mailbox, + uint32 target, + uint32 sync_point, + const gfx::Size& size_in_pixels, + bool allow_overlay) + : mailbox_holder_(mailbox, target, sync_point), + shared_bitmap_(nullptr), + size_in_pixels_(size_in_pixels), + allow_overlay_(allow_overlay), + nearest_neighbor_(false) { + DCHECK_IMPLIES(allow_overlay, !size_in_pixels.IsEmpty()); +} + TextureMailbox::TextureMailbox(SharedBitmap* shared_bitmap, - const gfx::Size& size) + const gfx::Size& size_in_pixels) : shared_bitmap_(shared_bitmap), - shared_memory_size_(size), + size_in_pixels_(size_in_pixels), allow_overlay_(false), nearest_neighbor_(false) { // If an embedder of cc gives an invalid TextureMailbox, we should crash // here to identify the offender. - CHECK(SharedBitmap::VerifySizeInBytes(shared_memory_size_)); + CHECK(SharedBitmap::VerifySizeInBytes(size_in_pixels_)); } TextureMailbox::~TextureMailbox() {} @@ -57,7 +70,7 @@ bool TextureMailbox::Equals(const TextureMailbox& other) const { size_t TextureMailbox::SharedMemorySizeInBytes() const { // UncheckedSizeInBytes is okay because we VerifySizeInBytes in the // constructor and the field is immutable. - return SharedBitmap::UncheckedSizeInBytes(shared_memory_size_); + return SharedBitmap::UncheckedSizeInBytes(size_in_pixels_); } } // namespace cc diff --git a/cc/resources/texture_mailbox.h b/cc/resources/texture_mailbox.h index cec60ce..47e71ac 100644 --- a/cc/resources/texture_mailbox.h +++ b/cc/resources/texture_mailbox.h @@ -22,7 +22,12 @@ class CC_EXPORT TextureMailbox { TextureMailbox(); explicit TextureMailbox(const gpu::MailboxHolder& mailbox_holder); TextureMailbox(const gpu::Mailbox& mailbox, uint32 target, uint32 sync_point); - TextureMailbox(SharedBitmap* shared_bitmap, const gfx::Size& size); + TextureMailbox(const gpu::Mailbox& mailbox, + uint32 target, + uint32 sync_point, + const gfx::Size& size_in_pixels, + bool allow_overlay); + TextureMailbox(SharedBitmap* shared_bitmap, const gfx::Size& size_in_pixels); ~TextureMailbox(); @@ -41,20 +46,21 @@ class CC_EXPORT TextureMailbox { } bool allow_overlay() const { return allow_overlay_; } - void set_allow_overlay(bool allow_overlay) { allow_overlay_ = allow_overlay; } bool nearest_neighbor() const { return nearest_neighbor_; } void set_nearest_neighbor(bool nearest_neighbor) { nearest_neighbor_ = nearest_neighbor; } + // This is valid if allow_overlau() or IsSharedMemory() is true. + gfx::Size size_in_pixels() const { return size_in_pixels_; } + SharedBitmap* shared_bitmap() const { return shared_bitmap_; } - gfx::Size shared_memory_size() const { return shared_memory_size_; } size_t SharedMemorySizeInBytes() const; private: gpu::MailboxHolder mailbox_holder_; SharedBitmap* shared_bitmap_; - gfx::Size shared_memory_size_; + gfx::Size size_in_pixels_; bool allow_overlay_; bool nearest_neighbor_; }; diff --git a/cc/resources/video_resource_updater.cc b/cc/resources/video_resource_updater.cc index d681b39..7c4746f 100644 --- a/cc/resources/video_resource_updater.cc +++ b/cc/resources/video_resource_updater.cc @@ -417,9 +417,8 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForHardwarePlanes( const gpu::MailboxHolder& mailbox_holder = video_frame->mailbox_holder(i); external_resources.mailboxes.push_back( TextureMailbox(mailbox_holder.mailbox, mailbox_holder.texture_target, - mailbox_holder.sync_point)); - external_resources.mailboxes.back().set_allow_overlay( - video_frame->allow_overlay()); + mailbox_holder.sync_point, video_frame->coded_size(), + video_frame->allow_overlay())); external_resources.release_callbacks.push_back( base::Bind(&ReturnTexture, AsWeakPtr(), video_frame)); } diff --git a/cc/surfaces/surface_aggregator_perftest.cc b/cc/surfaces/surface_aggregator_perftest.cc index 104a55c..b5fddf5 100644 --- a/cc/surfaces/surface_aggregator_perftest.cc +++ b/cc/surfaces/surface_aggregator_perftest.cc @@ -70,8 +70,8 @@ class SurfaceAggregatorPerfTest : public testing::Test { bool flipped = false; bool nearest_neighbor = false; quad->SetAll(sqs, rect, opaque_rect, visible_rect, needs_blending, j, - premultiplied_alpha, uv_top_left, uv_bottom_right, - background_color, vertex_opacity, flipped, + gfx::Size(), false, premultiplied_alpha, uv_top_left, + uv_bottom_right, background_color, vertex_opacity, flipped, nearest_neighbor); } sqs = pass->CreateAndAppendSharedQuadState(); diff --git a/cc/surfaces/surface_aggregator_unittest.cc b/cc/surfaces/surface_aggregator_unittest.cc index ac81b3b..981a573 100644 --- a/cc/surfaces/surface_aggregator_unittest.cc +++ b/cc/surfaces/surface_aggregator_unittest.cc @@ -1352,19 +1352,10 @@ void SubmitFrameWithResources(ResourceId* resource_ids, const float vertex_opacity[4] = {0.f, 0.f, 1.f, 1.f}; bool flipped = false; bool nearest_neighbor = false; - quad->SetAll(sqs, - rect, - opaque_rect, - visible_rect, - needs_blending, - resource_ids[i], - premultiplied_alpha, - uv_top_left, - uv_bottom_right, - background_color, - vertex_opacity, - flipped, - nearest_neighbor); + quad->SetAll(sqs, rect, opaque_rect, visible_rect, needs_blending, + resource_ids[i], gfx::Size(), false, premultiplied_alpha, + uv_top_left, uv_bottom_right, background_color, vertex_opacity, + flipped, nearest_neighbor); } frame_data->render_pass_list.push_back(pass.Pass()); scoped_ptr<CompositorFrame> frame(new CompositorFrame); diff --git a/cc/test/render_pass_test_common.cc b/cc/test/render_pass_test_common.cc index 3789efc..b2242f7 100644 --- a/cc/test/render_pass_test_common.cc +++ b/cc/test/render_pass_test_common.cc @@ -144,12 +144,8 @@ void TestRenderPass::AppendOneOfEveryQuadType( StreamVideoDrawQuad* stream_video_quad = this->CreateAndAppendDrawQuad<StreamVideoDrawQuad>(); - stream_video_quad->SetNew(shared_state, - rect, - opaque_rect, - visible_rect, - resource6, - gfx::Transform()); + stream_video_quad->SetNew(shared_state, rect, opaque_rect, visible_rect, + resource6, gfx::Size(), false, gfx::Transform()); TextureDrawQuad* texture_quad = this->CreateAndAppendDrawQuad<TextureDrawQuad>(); diff --git a/content/browser/compositor/browser_compositor_overlay_candidate_validator_ozone.cc b/content/browser/compositor/browser_compositor_overlay_candidate_validator_ozone.cc index 7a3c70d..d21121b 100644 --- a/content/browser/compositor/browser_compositor_overlay_candidate_validator_ozone.cc +++ b/content/browser/compositor/browser_compositor_overlay_candidate_validator_ozone.cc @@ -57,6 +57,8 @@ void BrowserCompositorOverlayCandidateValidatorOzone::CheckOverlaySupport( ozone_surface_list.at(i).display_rect = surfaces->at(i).display_rect; ozone_surface_list.at(i).crop_rect = surfaces->at(i).uv_rect; ozone_surface_list.at(i).plane_z_order = surfaces->at(i).plane_z_order; + ozone_surface_list.at(i).buffer_size = + surfaces->at(i).resource_size_in_pixels; } overlay_candidates_->CheckOverlaySupport(&ozone_surface_list); diff --git a/content/common/cc_messages.cc b/content/common/cc_messages.cc index 57871ac..cc8dd5f 100644 --- a/content/common/cc_messages.cc +++ b/content/common/cc_messages.cc @@ -854,4 +854,76 @@ void ParamTraits<cc::DrawQuad::Resources>::Log(const param_type& p, l->append("])"); } +void ParamTraits<cc::StreamVideoDrawQuad::OverlayResources>::Write( + Message* m, + const param_type& p) { + for (size_t i = 0; i < cc::DrawQuad::Resources::kMaxResourceIdCount; ++i) { + WriteParam(m, p.size_in_pixels[i]); + WriteParam(m, p.allow_overlay[i]); + } +} + +bool ParamTraits<cc::StreamVideoDrawQuad::OverlayResources>::Read( + const Message* m, + base::PickleIterator* iter, + param_type* p) { + for (size_t i = 0; i < cc::DrawQuad::Resources::kMaxResourceIdCount; ++i) { + if (!ReadParam(m, iter, &p->size_in_pixels[i])) + return false; + if (!ReadParam(m, iter, &p->allow_overlay[i])) + return false; + } + return true; +} + +void ParamTraits<cc::StreamVideoDrawQuad::OverlayResources>::Log( + const param_type& p, + std::string* l) { + l->append("StreamVideoDrawQuad::OverlayResources(["); + for (size_t i = 0; i < cc::DrawQuad::Resources::kMaxResourceIdCount; ++i) { + LogParam(p.size_in_pixels[i], l); + l->append(", "); + LogParam(p.allow_overlay[i], l); + if (i < (cc::DrawQuad::Resources::kMaxResourceIdCount - 1)) + l->append(", "); + } + l->append("])"); +} + +void ParamTraits<cc::TextureDrawQuad::OverlayResources>::Write( + Message* m, + const param_type& p) { + for (size_t i = 0; i < cc::DrawQuad::Resources::kMaxResourceIdCount; ++i) { + WriteParam(m, p.size_in_pixels[i]); + WriteParam(m, p.allow_overlay[i]); + } +} + +bool ParamTraits<cc::TextureDrawQuad::OverlayResources>::Read( + const Message* m, + base::PickleIterator* iter, + param_type* p) { + for (size_t i = 0; i < cc::DrawQuad::Resources::kMaxResourceIdCount; ++i) { + if (!ReadParam(m, iter, &p->size_in_pixels[i])) + return false; + if (!ReadParam(m, iter, &p->allow_overlay[i])) + return false; + } + return true; +} + +void ParamTraits<cc::TextureDrawQuad::OverlayResources>::Log( + const param_type& p, + std::string* l) { + l->append("TextureDrawQuad::OverlayResources(["); + for (size_t i = 0; i < cc::DrawQuad::Resources::kMaxResourceIdCount; ++i) { + LogParam(p.size_in_pixels[i], l); + l->append(", "); + LogParam(p.allow_overlay[i], l); + if (i < (cc::DrawQuad::Resources::kMaxResourceIdCount - 1)) + l->append(", "); + } + l->append("])"); +} + } // namespace IPC diff --git a/content/common/cc_messages.h b/content/common/cc_messages.h index 7560f80..8dfa794 100644 --- a/content/common/cc_messages.h +++ b/content/common/cc_messages.h @@ -126,6 +126,22 @@ struct CONTENT_EXPORT ParamTraits<cc::DrawQuad::Resources> { static void Log(const param_type& p, std::string* l); }; +template <> +struct CONTENT_EXPORT ParamTraits<cc::StreamVideoDrawQuad::OverlayResources> { + typedef cc::StreamVideoDrawQuad::OverlayResources param_type; + static void Write(Message* m, const param_type& p); + static bool Read(const Message* m, base::PickleIterator* iter, param_type* p); + static void Log(const param_type& p, std::string* l); +}; + +template <> +struct CONTENT_EXPORT ParamTraits<cc::TextureDrawQuad::OverlayResources> { + typedef cc::TextureDrawQuad::OverlayResources param_type; + static void Write(Message* m, const param_type& p); + static bool Read(const Message* m, base::PickleIterator* iter, param_type* p); + static void Log(const param_type& p, std::string* l); +}; + } // namespace IPC #endif // CONTENT_COMMON_CC_MESSAGES_H_ @@ -206,6 +222,7 @@ IPC_STRUCT_TRAITS_END() IPC_STRUCT_TRAITS_BEGIN(cc::StreamVideoDrawQuad) IPC_STRUCT_TRAITS_PARENT(cc::DrawQuad) + IPC_STRUCT_TRAITS_MEMBER(overlay_resources) IPC_STRUCT_TRAITS_MEMBER(matrix) IPC_STRUCT_TRAITS_END() @@ -216,6 +233,7 @@ IPC_STRUCT_TRAITS_END() IPC_STRUCT_TRAITS_BEGIN(cc::TextureDrawQuad) IPC_STRUCT_TRAITS_PARENT(cc::DrawQuad) + IPC_STRUCT_TRAITS_MEMBER(overlay_resources) IPC_STRUCT_TRAITS_MEMBER(premultiplied_alpha) IPC_STRUCT_TRAITS_MEMBER(uv_top_left) IPC_STRUCT_TRAITS_MEMBER(uv_bottom_right) diff --git a/content/common/cc_messages_unittest.cc b/content/common/cc_messages_unittest.cc index 8ba443d..88daaa7 100644 --- a/content/common/cc_messages_unittest.cc +++ b/content/common/cc_messages_unittest.cc @@ -169,6 +169,8 @@ class CCMessagesTest : public testing::Test { void Compare(const StreamVideoDrawQuad* a, const StreamVideoDrawQuad* b) { EXPECT_EQ(a->resource_id(), b->resource_id()); + EXPECT_EQ(a->resource_size_in_pixels(), b->resource_size_in_pixels()); + EXPECT_EQ(a->allow_overlay(), b->allow_overlay()); EXPECT_EQ(a->matrix, b->matrix); } @@ -178,6 +180,8 @@ class CCMessagesTest : public testing::Test { void Compare(const TextureDrawQuad* a, const TextureDrawQuad* b) { EXPECT_EQ(a->resource_id(), b->resource_id()); + EXPECT_EQ(a->resource_size_in_pixels(), b->resource_size_in_pixels()); + EXPECT_EQ(a->allow_overlay(), b->allow_overlay()); EXPECT_EQ(a->premultiplied_alpha, b->premultiplied_alpha); EXPECT_EQ(a->uv_top_left, b->uv_top_left); EXPECT_EQ(a->uv_bottom_right, b->uv_bottom_right); @@ -263,6 +267,7 @@ TEST_F(CCMessagesTest, AllQuads) { bool arbitrary_bool2 = false; bool arbitrary_bool3 = true; bool arbitrary_bool4 = true; + bool arbitrary_bool5 = false; int arbitrary_context_id1 = 12; int arbitrary_context_id2 = 57; int arbitrary_context_id3 = -503; @@ -397,10 +402,10 @@ TEST_F(CCMessagesTest, AllQuads) { StreamVideoDrawQuad* streamvideo_in = pass_in->CreateAndAppendDrawQuad<StreamVideoDrawQuad>(); - streamvideo_in->SetAll(shared_state3_in, arbitrary_rect2, - arbitrary_rect2_inside_rect2, - arbitrary_rect1_inside_rect2, arbitrary_bool1, - arbitrary_resourceid2, arbitrary_matrix1); + streamvideo_in->SetAll( + shared_state3_in, arbitrary_rect2, arbitrary_rect2_inside_rect2, + arbitrary_rect1_inside_rect2, arbitrary_bool1, arbitrary_resourceid2, + arbitrary_size1, arbitrary_bool2, arbitrary_matrix1); pass_cmp->CopyFromAndAppendDrawQuad(streamvideo_in, streamvideo_in->shared_quad_state); @@ -418,19 +423,12 @@ TEST_F(CCMessagesTest, AllQuads) { TextureDrawQuad* texture_in = pass_in->CreateAndAppendDrawQuad<TextureDrawQuad>(); - texture_in->SetAll(shared_state3_in, - arbitrary_rect2, - arbitrary_rect2_inside_rect2, - arbitrary_rect1_inside_rect2, - arbitrary_bool1, - arbitrary_resourceid1, - arbitrary_bool2, - arbitrary_pointf1, - arbitrary_pointf2, - arbitrary_color, - arbitrary_float_array, - arbitrary_bool3, - arbitrary_bool4); + texture_in->SetAll(shared_state3_in, arbitrary_rect2, + arbitrary_rect2_inside_rect2, arbitrary_rect1_inside_rect2, + arbitrary_bool1, arbitrary_resourceid1, arbitrary_size1, + arbitrary_bool2, arbitrary_bool3, arbitrary_pointf1, + arbitrary_pointf2, arbitrary_color, arbitrary_float_array, + arbitrary_bool4, arbitrary_bool5); pass_cmp->CopyFromAndAppendDrawQuad(texture_in, texture_in->shared_quad_state); diff --git a/mojo/converters/surfaces/surfaces_type_converters.cc b/mojo/converters/surfaces/surfaces_type_converters.cc index 1763b56..0420b28 100644 --- a/mojo/converters/surfaces/surfaces_type_converters.cc +++ b/mojo/converters/surfaces/surfaces_type_converters.cc @@ -129,19 +129,15 @@ bool ConvertDrawQuad(const QuadPtr& input, cc::TextureDrawQuad* texture_quad = render_pass->CreateAndAppendDrawQuad<cc::TextureDrawQuad>(); texture_quad->SetAll( - sqs, - input->rect.To<gfx::Rect>(), - input->opaque_rect.To<gfx::Rect>(), - input->visible_rect.To<gfx::Rect>(), - input->needs_blending, - texture_quad_state->resource_id, + sqs, input->rect.To<gfx::Rect>(), input->opaque_rect.To<gfx::Rect>(), + input->visible_rect.To<gfx::Rect>(), input->needs_blending, + texture_quad_state->resource_id, gfx::Size(), false, texture_quad_state->premultiplied_alpha, texture_quad_state->uv_top_left.To<gfx::PointF>(), texture_quad_state->uv_bottom_right.To<gfx::PointF>(), texture_quad_state->background_color.To<SkColor>(), &texture_quad_state->vertex_opacity.storage()[0], - texture_quad_state->y_flipped, - texture_quad_state->nearest_neighbor); + texture_quad_state->y_flipped, texture_quad_state->nearest_neighbor); break; } case MATERIAL_TILED_CONTENT: { diff --git a/mojo/converters/surfaces/tests/surface_unittest.cc b/mojo/converters/surfaces/tests/surface_unittest.cc index b02178d..355e5ee 100644 --- a/mojo/converters/surfaces/tests/surface_unittest.cc +++ b/mojo/converters/surfaces/tests/surface_unittest.cc @@ -111,18 +111,11 @@ TEST_F(SurfaceLibQuadTest, TextureQuad) { float vertex_opacity[4] = {0.1f, 0.5f, 0.4f, 0.8f}; bool y_flipped = false; bool nearest_neighbor = false; - texture_quad->SetAll(sqs, - rect, - opaque_rect, - visible_rect, - needs_blending, - resource_id, - premultiplied_alpha, - uv_top_left, - uv_bottom_right, - background_color, - vertex_opacity, - y_flipped, + bool allow_overlay = false; + texture_quad->SetAll(sqs, rect, opaque_rect, visible_rect, needs_blending, + resource_id, gfx::Size(), allow_overlay, + premultiplied_alpha, uv_top_left, uv_bottom_right, + background_color, vertex_opacity, y_flipped, nearest_neighbor); QuadPtr mojo_quad = Quad::From<cc::DrawQuad>(*texture_quad); @@ -278,18 +271,11 @@ TEST(SurfaceLibTest, RenderPass) { float vertex_opacity[4] = {0.1f, 0.5f, 0.4f, 0.8f}; bool y_flipped = false; bool nearest_neighbor = false; - texture_quad->SetAll(sqs, - rect, - opaque_rect, - visible_rect, - needs_blending, - resource_id, - premultiplied_alpha, - uv_top_left, - uv_bottom_right, - background_color, - vertex_opacity, - y_flipped, + bool allow_overlay = false; + texture_quad->SetAll(sqs, rect, opaque_rect, visible_rect, needs_blending, + resource_id, gfx::Size(), allow_overlay, + premultiplied_alpha, uv_top_left, uv_bottom_right, + background_color, vertex_opacity, y_flipped, nearest_neighbor); PassPtr mojo_pass = Pass::From(*pass); |