summaryrefslogtreecommitdiffstats
path: root/cc
diff options
context:
space:
mode:
Diffstat (limited to 'cc')
-rw-r--r--cc/layers/surface_layer.cc16
-rw-r--r--cc/layers/surface_layer.h8
-rw-r--r--cc/layers/surface_layer_unittest.cc33
3 files changed, 52 insertions, 5 deletions
diff --git a/cc/layers/surface_layer.cc b/cc/layers/surface_layer.cc
index f1909b4..ee376aa 100644
--- a/cc/layers/surface_layer.cc
+++ b/cc/layers/surface_layer.cc
@@ -53,9 +53,10 @@ SurfaceLayer::~SurfaceLayer() {
DCHECK(destroy_sequence_.is_null());
}
-void SurfaceLayer::SetSurfaceId(SurfaceId surface_id) {
+void SurfaceLayer::SetSurfaceId(SurfaceId surface_id, const gfx::Size& size) {
SatisfyDestroySequence();
surface_id_ = surface_id;
+ surface_size_ = size;
CreateNewDestroySequence();
UpdateDrawsContent(HasDrawableContent());
@@ -88,6 +89,19 @@ void SurfaceLayer::PushPropertiesTo(LayerImpl* layer) {
layer_impl->SetSurfaceId(surface_id_);
}
+void SurfaceLayer::CalculateContentsScale(float ideal_contents_scale,
+ float* contents_scale_x,
+ float* contents_scale_y,
+ gfx::Size* content_bounds) {
+ *content_bounds = surface_size_;
+ *contents_scale_x =
+ bounds().IsEmpty() ? 1.f : static_cast<float>(content_bounds->width()) /
+ bounds().width();
+ *contents_scale_y =
+ bounds().IsEmpty() ? 1.f : static_cast<float>(content_bounds->height()) /
+ bounds().height();
+}
+
void SurfaceLayer::CreateNewDestroySequence() {
DCHECK(destroy_sequence_.is_null());
if (layer_tree_host()) {
diff --git a/cc/layers/surface_layer.h b/cc/layers/surface_layer.h
index 4292549..29d821f 100644
--- a/cc/layers/surface_layer.h
+++ b/cc/layers/surface_layer.h
@@ -9,6 +9,7 @@
#include "cc/layers/layer.h"
#include "cc/surfaces/surface_id.h"
#include "cc/surfaces/surface_sequence.h"
+#include "ui/gfx/size.h"
namespace cc {
@@ -29,12 +30,16 @@ class CC_EXPORT SurfaceLayer : public Layer {
const SatisfyCallback& satisfy_callback,
const RequireCallback& require_callback);
- void SetSurfaceId(SurfaceId surface_id);
+ void SetSurfaceId(SurfaceId surface_id, const gfx::Size& size);
// Layer overrides.
scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) override;
void SetLayerTreeHost(LayerTreeHost* host) override;
void PushPropertiesTo(LayerImpl* layer) override;
+ void CalculateContentsScale(float ideal_contents_scale,
+ float* contents_scale_x,
+ float* contents_scale_y,
+ gfx::Size* content_bounds) override;
protected:
SurfaceLayer(const SatisfyCallback& satisfy_callback,
@@ -47,6 +52,7 @@ class CC_EXPORT SurfaceLayer : public Layer {
void SatisfyDestroySequence();
SurfaceId surface_id_;
+ gfx::Size surface_size_;
SurfaceSequence destroy_sequence_;
SatisfyCallback satisfy_callback_;
RequireCallback require_callback_;
diff --git a/cc/layers/surface_layer_unittest.cc b/cc/layers/surface_layer_unittest.cc
index 99d0e17..7323bf4 100644
--- a/cc/layers/surface_layer_unittest.cc
+++ b/cc/layers/surface_layer_unittest.cc
@@ -65,7 +65,7 @@ TEST_F(SurfaceLayerTest, MultipleFramesOneSurface) {
scoped_refptr<SurfaceLayer> layer(SurfaceLayer::Create(
base::Bind(&SatisfyCallback, &blank_change),
base::Bind(&RequireCallback, &required_id, &required_seq)));
- layer->SetSurfaceId(SurfaceId(1));
+ layer->SetSurfaceId(SurfaceId(1), gfx::Size(1, 1));
layer_tree_host_->set_surface_id_namespace(1);
layer_tree_host_->SetRootLayer(layer);
@@ -74,7 +74,7 @@ TEST_F(SurfaceLayerTest, MultipleFramesOneSurface) {
scoped_refptr<SurfaceLayer> layer2(SurfaceLayer::Create(
base::Bind(&SatisfyCallback, &blank_change),
base::Bind(&RequireCallback, &required_id, &required_seq)));
- layer2->SetSurfaceId(SurfaceId(1));
+ layer2->SetSurfaceId(SurfaceId(1), gfx::Size(1, 1));
layer_tree_host2->set_surface_id_namespace(2);
layer_tree_host2->SetRootLayer(layer2);
@@ -110,6 +110,33 @@ TEST_F(SurfaceLayerTest, MultipleFramesOneSurface) {
EXPECT_EQ(2u, required_seq.size());
}
+// Check that setting content scale on the surface works.
+TEST_F(SurfaceLayerTest, ScaleSurface) {
+ SurfaceSequence blank_change;
+ SurfaceId required_id;
+ std::set<SurfaceSequence> required_seq;
+ scoped_refptr<SurfaceLayer> layer(SurfaceLayer::Create(
+ base::Bind(&SatisfyCallback, &blank_change),
+ base::Bind(&RequireCallback, &required_id, &required_seq)));
+ gfx::Size surface_size(10, 15);
+ layer->SetSurfaceId(SurfaceId(1), surface_size);
+ layer->SetBounds(gfx::Size(25, 45));
+
+ float scale_x;
+ float scale_y;
+ gfx::Size bounds;
+ layer->CalculateContentsScale(2.f, &scale_x, &scale_y, &bounds);
+ EXPECT_EQ(10.f / 25.f, scale_x);
+ EXPECT_EQ(15.f / 45.f, scale_y);
+ EXPECT_EQ(surface_size.ToString(), bounds.ToString());
+
+ layer->SetBounds(gfx::Size(0, 0));
+ layer->CalculateContentsScale(2.f, &scale_x, &scale_y, &bounds);
+ EXPECT_EQ(1.f, scale_x);
+ EXPECT_EQ(1.f, scale_y);
+ EXPECT_EQ(surface_size.ToString(), bounds.ToString());
+}
+
// Check that SurfaceSequence is sent through swap promise.
class SurfaceLayerSwapPromise : public LayerTreeTest {
public:
@@ -121,7 +148,7 @@ class SurfaceLayerSwapPromise : public LayerTreeTest {
layer_ = SurfaceLayer::Create(
base::Bind(&SatisfyCallback, &satisfied_sequence_),
base::Bind(&RequireCallback, &required_id_, &required_set_));
- layer_->SetSurfaceId(SurfaceId(1));
+ layer_->SetSurfaceId(SurfaceId(1), gfx::Size(1, 1));
// Layer hasn't been added to tree so no SurfaceSequence generated yet.
EXPECT_EQ(0u, required_set_.size());