summaryrefslogtreecommitdiffstats
path: root/cc
diff options
context:
space:
mode:
authorccameron@chromium.org <ccameron@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-24 22:01:50 +0000
committerccameron@chromium.org <ccameron@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-24 22:01:50 +0000
commit94c40e629c13f38e8eff6f8435ea490b7d40dbb9 (patch)
tree38578f86de47e92040742c8dd5e84a5910c2e5a7 /cc
parentf66375e4d724f5da1a406d553259685451cdf55d (diff)
downloadchromium_src-94c40e629c13f38e8eff6f8435ea490b7d40dbb9.zip
chromium_src-94c40e629c13f38e8eff6f8435ea490b7d40dbb9.tar.gz
chromium_src-94c40e629c13f38e8eff6f8435ea490b7d40dbb9.tar.bz2
Part 1/3 (compositor) of adding with device scale factor to transport surfaces
Add a DeviceScaleFactor method to RendererClient (and all its instances) to get the scale factor from the layer tree to the output surface. Add a scale factor argument to OutputSurface::Reshape Replace OutputSurface::Reshape's use of WebGraphicsContext3D's reshape with reshapeWithScaleFactor. Implement reshapeWithScaleFactor for command buffer based WebGraphicsContext3Ds, but stop propagating the scale factor argument there. BUG=132714 Review URL: https://chromiumcodereview.appspot.com/15688002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@202189 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc')
-rw-r--r--cc/output/gl_renderer.cc3
-rw-r--r--cc/output/gl_renderer_unittest.cc54
-rw-r--r--cc/output/output_surface.cc4
-rw-r--r--cc/output/output_surface.h2
-rw-r--r--cc/output/renderer.h3
-rw-r--r--cc/output/software_renderer_unittest.cc3
-rw-r--r--cc/test/pixel_test.cc3
-rw-r--r--cc/test/test_web_graphics_context_3d.cc3
-rw-r--r--cc/test/test_web_graphics_context_3d.h3
-rw-r--r--cc/trees/layer_tree_host_impl.cc7
-rw-r--r--cc/trees/layer_tree_host_impl.h1
-rw-r--r--cc/trees/layer_tree_host_impl_unittest.cc50
12 files changed, 124 insertions, 12 deletions
diff --git a/cc/output/gl_renderer.cc b/cc/output/gl_renderer.cc
index 47a7cc0..da2f4f6 100644
--- a/cc/output/gl_renderer.cc
+++ b/cc/output/gl_renderer.cc
@@ -321,7 +321,8 @@ void GLRenderer::BeginDrawingFrame(DrawingFrame* frame) {
// can leave the window at the wrong size if we never draw and the proper
// viewport size is never set.
is_viewport_changed_ = false;
- output_surface_->Reshape(gfx::Size(ViewportWidth(), ViewportHeight()));
+ output_surface_->Reshape(gfx::Size(ViewportWidth(), ViewportHeight()),
+ DeviceScaleFactor());
}
MakeContextCurrent();
diff --git a/cc/output/gl_renderer_unittest.cc b/cc/output/gl_renderer_unittest.cc
index 2ee3a63..7e1a438 100644
--- a/cc/output/gl_renderer_unittest.cc
+++ b/cc/output/gl_renderer_unittest.cc
@@ -151,7 +151,10 @@ class FakeRendererClient : public RendererClient {
last_call_was_set_visibility_(0),
root_layer_(LayerImpl::Create(host_impl_.active_tree(), 1)),
memory_allocation_limit_bytes_(
- PrioritizedResourceManager::DefaultMemoryAllocationLimit()) {
+ PrioritizedResourceManager::DefaultMemoryAllocationLimit()),
+ viewport_size_(gfx::Size(1, 1)),
+ scale_factor_(1.f),
+ is_viewport_changed_(true) {
root_layer_->CreateRenderSurface();
RenderPass::Id render_pass_id =
root_layer_->render_surface()->RenderPassId();
@@ -166,6 +169,9 @@ class FakeRendererClient : public RendererClient {
static gfx::Size fake_size(1, 1);
return fake_size;
}
+ virtual float DeviceScaleFactor() const OVERRIDE {
+ return scale_factor_;
+ }
virtual const LayerTreeSettings& Settings() const OVERRIDE {
static LayerTreeSettings fake_settings;
return fake_settings;
@@ -199,6 +205,14 @@ class FakeRendererClient : public RendererClient {
bool* last_call_was_set_visibility) {
last_call_was_set_visibility_ = last_call_was_set_visibility;
}
+ void set_viewport_and_scale(
+ gfx::Size viewport_size, float scale_factor) {
+ viewport_size_ = viewport_size;
+ scale_factor_ = scale_factor;
+ is_viewport_changed_ = true;
+ }
+ bool is_viewport_changed() const { return is_viewport_changed_; }
+ void clear_viewport_changed() { is_viewport_changed_ = false; }
RenderPass* root_render_pass() { return render_passes_in_draw_order_.back(); }
RenderPassList* render_passes_in_draw_order() {
@@ -217,6 +231,9 @@ class FakeRendererClient : public RendererClient {
scoped_ptr<LayerImpl> root_layer_;
RenderPassList render_passes_in_draw_order_;
size_t memory_allocation_limit_bytes_;
+ gfx::Size viewport_size_;
+ float scale_factor_;
+ bool is_viewport_changed_;
};
class FakeRendererGL : public GLRenderer {
@@ -1437,7 +1454,8 @@ class OutputSurfaceMockContext : public TestWebGraphicsContext3D {
MOCK_METHOD0(discardBackbufferCHROMIUM, void());
MOCK_METHOD2(bindFramebuffer, void(WGC3Denum target, WebGLId framebuffer));
MOCK_METHOD0(prepareTexture, void());
- MOCK_METHOD2(reshape, void(int width, int height));
+ MOCK_METHOD3(reshapeWithScaleFactor,
+ void(int width, int height, float scale_factor));
MOCK_METHOD4(drawElements,
void(WGC3Denum mode,
WGC3Dsizei count,
@@ -1462,7 +1480,7 @@ class MockOutputSurface : public OutputSurface {
MOCK_METHOD1(SendFrameToParentCompositor, void(CompositorFrame* frame));
MOCK_METHOD0(EnsureBackbuffer, void());
MOCK_METHOD0(DiscardBackbuffer, void());
- MOCK_METHOD1(Reshape, void(gfx::Size size));
+ MOCK_METHOD2(Reshape, void(gfx::Size size, float scale_factor));
MOCK_METHOD0(BindFramebuffer, void());
MOCK_METHOD2(PostSubBuffer, void(gfx::Rect rect, const LatencyInfo&));
MOCK_METHOD1(SwapBuffers, void(const LatencyInfo&));
@@ -1490,7 +1508,11 @@ class MockOutputSurfaceTest : public testing::Test, public FakeRendererClient {
EXPECT_CALL(output_surface_, EnsureBackbuffer()).WillRepeatedly(Return());
- EXPECT_CALL(output_surface_, Reshape(_)).Times(1);
+ if (is_viewport_changed()) {
+ EXPECT_CALL(output_surface_,
+ Reshape(DeviceViewportSize(), DeviceScaleFactor())).Times(1);
+ clear_viewport_changed();
+ }
EXPECT_CALL(output_surface_, BindFramebuffer()).Times(1);
@@ -1517,6 +1539,30 @@ TEST_F(MockOutputSurfaceTest, DrawFrameAndSwap) {
renderer_.SwapBuffers(LatencyInfo());
}
+TEST_F(MockOutputSurfaceTest, DrawFrameAndResizeAndSwap) {
+ DrawFrame();
+ EXPECT_CALL(output_surface_, SwapBuffers(_)).Times(1);
+ renderer_.SwapBuffers(LatencyInfo());
+
+ set_viewport_and_scale(gfx::Size(2, 2), 2.f);
+ renderer_.ViewportChanged();
+
+ DrawFrame();
+ EXPECT_CALL(output_surface_, SwapBuffers(_)).Times(1);
+ renderer_.SwapBuffers(LatencyInfo());
+
+ DrawFrame();
+ EXPECT_CALL(output_surface_, SwapBuffers(_)).Times(1);
+ renderer_.SwapBuffers(LatencyInfo());
+
+ set_viewport_and_scale(gfx::Size(1, 1), 1.f);
+ renderer_.ViewportChanged();
+
+ DrawFrame();
+ EXPECT_CALL(output_surface_, SwapBuffers(_)).Times(1);
+ renderer_.SwapBuffers(LatencyInfo());
+}
+
class MockOutputSurfaceTestWithPartialSwap : public MockOutputSurfaceTest {
public:
virtual const LayerTreeSettings& Settings() const OVERRIDE {
diff --git a/cc/output/output_surface.cc b/cc/output/output_surface.cc
index 7a7bdb0..b471a08 100644
--- a/cc/output/output_surface.cc
+++ b/cc/output/output_surface.cc
@@ -112,9 +112,9 @@ void OutputSurface::DiscardBackbuffer() {
context3d_->discardBackbufferCHROMIUM();
}
-void OutputSurface::Reshape(gfx::Size size) {
+void OutputSurface::Reshape(gfx::Size size, float scale_factor) {
DCHECK(context3d_);
- context3d_->reshape(size.width(), size.height());
+ context3d_->reshapeWithScaleFactor(size.width(), size.height(), scale_factor);
}
void OutputSurface::BindFramebuffer() {
diff --git a/cc/output/output_surface.h b/cc/output/output_surface.h
index 22ce6af..fb6f0b9 100644
--- a/cc/output/output_surface.h
+++ b/cc/output/output_surface.h
@@ -87,7 +87,7 @@ class CC_EXPORT OutputSurface {
virtual void EnsureBackbuffer();
virtual void DiscardBackbuffer();
- virtual void Reshape(gfx::Size size);
+ virtual void Reshape(gfx::Size size, float scale_factor);
virtual void BindFramebuffer();
diff --git a/cc/output/renderer.h b/cc/output/renderer.h
index b1b9f48..5592090 100644
--- a/cc/output/renderer.h
+++ b/cc/output/renderer.h
@@ -21,6 +21,7 @@ class ScopedResource;
class CC_EXPORT RendererClient {
public:
virtual gfx::Size DeviceViewportSize() const = 0;
+ virtual float DeviceScaleFactor() const = 0;
virtual const LayerTreeSettings& Settings() const = 0;
virtual void SetFullRootLayerDamage() = 0;
virtual void SetManagedMemoryPolicy(const ManagedMemoryPolicy& policy) = 0;
@@ -47,6 +48,8 @@ class CC_EXPORT Renderer {
int ViewportWidth() const { return ViewportSize().width(); }
int ViewportHeight() const { return ViewportSize().height(); }
+ float DeviceScaleFactor() const { return client_->DeviceScaleFactor(); }
+
virtual void ViewportChanged() {}
virtual void ReceiveCompositorFrameAck(const CompositorFrameAck& ack) {}
diff --git a/cc/output/software_renderer_unittest.cc b/cc/output/software_renderer_unittest.cc
index 4f2d605..af4d7d1 100644
--- a/cc/output/software_renderer_unittest.cc
+++ b/cc/output/software_renderer_unittest.cc
@@ -52,6 +52,9 @@ class SoftwareRendererTest : public testing::Test, public RendererClient {
virtual gfx::Size DeviceViewportSize() const OVERRIDE {
return viewport_size_;
}
+ virtual float DeviceScaleFactor() const OVERRIDE {
+ return 1.f;
+ }
virtual const LayerTreeSettings& Settings() const OVERRIDE {
return settings_;
}
diff --git a/cc/test/pixel_test.cc b/cc/test/pixel_test.cc
index 47d1796..132dc3b 100644
--- a/cc/test/pixel_test.cc
+++ b/cc/test/pixel_test.cc
@@ -30,6 +30,9 @@ class PixelTest::PixelTestRendererClient : public RendererClient {
virtual gfx::Size DeviceViewportSize() const OVERRIDE {
return device_viewport_size_;
}
+ virtual float DeviceScaleFactor() const OVERRIDE {
+ return 1.f;
+ }
virtual const LayerTreeSettings& Settings() const OVERRIDE {
return settings_;
}
diff --git a/cc/test/test_web_graphics_context_3d.cc b/cc/test/test_web_graphics_context_3d.cc
index 3de1d51..11c8a90 100644
--- a/cc/test/test_web_graphics_context_3d.cc
+++ b/cc/test/test_web_graphics_context_3d.cc
@@ -103,7 +103,8 @@ int TestWebGraphicsContext3D::height() {
return height_;
}
-void TestWebGraphicsContext3D::reshape(int width, int height) {
+void TestWebGraphicsContext3D::reshapeWithScaleFactor(
+ int width, int height, float scale_factor) {
width_ = width;
height_ = height;
}
diff --git a/cc/test/test_web_graphics_context_3d.h b/cc/test/test_web_graphics_context_3d.h
index 1e7e356..5780980 100644
--- a/cc/test/test_web_graphics_context_3d.h
+++ b/cc/test/test_web_graphics_context_3d.h
@@ -34,7 +34,8 @@ class TestWebGraphicsContext3D : public FakeWebGraphicsContext3D {
virtual int width();
virtual int height();
- virtual void reshape(int width, int height);
+ virtual void reshapeWithScaleFactor(
+ int width, int height, float scale_factor);
virtual bool isContextLost();
virtual WebKit::WGC3Denum getGraphicsResetStatusARB();
diff --git a/cc/trees/layer_tree_host_impl.cc b/cc/trees/layer_tree_host_impl.cc
index 9ccbe70..84c43c2 100644
--- a/cc/trees/layer_tree_host_impl.cc
+++ b/cc/trees/layer_tree_host_impl.cc
@@ -1204,6 +1204,10 @@ gfx::Size LayerTreeHostImpl::DeviceViewportSize() const {
return device_viewport_size();
}
+float LayerTreeHostImpl::DeviceScaleFactor() const {
+ return device_scale_factor_;
+}
+
gfx::SizeF LayerTreeHostImpl::VisibleViewportSize() const {
gfx::SizeF dip_size =
gfx::ScaleSize(DeviceViewportSize(), 1.f / device_scale_factor());
@@ -1511,6 +1515,9 @@ void LayerTreeHostImpl::SetDeviceScaleFactor(float device_scale_factor) {
return;
device_scale_factor_ = device_scale_factor;
+ if (renderer_)
+ renderer_->ViewportChanged();
+
UpdateMaxScrollOffset();
SetFullRootLayerDamage();
}
diff --git a/cc/trees/layer_tree_host_impl.h b/cc/trees/layer_tree_host_impl.h
index 57221b2..15cc599 100644
--- a/cc/trees/layer_tree_host_impl.h
+++ b/cc/trees/layer_tree_host_impl.h
@@ -182,6 +182,7 @@ class CC_EXPORT LayerTreeHostImpl
// RendererClient implementation
private:
virtual gfx::Size DeviceViewportSize() const OVERRIDE;
+ virtual float DeviceScaleFactor() const OVERRIDE;
virtual const LayerTreeSettings& Settings() const OVERRIDE;
public:
virtual void DidLoseOutputSurface() OVERRIDE;
diff --git a/cc/trees/layer_tree_host_impl_unittest.cc b/cc/trees/layer_tree_host_impl_unittest.cc
index f0b8c18..6976087 100644
--- a/cc/trees/layer_tree_host_impl_unittest.cc
+++ b/cc/trees/layer_tree_host_impl_unittest.cc
@@ -2662,16 +2662,32 @@ TEST_F(LayerTreeHostImplTest, ViewportCovered) {
class ReshapeTrackerContext: public TestWebGraphicsContext3D {
public:
- ReshapeTrackerContext() : reshape_called_(false) {}
+ ReshapeTrackerContext()
+ : reshape_called_(false),
+ last_reshape_width_(-1),
+ last_reshape_height_(-1),
+ last_reshape_scale_factor_(-1.f) {
+ }
- virtual void reshape(int width, int height) OVERRIDE {
+ virtual void reshapeWithScaleFactor(
+ int width, int height, float scale_factor) OVERRIDE {
reshape_called_ = true;
+ last_reshape_width_ = width;
+ last_reshape_height_ = height;
+ last_reshape_scale_factor_ = scale_factor;
}
bool reshape_called() const { return reshape_called_; }
+ void clear_reshape_called() { reshape_called_ = false; }
+ int last_reshape_width() { return last_reshape_width_; }
+ int last_reshape_height() { return last_reshape_height_; }
+ int last_reshape_scale_factor() { return last_reshape_scale_factor_; }
private:
bool reshape_called_;
+ int last_reshape_width_;
+ int last_reshape_height_;
+ float last_reshape_scale_factor_;
};
class FakeDrawableLayerImpl: public LayerImpl {
@@ -2703,12 +2719,39 @@ TEST_F(LayerTreeHostImplTest, ReshapeNotCalledUntilDraw) {
root->SetDrawsContent(true);
host_impl_->active_tree()->SetRootLayer(root.Pass());
EXPECT_FALSE(reshape_tracker->reshape_called());
+ reshape_tracker->clear_reshape_called();
LayerTreeHostImpl::FrameData frame;
+ host_impl_->SetViewportSize(gfx::Size(10, 10));
+ host_impl_->SetDeviceScaleFactor(1.f);
+ EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
+ host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
+ EXPECT_TRUE(reshape_tracker->reshape_called());
+ EXPECT_EQ(reshape_tracker->last_reshape_width(), 10);
+ EXPECT_EQ(reshape_tracker->last_reshape_height(), 10);
+ EXPECT_EQ(reshape_tracker->last_reshape_scale_factor(), 1.f);
+ host_impl_->DidDrawAllLayers(frame);
+ reshape_tracker->clear_reshape_called();
+
+ host_impl_->SetViewportSize(gfx::Size(20, 30));
EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
EXPECT_TRUE(reshape_tracker->reshape_called());
+ EXPECT_EQ(reshape_tracker->last_reshape_width(), 20);
+ EXPECT_EQ(reshape_tracker->last_reshape_height(), 30);
+ EXPECT_EQ(reshape_tracker->last_reshape_scale_factor(), 1.f);
host_impl_->DidDrawAllLayers(frame);
+ reshape_tracker->clear_reshape_called();
+
+ host_impl_->SetDeviceScaleFactor(2.f);
+ EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect()));
+ host_impl_->DrawLayers(&frame, base::TimeTicks::Now());
+ EXPECT_TRUE(reshape_tracker->reshape_called());
+ EXPECT_EQ(reshape_tracker->last_reshape_width(), 20);
+ EXPECT_EQ(reshape_tracker->last_reshape_height(), 30);
+ EXPECT_EQ(reshape_tracker->last_reshape_scale_factor(), 2.f);
+ host_impl_->DidDrawAllLayers(frame);
+ reshape_tracker->clear_reshape_called();
}
class PartialSwapTrackerContext : public TestWebGraphicsContext3D {
@@ -4506,6 +4549,9 @@ class TestRenderer : public GLRenderer, public RendererClient {
virtual gfx::Size DeviceViewportSize() const OVERRIDE {
return viewport_size_;
}
+ virtual float DeviceScaleFactor() const OVERRIDE {
+ return 1.f;
+ }
virtual const LayerTreeSettings& Settings() const OVERRIDE {
return settings_;
}