Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(182)

Side by Side Diff: cc/layers/texture_layer_unittest.cc

Issue 151093005: cc: Update Main RendererCapabilities on DeferredInitialize (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: with tests Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/layers/texture_layer.h" 5 #include "cc/layers/texture_layer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 root_->SetBounds(bounds); 788 root_->SetBounds(bounds);
789 789
790 layer_ = TextureLayer::CreateForMailbox(NULL); 790 layer_ = TextureLayer::CreateForMailbox(NULL);
791 layer_->SetIsDrawable(true); 791 layer_->SetIsDrawable(true);
792 layer_->SetAnchorPoint(gfx::PointF()); 792 layer_->SetAnchorPoint(gfx::PointF());
793 layer_->SetBounds(bounds); 793 layer_->SetBounds(bounds);
794 794
795 root_->AddChild(layer_); 795 root_->AddChild(layer_);
796 layer_tree_host()->SetRootLayer(root_); 796 layer_tree_host()->SetRootLayer(root_);
797 layer_tree_host()->SetViewportSize(bounds); 797 layer_tree_host()->SetViewportSize(bounds);
798 SetMailbox('1');
799 EXPECT_EQ(0, callback_count_);
800
801 // Case #1: change mailbox before the commit. The old mailbox should be
802 // released immediately.
803 SetMailbox('2');
804 EXPECT_EQ(1, callback_count_);
805 PostSetNeedsCommitToMainThread(); 798 PostSetNeedsCommitToMainThread();
806 } 799 }
807 800
808 virtual void DidCommit() OVERRIDE { 801 virtual void DidCommit() OVERRIDE {
809 ++commit_count_; 802 ++commit_count_;
810 switch (commit_count_) { 803 switch (commit_count_) {
811 case 1: 804 case 1:
805 // First commit from setting up tree. Nothing to check.
806 SetMailbox('1');
807 EXPECT_EQ(0, callback_count_);
808 break;
809 case 2:
812 // Case #2: change mailbox after the commit (and draw), where the 810 // Case #2: change mailbox after the commit (and draw), where the
813 // layer draws. The old mailbox should be released during the next 811 // layer draws. The old mailbox should be released during the next
814 // commit. 812 // commit.
815 SetMailbox('3'); 813 SetMailbox('2');
814 EXPECT_EQ(0, callback_count_);
815 break;
816 case 3:
816 EXPECT_EQ(1, callback_count_); 817 EXPECT_EQ(1, callback_count_);
817 break;
818 case 2:
819 EXPECT_EQ(2, callback_count_);
820 // Case #3: change mailbox when the layer doesn't draw. The old 818 // Case #3: change mailbox when the layer doesn't draw. The old
821 // mailbox should be released during the next commit. 819 // mailbox should be released during the next commit.
822 layer_->SetBounds(gfx::Size()); 820 layer_->SetBounds(gfx::Size());
823 SetMailbox('4'); 821 SetMailbox('3');
824 break; 822 break;
825 case 3: 823 case 4:
826 EXPECT_EQ(3, callback_count_); 824 EXPECT_EQ(2, callback_count_);
827 // Case #4: release mailbox that was committed but never drawn. The 825 // Case #4: release mailbox that was committed but never drawn. The
828 // old mailbox should be released during the next commit. 826 // old mailbox should be released during the next commit.
829 layer_->SetTextureMailbox(TextureMailbox(), 827 layer_->SetTextureMailbox(TextureMailbox(),
830 scoped_ptr<SingleReleaseCallback>()); 828 scoped_ptr<SingleReleaseCallback>());
831 break; 829 break;
832 case 4: 830 case 5:
833 if (layer_tree_host()->settings().impl_side_painting) { 831 if (layer_tree_host()->settings().impl_side_painting) {
834 // With impl painting, the texture mailbox will still be on the impl 832 // With impl painting, the texture mailbox will still be on the impl
835 // thread when the commit finishes, because the layer is not drawble 833 // thread when the commit finishes, because the layer is not drawble
836 // when it has no texture mailbox, and thus does not block the commit 834 // when it has no texture mailbox, and thus does not block the commit
837 // on activation. So, we wait for activation. 835 // on activation. So, we wait for activation.
838 // TODO(danakj): fix this. crbug.com/277953 836 // TODO(danakj): fix this. crbug.com/277953
839 layer_tree_host()->SetNeedsCommit(); 837 layer_tree_host()->SetNeedsCommit();
840 break; 838 break;
841 } else { 839 } else {
842 ++commit_count_; 840 ++commit_count_;
843 } 841 }
844 case 5: 842 case 6:
845 EXPECT_EQ(4, callback_count_); 843 EXPECT_EQ(3, callback_count_);
846 // Restore a mailbox for the next step. 844 // Restore a mailbox for the next step.
847 SetMailbox('5'); 845 SetMailbox('4');
848 break; 846 break;
849 case 6: 847 case 7:
850 // Case #5: remove layer from tree. Callback should *not* be called, the 848 // Case #5: remove layer from tree. Callback should *not* be called, the
851 // mailbox is returned to the main thread. 849 // mailbox is returned to the main thread.
852 EXPECT_EQ(4, callback_count_); 850 EXPECT_EQ(3, callback_count_);
853 layer_->RemoveFromParent(); 851 layer_->RemoveFromParent();
854 break; 852 break;
855 case 7: 853 case 8:
856 if (layer_tree_host()->settings().impl_side_painting) { 854 if (layer_tree_host()->settings().impl_side_painting) {
857 // With impl painting, the texture mailbox will still be on the impl 855 // With impl painting, the texture mailbox will still be on the impl
858 // thread when the commit finishes, because the layer is not around to 856 // thread when the commit finishes, because the layer is not around to
859 // block the commit on activation anymore. So, we wait for activation. 857 // block the commit on activation anymore. So, we wait for activation.
860 // TODO(danakj): fix this. crbug.com/277953 858 // TODO(danakj): fix this. crbug.com/277953
861 layer_tree_host()->SetNeedsCommit(); 859 layer_tree_host()->SetNeedsCommit();
862 break; 860 break;
863 } else { 861 } else {
864 ++commit_count_; 862 ++commit_count_;
865 } 863 }
866 case 8: 864 case 9:
867 EXPECT_EQ(4, callback_count_); 865 EXPECT_EQ(3, callback_count_);
868 // Resetting the mailbox will call the callback now. 866 // Resetting the mailbox will call the callback now.
869 layer_->SetTextureMailbox(TextureMailbox(), 867 layer_->SetTextureMailbox(TextureMailbox(),
870 scoped_ptr<SingleReleaseCallback>()); 868 scoped_ptr<SingleReleaseCallback>());
871 EXPECT_EQ(5, callback_count_); 869 EXPECT_EQ(4, callback_count_);
872 EndTest(); 870 EndTest();
873 break; 871 break;
874 default: 872 default:
875 NOTREACHED(); 873 NOTREACHED();
876 break; 874 break;
877 } 875 }
878 } 876 }
879 877
880 virtual void AfterTest() OVERRIDE {} 878 virtual void AfterTest() OVERRIDE {}
881 879
(...skipping 982 matching lines...) Expand 10 before | Expand all | Expand 10 after
1864 // Used on the main thread. 1862 // Used on the main thread.
1865 bool mailbox_changed_; 1863 bool mailbox_changed_;
1866 TextureMailbox mailbox_; 1864 TextureMailbox mailbox_;
1867 int mailbox_returned_; 1865 int mailbox_returned_;
1868 int prepare_called_; 1866 int prepare_called_;
1869 int commit_count_; 1867 int commit_count_;
1870 }; 1868 };
1871 1869
1872 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerChangeInvisibleMailboxTest); 1870 SINGLE_AND_MULTI_THREAD_TEST_F(TextureLayerChangeInvisibleMailboxTest);
1873 1871
1872 class TrackMailboxReleaseTextureHelper {
1873 public:
1874 TrackMailboxReleaseTextureHelper()
1875 : mailbox_id_(0),
1876 last_released_mailbox_(0) {}
1877
1878 void ReleaseCallback(int mailbox_id, uint32 sync_point, bool lost_resource) {
1879 last_released_mailbox_++;
1880 EXPECT_EQ(last_released_mailbox_, mailbox_id);
1881 }
1882
1883 void SetNextMailbox(TextureLayer* layer) {
1884 mailbox_id_++;
1885
1886 TextureMailbox mailbox = TextureMailbox(
1887 MailboxFromString(std::string(mailbox_id_, 'a')), GL_TEXTURE_2D, 0);
1888 scoped_ptr<SingleReleaseCallback> release_callback =
1889 SingleReleaseCallback::Create(
1890 base::Bind(&TrackMailboxReleaseTextureHelper::ReleaseCallback,
1891 base::Unretained(this),
1892 mailbox_id_));
1893 layer->SetTextureMailbox(mailbox, release_callback.Pass());
1894 }
1895
1896 int last_released_mailbox() { return last_released_mailbox_; }
1897
1898 private:
1899 int mailbox_id_;
1900 int last_released_mailbox_;
1901 };
1902
1903 TEST(TextureLayerUnitTest, ReleaseMailboxOnReset) {
1904 TrackMailboxReleaseTextureHelper helper;
1905 scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox(NULL);
1906
1907 // Set first mailbox.
1908 helper.SetNextMailbox(test_layer.get());
1909 EXPECT_EQ(0, helper.last_released_mailbox());
1910
1911 // Set second mailbox. First should be released immediately.
1912 helper.SetNextMailbox(test_layer.get());
1913 EXPECT_EQ(1, helper.last_released_mailbox());
1914
1915 test_layer = NULL;
1916 EXPECT_EQ(2, helper.last_released_mailbox());
1917 }
1918
1919 TEST(TextureLayerUnitTest, ReleaseMailboxRendererCapChange) {
1920 TrackMailboxReleaseTextureHelper helper;
1921 scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox(NULL);
1922
1923 helper.SetNextMailbox(test_layer.get());
1924 EXPECT_EQ(0, helper.last_released_mailbox());
1925
1926 test_layer->OnOutputSurfaceCreated();
1927 helper.SetNextMailbox(test_layer.get());
1928 EXPECT_EQ(1, helper.last_released_mailbox());
1929 }
1930
1874 // Test that TextureLayerImpl::ReleaseResources can be called which releases 1931 // Test that TextureLayerImpl::ReleaseResources can be called which releases
1875 // the mailbox back to TextureLayerClient. 1932 // the mailbox back to TextureLayerClient.
1876 class TextureLayerReleaseResourcesBase 1933 class TextureLayerReleaseResourcesBase
1877 : public LayerTreeTest, 1934 : public LayerTreeTest,
1878 public TextureLayerClient { 1935 public TextureLayerClient {
1879 public: 1936 public:
1880 // TextureLayerClient implementation. 1937 // TextureLayerClient implementation.
1881 virtual unsigned PrepareTexture() OVERRIDE { 1938 virtual unsigned PrepareTexture() OVERRIDE {
1882 NOTREACHED(); 1939 NOTREACHED();
1883 return 0; 1940 return 0;
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
2173 int callback_count_; 2230 int callback_count_;
2174 scoped_refptr<Layer> root_; 2231 scoped_refptr<Layer> root_;
2175 scoped_refptr<TextureLayer> layer_; 2232 scoped_refptr<TextureLayer> layer_;
2176 }; 2233 };
2177 2234
2178 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( 2235 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F(
2179 TextureLayerWithMailboxImplThreadDeleted); 2236 TextureLayerWithMailboxImplThreadDeleted);
2180 2237
2181 } // namespace 2238 } // namespace
2182 } // namespace cc 2239 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698