Skip to content

Commit

Permalink
Make TextureLayerImplTest comply with secure_output flag.
Browse files Browse the repository at this point in the history
This patch adds a flag 'secure_output_only_' to TextureMailbox and a flag
'is_secure_output_' to the LayerTreeImpl.

This flags are used by TextureLayerImpl to determine if it's secure to
composite specific textures coming from a mailbox on a specific compositor.

BUG=b/27173841,b/27174223
CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel

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

Cr-Commit-Position: refs/heads/master@{#379966}
  • Loading branch information
DCastagna authored and Commit bot committed Mar 8, 2016
1 parent 5241d81 commit 26563f4
Show file tree
Hide file tree
Showing 14 changed files with 137 additions and 33 deletions.
2 changes: 1 addition & 1 deletion cc/blink/web_external_texture_layer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ bool WebExternalTextureLayerImpl::PrepareTextureMailbox(

*mailbox =
cc::TextureMailbox(name, sync_token, client_mailbox.textureTarget, size,
client_mailbox.allowOverlay);
client_mailbox.allowOverlay, false);
}
mailbox->set_nearest_neighbor(client_mailbox.nearestNeighbor);

Expand Down
8 changes: 8 additions & 0 deletions cc/layers/layer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,14 @@ void LayerImpl::TakeCopyRequestsAndTransformToTarget(
layer_tree_impl()->set_needs_update_draw_properties();
}

bool LayerImpl::AnchestorHasCopyRequest() const {
for (const LayerImpl* layer = this; layer; layer = layer->parent()) {
if (layer->HasCopyRequest())
return true;
}
return false;
}

void LayerImpl::ClearRenderSurfaceLayerList() {
if (render_surface_)
render_surface_->ClearLayerLists();
Expand Down
1 change: 1 addition & 0 deletions cc/layers/layer_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ class CC_EXPORT LayerImpl : public LayerAnimationValueObserver,
void TakeCopyRequestsAndTransformToTarget(
std::vector<scoped_ptr<CopyOutputRequest>>* request);
bool HasCopyRequest() const { return !copy_requests_.empty(); }
bool AnchestorHasCopyRequest() const;

void SetMaskLayer(scoped_ptr<LayerImpl> mask_layer);
LayerImpl* mask_layer() { return mask_layer_.get(); }
Expand Down
40 changes: 21 additions & 19 deletions cc/layers/texture_layer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
#include <vector>

#include "base/strings/stringprintf.h"
#include "cc/output/output_surface.h"
#include "cc/output/renderer.h"
#include "cc/quads/solid_color_draw_quad.h"
#include "cc/quads/texture_draw_quad.h"
#include "cc/resources/platform_color.h"
#include "cc/resources/scoped_resource.h"
Expand Down Expand Up @@ -163,26 +165,26 @@ void TextureLayerImpl::AppendQuads(RenderPass* render_pass,
if (visible_quad_rect.IsEmpty())
return;

TextureDrawQuad* quad =
render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>();
ResourceId id =
valid_texture_copy_ ? texture_copy_->id() : external_texture_resource_;
quad->SetNew(shared_quad_state,
quad_rect,
opaque_rect,
visible_quad_rect,
id,
premultiplied_alpha_,
uv_top_left_,
uv_bottom_right_,
bg_color,
vertex_opacity_,
flipped_,
nearest_neighbor_);
if (!valid_texture_copy_) {
quad->set_resource_size_in_pixels(texture_mailbox_.size_in_pixels());
if (!texture_mailbox_.secure_output_only() ||
(layer_tree_impl()->output_surface()->is_secure() &&
!AnchestorHasCopyRequest())) {
TextureDrawQuad* quad =
render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>();
ResourceId id =
valid_texture_copy_ ? texture_copy_->id() : external_texture_resource_;
quad->SetNew(shared_quad_state, quad_rect, opaque_rect, visible_quad_rect,
id, premultiplied_alpha_, uv_top_left_, uv_bottom_right_,
bg_color, vertex_opacity_, flipped_, nearest_neighbor_);
if (!valid_texture_copy_) {
quad->set_resource_size_in_pixels(texture_mailbox_.size_in_pixels());
}
ValidateQuadResources(quad);
} else {
SolidColorDrawQuad* quad =
render_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
quad->SetNew(shared_quad_state, quad_rect, visible_quad_rect, SK_ColorBLACK,
false);
}
ValidateQuadResources(quad);
}

SimpleEnclosedRegion TextureLayerImpl::VisibleOpaqueRegion() const {
Expand Down
57 changes: 57 additions & 0 deletions cc/layers/texture_layer_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "cc/output/context_provider.h"
#include "cc/output/output_surface.h"
#include "cc/quads/draw_quad.h"
#include "cc/test/layer_test_common.h"
#include "testing/gtest/include/gtest/gtest.h"

Expand Down Expand Up @@ -102,5 +103,61 @@ TEST(TextureLayerImplTest, Occlusion) {
}
}

TEST(TextureLayerImplTest, Protected) {
gfx::Size layer_size(1000, 1000);
gfx::Size viewport_size(1000, 1000);

LayerTestCommon::LayerImplTest impl;

gpu::Mailbox mailbox;
impl.output_surface()->context_provider()->ContextGL()->GenMailboxCHROMIUM(
mailbox.name);
TextureMailbox texture_mailbox(
mailbox,
gpu::SyncToken(gpu::CommandBufferNamespace::GPU_IO, 0x123,
gpu::CommandBufferId::FromUnsafeValue(0x234), 0x456),
GL_TEXTURE_2D, layer_size, false, true);

TextureLayerImpl* texture_layer_impl =
impl.AddChildToRoot<TextureLayerImpl>();
texture_layer_impl->SetBounds(layer_size);
texture_layer_impl->SetDrawsContent(true);
texture_layer_impl->SetTextureMailbox(
texture_mailbox,
SingleReleaseCallbackImpl::Create(base::Bind(&IgnoreCallback)));

impl.CalcDrawProps(viewport_size);

{
gfx::Rect occluded;
impl.AppendQuadsWithOcclusion(texture_layer_impl, occluded);

EXPECT_EQ(1u, impl.quad_list().size());
EXPECT_EQ(DrawQuad::Material::SOLID_COLOR,
impl.quad_list().front()->material);
}

{
impl.SetSecureOutputSurface(true);
gfx::Rect occluded;
impl.AppendQuadsWithOcclusion(texture_layer_impl, occluded);

EXPECT_EQ(1u, impl.quad_list().size());
EXPECT_NE(DrawQuad::Material::SOLID_COLOR,
impl.quad_list().front()->material);
}

{
impl.SetSecureOutputSurface(false);
impl.RequestCopyOfOutput();
gfx::Rect occluded;
impl.AppendQuadsWithOcclusion(texture_layer_impl, occluded);

EXPECT_EQ(1u, impl.quad_list().size());
EXPECT_EQ(DrawQuad::Material::SOLID_COLOR,
impl.quad_list().front()->material);
}
}

} // namespace
} // namespace cc
4 changes: 2 additions & 2 deletions cc/output/gl_renderer_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2033,7 +2033,7 @@ TEST_F(GLRendererTest, DontOverlayWithCopyRequests) {

TextureMailbox mailbox =
TextureMailbox(gpu::Mailbox::Generate(), gpu::SyncToken(), GL_TEXTURE_2D,
gfx::Size(256, 256), true);
gfx::Size(256, 256), true, false);
scoped_ptr<SingleReleaseCallbackImpl> release_callback =
SingleReleaseCallbackImpl::Create(base::Bind(&MailboxReleased));
ResourceId resource_id = resource_provider->CreateResourceFromTextureMailbox(
Expand Down Expand Up @@ -2189,7 +2189,7 @@ TEST_F(GLRendererTest, OverlaySyncTokensAreProcessed) {
gpu::CommandBufferId::FromUnsafeValue(0x123), 29);
TextureMailbox mailbox =
TextureMailbox(gpu::Mailbox::Generate(), sync_token, GL_TEXTURE_2D,
gfx::Size(256, 256), true);
gfx::Size(256, 256), true, false);
scoped_ptr<SingleReleaseCallbackImpl> release_callback =
SingleReleaseCallbackImpl::Create(base::Bind(&MailboxReleased));
ResourceId resource_id = resource_provider->CreateResourceFromTextureMailbox(
Expand Down
5 changes: 5 additions & 0 deletions cc/output/output_surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ class CC_EXPORT OutputSurface : public base::trace_event::MemoryDumpProvider {
bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args,
base::trace_event::ProcessMemoryDump* pmd) override;

// Is this output surface associated with a secure display.
bool is_secure() const { return is_secure_; }
void set_is_secure(bool is_secure) { is_secure_ = is_secure; }

protected:
OutputSurfaceClient* client_;

Expand All @@ -193,6 +197,7 @@ class CC_EXPORT OutputSurface : public base::trace_event::MemoryDumpProvider {
private:
bool external_stencil_test_enabled_;

bool is_secure_ = false;
base::WeakPtrFactory<OutputSurface> weak_ptr_factory_;

DISALLOW_COPY_AND_ASSIGN(OutputSurface);
Expand Down
2 changes: 1 addition & 1 deletion cc/output/overlay_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ ResourceId CreateResource(ResourceProvider* resource_provider,
bool is_overlay_candidate) {
TextureMailbox mailbox =
TextureMailbox(gpu::Mailbox::Generate(), gpu::SyncToken(), GL_TEXTURE_2D,
size, is_overlay_candidate);
size, is_overlay_candidate, false);
scoped_ptr<SingleReleaseCallbackImpl> release_callback =
SingleReleaseCallbackImpl::Create(base::Bind(&MailboxReleased));

Expand Down
7 changes: 6 additions & 1 deletion cc/resources/texture_mailbox.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ TextureMailbox::TextureMailbox(const gpu::MailboxHolder& mailbox_holder)
: mailbox_holder_(mailbox_holder),
shared_bitmap_(NULL),
is_overlay_candidate_(false),
secure_output_only_(false),
nearest_neighbor_(false) {}

TextureMailbox::TextureMailbox(const gpu::Mailbox& mailbox,
Expand All @@ -27,17 +28,20 @@ TextureMailbox::TextureMailbox(const gpu::Mailbox& mailbox,
: mailbox_holder_(mailbox, sync_token, target),
shared_bitmap_(NULL),
is_overlay_candidate_(false),
secure_output_only_(false),
nearest_neighbor_(false) {}

TextureMailbox::TextureMailbox(const gpu::Mailbox& mailbox,
const gpu::SyncToken& sync_token,
uint32_t target,
const gfx::Size& size_in_pixels,
bool is_overlay_candidate)
bool is_overlay_candidate,
bool secure_output_only)
: mailbox_holder_(mailbox, sync_token, target),
shared_bitmap_(nullptr),
size_in_pixels_(size_in_pixels),
is_overlay_candidate_(is_overlay_candidate),
secure_output_only_(secure_output_only),
nearest_neighbor_(false) {
DCHECK(!is_overlay_candidate || !size_in_pixels.IsEmpty());
}
Expand All @@ -47,6 +51,7 @@ TextureMailbox::TextureMailbox(SharedBitmap* shared_bitmap,
: shared_bitmap_(shared_bitmap),
size_in_pixels_(size_in_pixels),
is_overlay_candidate_(false),
secure_output_only_(false),
nearest_neighbor_(false) {
// If an embedder of cc gives an invalid TextureMailbox, we should crash
// here to identify the offender.
Expand Down
5 changes: 4 additions & 1 deletion cc/resources/texture_mailbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class CC_EXPORT TextureMailbox {
const gpu::SyncToken& sync_token,
uint32_t target,
const gfx::Size& size_in_pixels,
bool is_overlay_candidate);
bool is_overlay_candidate,
bool secure_output_only);
TextureMailbox(SharedBitmap* shared_bitmap, const gfx::Size& size_in_pixels);

~TextureMailbox();
Expand All @@ -56,6 +57,7 @@ class CC_EXPORT TextureMailbox {
}

bool is_overlay_candidate() const { return is_overlay_candidate_; }
bool secure_output_only() const { return secure_output_only_; }
bool nearest_neighbor() const { return nearest_neighbor_; }
void set_nearest_neighbor(bool nearest_neighbor) {
nearest_neighbor_ = nearest_neighbor;
Expand All @@ -72,6 +74,7 @@ class CC_EXPORT TextureMailbox {
SharedBitmap* shared_bitmap_;
gfx::Size size_in_pixels_;
bool is_overlay_candidate_;
bool secure_output_only_;
bool nearest_neighbor_;
};

Expand Down
5 changes: 3 additions & 2 deletions cc/resources/video_resource_updater.cc
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ void VideoResourceUpdater::CopyPlaneTexture(

external_resources->mailboxes.push_back(
TextureMailbox(resource->mailbox, sync_token, GL_TEXTURE_2D,
video_frame->coded_size(), false));
video_frame->coded_size(), false, false));

external_resources->release_callbacks.push_back(
base::Bind(&RecycleResource, AsWeakPtr(), resource->resource_id));
Expand Down Expand Up @@ -648,7 +648,8 @@ VideoFrameExternalResources VideoResourceUpdater::CreateForHardwarePlanes(
mailbox_holder.mailbox, mailbox_holder.sync_token,
mailbox_holder.texture_target, video_frame->coded_size(),
video_frame->metadata()->IsTrue(
media::VideoFrameMetadata::ALLOW_OVERLAY)));
media::VideoFrameMetadata::ALLOW_OVERLAY),
false));

external_resources.release_callbacks.push_back(
base::Bind(&ReturnTexture, AsWeakPtr(), video_frame));
Expand Down
11 changes: 11 additions & 0 deletions cc/test/layer_test_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "cc/base/math_util.h"
#include "cc/base/region.h"
#include "cc/layers/append_quads_data.h"
#include "cc/output/copy_output_request.h"
#include "cc/output/copy_output_result.h"
#include "cc/quads/draw_quad.h"
#include "cc/quads/render_pass.h"
#include "cc/test/animation_test_common.h"
Expand Down Expand Up @@ -208,4 +210,13 @@ void LayerTestCommon::LayerImplTest::AppendSurfaceQuadsWithOcclusion(
SK_ColorBLACK, 1.f, nullptr, &data, RenderPassId(1, 1));
}

void EmptyCopyOutputCallback(scoped_ptr<CopyOutputResult> result) {}

void LayerTestCommon::LayerImplTest::RequestCopyOfOutput() {
std::vector<scoped_ptr<CopyOutputRequest>> copy_requests;
copy_requests.push_back(
CopyOutputRequest::CreateRequest(base::Bind(&EmptyCopyOutputCallback)));
root_layer_impl_->PassCopyRequests(&copy_requests);
}

} // namespace cc
6 changes: 6 additions & 0 deletions cc/test/layer_test_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ class LayerTestCommon {
void AppendSurfaceQuadsWithOcclusion(RenderSurfaceImpl* surface_impl,
const gfx::Rect& occluded);

void RequestCopyOfOutput();

void SetSecureOutputSurface(bool secure_output) {
host_->host_impl()->output_surface()->set_is_secure(secure_output);
}

OutputSurface* output_surface() const {
return host_->host_impl()->output_surface();
}
Expand Down
17 changes: 11 additions & 6 deletions components/exo/buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -408,16 +408,20 @@ scoped_ptr<cc::SingleReleaseCallback> Buffer::ProduceTextureMailbox(
texture_target_, query_type_));
}

// TODO(dcastagna): Set properly based on the flag on the imported buffer.
bool secure_output_only = false;

if (use_zero_copy_) {
// Zero-copy means using the contents texture directly.
Texture* texture = contents_texture_.get();

// This binds the latest contents of this buffer to |texture|.
gpu::SyncToken sync_token = texture->BindTexImage();

*texture_mailbox = cc::TextureMailbox(
texture->mailbox(), sync_token, texture_target_,
gpu_memory_buffer_->GetSize(), is_overlay_candidate_);
*texture_mailbox =
cc::TextureMailbox(texture->mailbox(), sync_token, texture_target_,
gpu_memory_buffer_->GetSize(), is_overlay_candidate_,
secure_output_only);
// The contents texture will be released when no longer used by the
// compositor.
return cc::SingleReleaseCallback::Create(
Expand All @@ -439,9 +443,10 @@ scoped_ptr<cc::SingleReleaseCallback> Buffer::ProduceTextureMailbox(
gpu::SyncToken sync_token = contents_texture->CopyTexImage(
texture, base::Bind(&Buffer::ReleaseContentsTexture, AsWeakPtr(),
base::Passed(&contents_texture_)));
*texture_mailbox = cc::TextureMailbox(
texture->mailbox(), sync_token, GL_TEXTURE_2D,
gpu_memory_buffer_->GetSize(), false /* is_overlay_candidate */);
*texture_mailbox =
cc::TextureMailbox(texture->mailbox(), sync_token, GL_TEXTURE_2D,
gpu_memory_buffer_->GetSize(),
false /* is_overlay_candidate */, secure_output_only);
// The mailbox texture will be released when no longer used by the
// compositor.
return cc::SingleReleaseCallback::Create(
Expand Down

0 comments on commit 26563f4

Please sign in to comment.