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

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: Release Mailbox if UsingSharedMemoryResources changed in TextureLayer::Update 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"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/synchronization/waitable_event.h" 12 #include "base/synchronization/waitable_event.h"
13 #include "base/threading/thread.h" 13 #include "base/threading/thread.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "cc/layers/solid_color_layer.h" 15 #include "cc/layers/solid_color_layer.h"
16 #include "cc/layers/texture_layer_client.h" 16 #include "cc/layers/texture_layer_client.h"
17 #include "cc/layers/texture_layer_impl.h" 17 #include "cc/layers/texture_layer_impl.h"
18 #include "cc/output/compositor_frame_ack.h" 18 #include "cc/output/compositor_frame_ack.h"
19 #include "cc/output/context_provider.h" 19 #include "cc/output/context_provider.h"
20 #include "cc/resources/resource_update_queue.h"
20 #include "cc/resources/returned_resource.h" 21 #include "cc/resources/returned_resource.h"
21 #include "cc/test/fake_impl_proxy.h" 22 #include "cc/test/fake_impl_proxy.h"
23 #include "cc/test/fake_layer_tree_host.h"
22 #include "cc/test/fake_layer_tree_host_client.h" 24 #include "cc/test/fake_layer_tree_host_client.h"
23 #include "cc/test/fake_layer_tree_host_impl.h" 25 #include "cc/test/fake_layer_tree_host_impl.h"
24 #include "cc/test/fake_output_surface.h" 26 #include "cc/test/fake_output_surface.h"
27 #include "cc/test/fake_proxy.h"
25 #include "cc/test/layer_test_common.h" 28 #include "cc/test/layer_test_common.h"
26 #include "cc/test/layer_tree_test.h" 29 #include "cc/test/layer_tree_test.h"
27 #include "cc/test/test_web_graphics_context_3d.h" 30 #include "cc/test/test_web_graphics_context_3d.h"
28 #include "cc/trees/blocking_task_runner.h" 31 #include "cc/trees/blocking_task_runner.h"
29 #include "cc/trees/layer_tree_host.h" 32 #include "cc/trees/layer_tree_host.h"
30 #include "cc/trees/layer_tree_impl.h" 33 #include "cc/trees/layer_tree_impl.h"
31 #include "cc/trees/single_thread_proxy.h" 34 #include "cc/trees/single_thread_proxy.h"
32 #include "gpu/GLES2/gl2extchromium.h" 35 #include "gpu/GLES2/gl2extchromium.h"
33 #include "testing/gmock/include/gmock/gmock.h" 36 #include "testing/gmock/include/gmock/gmock.h"
34 #include "testing/gtest/include/gtest/gtest.h" 37 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 2136 matching lines...) Expand 10 before | Expand all | Expand 10 after
2171 private: 2174 private:
2172 base::ThreadChecker main_thread_; 2175 base::ThreadChecker main_thread_;
2173 int callback_count_; 2176 int callback_count_;
2174 scoped_refptr<Layer> root_; 2177 scoped_refptr<Layer> root_;
2175 scoped_refptr<TextureLayer> layer_; 2178 scoped_refptr<TextureLayer> layer_;
2176 }; 2179 };
2177 2180
2178 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( 2181 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F(
2179 TextureLayerWithMailboxImplThreadDeleted); 2182 TextureLayerWithMailboxImplThreadDeleted);
2180 2183
2184 class FakeMailboxTextureLayerClient : public TextureLayerClient {
2185 public:
2186 FakeMailboxTextureLayerClient()
2187 : prepare_texture_mailbox_(0), mailbox_released_(0) {}
2188
2189 // TextureLayerClient implementation.
2190 virtual unsigned PrepareTexture() OVERRIDE {
2191 NOTREACHED();
2192 return 0;
2193 }
2194 virtual bool PrepareTextureMailbox(
2195 TextureMailbox* texture_mailbox,
2196 scoped_ptr<SingleReleaseCallback>* release_callback,
2197 bool use_shared_memory) OVERRIDE {
2198 prepare_texture_mailbox_++;
2199 *texture_mailbox = TextureMailbox(
2200 MailboxFromString(std::string(64, '1')), GL_TEXTURE_2D, 0);
2201 *release_callback = SingleReleaseCallback::Create(
2202 base::Bind(&FakeMailboxTextureLayerClient::MailboxReleased,
2203 base::Unretained(this)));
2204 return true;
2205 }
2206
2207 void MailboxReleased(uint32 sync_point, bool lost_resource) {
2208 mailbox_released_++;
2209 }
2210
2211 int prepare_texture_mailbox() { return prepare_texture_mailbox_; }
2212 int mailbox_released() { return mailbox_released_; }
2213
2214 private:
2215 int prepare_texture_mailbox_;
2216 int mailbox_released_;
2217 };
2218
2219 TEST(TextureLayerUnittest, ReleaseMailboxOnRendererCapabilityChange) {
2220 FakeMailboxTextureLayerClient client;
2221 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
2222 host->InitializeForTesting(scoped_ptr<Proxy>(new FakeProxy));
2223 FakeProxy* fake_proxy = static_cast<FakeProxy*>(host->proxy());
2224
2225 scoped_refptr<TextureLayer> test_layer =
2226 TextureLayer::CreateForMailbox(&client);
2227 test_layer->SetLayerTreeHost(host.get());
2228
2229 fake_proxy->GetRendererCapabilities().using_shared_memory_resources = false;
2230 scoped_ptr<ResourceUpdateQueue> queue =
2231 make_scoped_ptr(new ResourceUpdateQueue);
2232 test_layer->SavePaintProperties();
2233 EXPECT_TRUE(test_layer->Update(queue.get(), NULL));
2234 EXPECT_EQ(1, client.prepare_texture_mailbox());
2235 EXPECT_EQ(0, client.mailbox_released());
2236
2237 // Update when using_shared_memory_resources changed. Should release old
2238 // mailbox back to client, and acquire a new one.
2239 fake_proxy->GetRendererCapabilities().using_shared_memory_resources = true;
2240 EXPECT_TRUE(test_layer->Update(queue.get(), NULL));
2241 EXPECT_EQ(2, client.prepare_texture_mailbox());
2242 EXPECT_EQ(1, client.mailbox_released());
2243
2244 test_layer->SetLayerTreeHost(NULL);
2245 }
2246
2181 } // namespace 2247 } // namespace
2182 } // namespace cc 2248 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698