picture_image_layer_impl_unittest.cc revision c2e0dbddbe15c98d52c4786dac06cb8952a8ae6d
1// Copyright 2013 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "cc/layers/picture_image_layer_impl.h" 6 7#include "cc/test/fake_impl_proxy.h" 8#include "cc/test/fake_layer_tree_host_impl.h" 9#include "cc/test/fake_output_surface.h" 10#include "cc/test/fake_picture_layer_tiling_client.h" 11#include "cc/test/impl_side_painting_settings.h" 12#include "cc/trees/layer_tree_impl.h" 13#include "testing/gtest/include/gtest/gtest.h" 14 15namespace cc { 16namespace { 17 18class TestablePictureImageLayerImpl : public PictureImageLayerImpl { 19 public: 20 TestablePictureImageLayerImpl(LayerTreeImpl* tree_impl, int id) 21 : PictureImageLayerImpl(tree_impl, id) { 22 } 23 friend class PictureImageLayerImplTest; 24}; 25 26class PictureImageLayerImplTest : public testing::Test { 27 public: 28 PictureImageLayerImplTest() 29 : host_impl_(ImplSidePaintingSettings(), &proxy_) { 30 tiling_client_.SetTileSize(ImplSidePaintingSettings().default_tile_size); 31 host_impl_.CreatePendingTree(); 32 host_impl_.InitializeRenderer(CreateFakeOutputSurface()); 33 } 34 35 scoped_ptr<TestablePictureImageLayerImpl> CreateLayer(int id) { 36 TestablePictureImageLayerImpl* layer = 37 new TestablePictureImageLayerImpl(host_impl_.pending_tree(), id); 38 layer->SetBounds(gfx::Size(100, 200)); 39 layer->tilings_.reset(new PictureLayerTilingSet(&tiling_client_, 40 layer->bounds())); 41 layer->pile_ = tiling_client_.pile(); 42 return make_scoped_ptr(layer); 43 } 44 45 void UpdateDrawProperties() { 46 host_impl_.pending_tree()->UpdateDrawProperties(); 47 } 48 49 private: 50 FakeImplProxy proxy_; 51 FakeLayerTreeHostImpl host_impl_; 52 FakePictureLayerTilingClient tiling_client_; 53}; 54 55TEST_F(PictureImageLayerImplTest, CalculateContentsScale) { 56 scoped_ptr<TestablePictureImageLayerImpl> layer(CreateLayer(1)); 57 layer->SetDrawsContent(true); 58 59 float contents_scale_x; 60 float contents_scale_y; 61 gfx::Size content_bounds; 62 layer->CalculateContentsScale(2.f, false, 63 &contents_scale_x, &contents_scale_y, 64 &content_bounds); 65 EXPECT_FLOAT_EQ(1.f, contents_scale_x); 66 EXPECT_FLOAT_EQ(1.f, contents_scale_y); 67 EXPECT_EQ(layer->bounds(), content_bounds); 68} 69 70TEST_F(PictureImageLayerImplTest, AreVisibleResourcesReady) { 71 scoped_ptr<TestablePictureImageLayerImpl> layer(CreateLayer(1)); 72 layer->SetBounds(gfx::Size(100, 200)); 73 layer->SetDrawsContent(true); 74 75 UpdateDrawProperties(); 76 77 float contents_scale_x; 78 float contents_scale_y; 79 gfx::Size content_bounds; 80 layer->CalculateContentsScale(2.f, false, 81 &contents_scale_x, &contents_scale_y, 82 &content_bounds); 83 layer->UpdateTilePriorities(); 84 85 EXPECT_TRUE(layer->AreVisibleResourcesReady()); 86} 87 88} // namespace 89} // namespace cc 90