Home | History | Annotate | Download | only in layers
      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/ui_resource_layer.h"
      6 
      7 #include "cc/debug/overdraw_metrics.h"
      8 #include "cc/resources/prioritized_resource_manager.h"
      9 #include "cc/resources/resource_provider.h"
     10 #include "cc/resources/resource_update_queue.h"
     11 #include "cc/resources/scoped_ui_resource.h"
     12 #include "cc/scheduler/texture_uploader.h"
     13 #include "cc/test/fake_layer_tree_host.h"
     14 #include "cc/test/fake_layer_tree_host_client.h"
     15 #include "cc/test/fake_output_surface.h"
     16 #include "cc/test/fake_output_surface_client.h"
     17 #include "cc/test/geometry_test_utils.h"
     18 #include "cc/trees/layer_tree_host.h"
     19 #include "cc/trees/occlusion_tracker.h"
     20 #include "cc/trees/single_thread_proxy.h"
     21 #include "testing/gmock/include/gmock/gmock.h"
     22 #include "testing/gtest/include/gtest/gtest.h"
     23 #include "third_party/skia/include/core/SkBitmap.h"
     24 
     25 using ::testing::Mock;
     26 using ::testing::_;
     27 using ::testing::AtLeast;
     28 using ::testing::AnyNumber;
     29 
     30 namespace cc {
     31 namespace {
     32 
     33 class UIResourceLayerTest : public testing::Test {
     34  public:
     35   UIResourceLayerTest() : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {}
     36 
     37  protected:
     38   virtual void SetUp() {
     39     layer_tree_host_ = FakeLayerTreeHost::Create();
     40     layer_tree_host_->InitializeSingleThreaded(&fake_client_);
     41   }
     42 
     43   virtual void TearDown() {
     44     Mock::VerifyAndClearExpectations(layer_tree_host_.get());
     45   }
     46 
     47   scoped_ptr<FakeLayerTreeHost> layer_tree_host_;
     48   FakeLayerTreeHostClient fake_client_;
     49 };
     50 
     51 TEST_F(UIResourceLayerTest, SetBitmap) {
     52   scoped_refptr<UIResourceLayer> test_layer = UIResourceLayer::Create();
     53   ASSERT_TRUE(test_layer.get());
     54   test_layer->SetIsDrawable(true);
     55   test_layer->SetBounds(gfx::Size(100, 100));
     56 
     57   layer_tree_host_->SetRootLayer(test_layer);
     58   Mock::VerifyAndClearExpectations(layer_tree_host_.get());
     59   EXPECT_EQ(test_layer->layer_tree_host(), layer_tree_host_.get());
     60 
     61   layer_tree_host_->InitializeOutputSurfaceIfNeeded();
     62 
     63   ResourceUpdateQueue queue;
     64   OcclusionTracker occlusion_tracker(gfx::Rect(), false);
     65   test_layer->SavePaintProperties();
     66   test_layer->Update(&queue, &occlusion_tracker);
     67 
     68   EXPECT_FALSE(test_layer->DrawsContent());
     69 
     70   SkBitmap bitmap;
     71   bitmap.setConfig(SkBitmap::kARGB_8888_Config, 10, 10);
     72   bitmap.allocPixels();
     73   bitmap.setImmutable();
     74 
     75   test_layer->SetBitmap(bitmap);
     76   test_layer->Update(&queue, &occlusion_tracker);
     77 
     78   EXPECT_TRUE(test_layer->DrawsContent());
     79 }
     80 
     81 TEST_F(UIResourceLayerTest, SetUIResourceId) {
     82   scoped_refptr<UIResourceLayer> test_layer = UIResourceLayer::Create();
     83   ASSERT_TRUE(test_layer.get());
     84   test_layer->SetIsDrawable(true);
     85   test_layer->SetBounds(gfx::Size(100, 100));
     86 
     87   layer_tree_host_->SetRootLayer(test_layer);
     88   Mock::VerifyAndClearExpectations(layer_tree_host_.get());
     89   EXPECT_EQ(test_layer->layer_tree_host(), layer_tree_host_.get());
     90 
     91   layer_tree_host_->InitializeOutputSurfaceIfNeeded();
     92 
     93   ResourceUpdateQueue queue;
     94   OcclusionTracker occlusion_tracker(gfx::Rect(), false);
     95   test_layer->SavePaintProperties();
     96   test_layer->Update(&queue, &occlusion_tracker);
     97 
     98   EXPECT_FALSE(test_layer->DrawsContent());
     99 
    100   SkBitmap bitmap;
    101   bitmap.setConfig(SkBitmap::kARGB_8888_Config, 10, 10);
    102   bitmap.allocPixels();
    103   bitmap.setImmutable();
    104 
    105   scoped_ptr<ScopedUIResource> resource = ScopedUIResource::Create(
    106       layer_tree_host_.get(), UIResourceBitmap(bitmap));
    107   test_layer->SetUIResourceId(resource->id());
    108   test_layer->Update(&queue, &occlusion_tracker);
    109 
    110   EXPECT_TRUE(test_layer->DrawsContent());
    111 }
    112 
    113 }  // namespace
    114 }  // namespace cc
    115