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

Side by Side Diff: cc/trees/layer_tree_host_unittest_context.cc

Issue 20185002: ContextProvider in OutputSurface (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: contextprovider: don't access Context3d() in OutputSurface contructors, it's not bound yet Created 7 years, 4 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
« no previous file with comments | « cc/trees/layer_tree_host_unittest.cc ('k') | cc/trees/layer_tree_host_unittest_delegated.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/trees/layer_tree_host.h" 5 #include "cc/trees/layer_tree_host.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "cc/debug/test_context_provider.h" 8 #include "cc/debug/test_context_provider.h"
9 #include "cc/debug/test_web_graphics_context_3d.h" 9 #include "cc/debug/test_web_graphics_context_3d.h"
10 #include "cc/layers/content_layer.h" 10 #include "cc/layers/content_layer.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 // can be changed if needed to make this pass with future changes. 101 // can be changed if needed to make this pass with future changes.
102 context3d_->set_times_make_current_succeeds(2); 102 context3d_->set_times_make_current_succeeds(2);
103 ExpectCreateToFail(); 103 ExpectCreateToFail();
104 } else if (times_to_lose_on_create_) { 104 } else if (times_to_lose_on_create_) {
105 --times_to_lose_on_create_; 105 --times_to_lose_on_create_;
106 LoseContext(); 106 LoseContext();
107 ExpectCreateToFail(); 107 ExpectCreateToFail();
108 } 108 }
109 109
110 if (delegating_renderer()) { 110 if (delegating_renderer()) {
111 return FakeOutputSurface::CreateDelegating3d( 111 return FakeOutputSurface::CreateDelegating3d(context3d.Pass())
112 context3d.PassAs<WebGraphicsContext3D>()).PassAs<OutputSurface>(); 112 .PassAs<OutputSurface>();
113 } 113 }
114 return FakeOutputSurface::Create3d( 114 return FakeOutputSurface::Create3d(context3d.Pass())
115 context3d.PassAs<WebGraphicsContext3D>()).PassAs<OutputSurface>(); 115 .PassAs<OutputSurface>();
116 } 116 }
117 117
118 scoped_ptr<TestWebGraphicsContext3D> CreateOffscreenContext3d() { 118 scoped_ptr<TestWebGraphicsContext3D> CreateOffscreenContext3d() {
119 if (!context3d_) 119 if (!context3d_)
120 return scoped_ptr<TestWebGraphicsContext3D>(); 120 return scoped_ptr<TestWebGraphicsContext3D>();
121 121
122 ++times_offscreen_created_; 122 ++times_offscreen_created_;
123 123
124 if (times_to_fail_create_offscreen_) { 124 if (times_to_fail_create_offscreen_) {
125 --times_to_fail_create_offscreen_; 125 --times_to_fail_create_offscreen_;
126 ExpectCreateToFail(); 126 ExpectCreateToFail();
127 return scoped_ptr<TestWebGraphicsContext3D>(); 127 return scoped_ptr<TestWebGraphicsContext3D>();
128 } 128 }
129 129
130 scoped_ptr<TestWebGraphicsContext3D> offscreen_context3d = 130 scoped_ptr<TestWebGraphicsContext3D> offscreen_context3d =
131 TestWebGraphicsContext3D::Create().Pass(); 131 TestWebGraphicsContext3D::Create().Pass();
132 DCHECK(offscreen_context3d); 132 DCHECK(offscreen_context3d);
133 context3d_->add_share_group_context(offscreen_context3d.get()); 133 context3d_->add_share_group_context(offscreen_context3d.get());
134 134
135 return offscreen_context3d.Pass(); 135 return offscreen_context3d.Pass();
136 } 136 }
137 137
138 virtual scoped_refptr<cc::ContextProvider> 138 virtual scoped_refptr<cc::ContextProvider>
139 OffscreenContextProviderForMainThread() OVERRIDE { 139 OffscreenContextProviderForMainThread() OVERRIDE {
140 DCHECK(!HasImplThread()); 140 DCHECK(!HasImplThread());
141 141
142 if (!offscreen_contexts_main_thread_.get() || 142 if (!offscreen_contexts_main_thread_.get() ||
143 offscreen_contexts_main_thread_->DestroyedOnMainThread()) { 143 offscreen_contexts_main_thread_->DestroyedOnMainThread()) {
144 offscreen_contexts_main_thread_ = TestContextProvider::Create( 144 offscreen_contexts_main_thread_ =
145 base::Bind(&LayerTreeHostContextTest::CreateOffscreenContext3d, 145 TestContextProvider::Create(
146 base::Unretained(this))); 146 base::Bind(&LayerTreeHostContextTest::CreateOffscreenContext3d,
147 if (offscreen_contexts_main_thread_.get() && 147 base::Unretained(this)));
148 if (offscreen_contexts_main_thread_ &&
148 !offscreen_contexts_main_thread_->BindToCurrentThread()) 149 !offscreen_contexts_main_thread_->BindToCurrentThread())
149 offscreen_contexts_main_thread_ = NULL; 150 offscreen_contexts_main_thread_ = NULL;
150 } 151 }
151 return offscreen_contexts_main_thread_; 152 return offscreen_contexts_main_thread_;
152 } 153 }
153 154
154 virtual scoped_refptr<cc::ContextProvider> 155 virtual scoped_refptr<cc::ContextProvider>
155 OffscreenContextProviderForCompositorThread() OVERRIDE { 156 OffscreenContextProviderForCompositorThread() OVERRIDE {
156 DCHECK(HasImplThread()); 157 DCHECK(HasImplThread());
157 158
158 if (!offscreen_contexts_compositor_thread_.get() || 159 if (!offscreen_contexts_compositor_thread_.get() ||
159 offscreen_contexts_compositor_thread_->DestroyedOnMainThread()) { 160 offscreen_contexts_compositor_thread_->DestroyedOnMainThread()) {
160 offscreen_contexts_compositor_thread_ = TestContextProvider::Create( 161 offscreen_contexts_compositor_thread_ =
161 base::Bind(&LayerTreeHostContextTest::CreateOffscreenContext3d, 162 TestContextProvider::Create(
162 base::Unretained(this))); 163 base::Bind(&LayerTreeHostContextTest::CreateOffscreenContext3d,
164 base::Unretained(this)));
163 } 165 }
164 return offscreen_contexts_compositor_thread_; 166 return offscreen_contexts_compositor_thread_;
165 } 167 }
166 168
167 virtual bool PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, 169 virtual bool PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
168 LayerTreeHostImpl::FrameData* frame, 170 LayerTreeHostImpl::FrameData* frame,
169 bool result) OVERRIDE { 171 bool result) OVERRIDE {
170 EXPECT_TRUE(result); 172 EXPECT_TRUE(result);
171 if (!times_to_lose_during_draw_) 173 if (!times_to_lose_during_draw_)
172 return result; 174 return result;
(...skipping 1039 matching lines...) Expand 10 before | Expand all | Expand 10 after
1212 1214
1213 virtual void BeginTest() OVERRIDE { 1215 virtual void BeginTest() OVERRIDE {
1214 context_should_support_io_surface_ = true; 1216 context_should_support_io_surface_ = true;
1215 PostSetNeedsCommitToMainThread(); 1217 PostSetNeedsCommitToMainThread();
1216 } 1218 }
1217 1219
1218 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { 1220 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
1219 LayerTreeHostContextTest::CommitCompleteOnThread(host_impl); 1221 LayerTreeHostContextTest::CommitCompleteOnThread(host_impl);
1220 1222
1221 ResourceProvider* resource_provider = host_impl->resource_provider(); 1223 ResourceProvider* resource_provider = host_impl->resource_provider();
1224 ContextProvider* context_provider =
1225 host_impl->output_surface()->context_provider();
1226
1227 DCHECK(context_provider);
1222 1228
1223 if (host_impl->active_tree()->source_frame_number() == 0) { 1229 if (host_impl->active_tree()->source_frame_number() == 0) {
1224 // Set up impl resources on the first commit. 1230 // Set up impl resources on the first commit.
1225 1231
1226 scoped_ptr<TestRenderPass> pass_for_quad = TestRenderPass::Create(); 1232 scoped_ptr<TestRenderPass> pass_for_quad = TestRenderPass::Create();
1227 pass_for_quad->SetNew( 1233 pass_for_quad->SetNew(
1228 // AppendOneOfEveryQuadType() makes a RenderPass quad with this id. 1234 // AppendOneOfEveryQuadType() makes a RenderPass quad with this id.
1229 RenderPass::Id(1, 1), 1235 RenderPass::Id(1, 1),
1230 gfx::Rect(0, 0, 10, 10), 1236 gfx::Rect(0, 0, 10, 10),
1231 gfx::Rect(0, 0, 10, 10), 1237 gfx::Rect(0, 0, 10, 10),
(...skipping 16 matching lines...) Expand all
1248 static_cast<FakeDelegatedRendererLayerImpl*>( 1254 static_cast<FakeDelegatedRendererLayerImpl*>(
1249 host_impl->active_tree()->root_layer()->children()[0]); 1255 host_impl->active_tree()->root_layer()->children()[0]);
1250 delegated_impl->SetFrameDataForRenderPasses(&pass_list); 1256 delegated_impl->SetFrameDataForRenderPasses(&pass_list);
1251 EXPECT_TRUE(pass_list.empty()); 1257 EXPECT_TRUE(pass_list.empty());
1252 1258
1253 // Third child is the texture layer. 1259 // Third child is the texture layer.
1254 TextureLayerImpl* texture_impl = 1260 TextureLayerImpl* texture_impl =
1255 static_cast<TextureLayerImpl*>( 1261 static_cast<TextureLayerImpl*>(
1256 host_impl->active_tree()->root_layer()->children()[2]); 1262 host_impl->active_tree()->root_layer()->children()[2]);
1257 texture_impl->set_texture_id( 1263 texture_impl->set_texture_id(
1258 resource_provider->GraphicsContext3D()->createTexture()); 1264 context_provider->Context3d()->createTexture());
1259 1265
1260 DCHECK(resource_provider->GraphicsContext3D());
1261 ResourceProvider::ResourceId texture = resource_provider->CreateResource( 1266 ResourceProvider::ResourceId texture = resource_provider->CreateResource(
1262 gfx::Size(4, 4), 1267 gfx::Size(4, 4),
1263 resource_provider->default_resource_type(), 1268 resource_provider->default_resource_type(),
1264 ResourceProvider::TextureUsageAny); 1269 ResourceProvider::TextureUsageAny);
1265 ResourceProvider::ScopedWriteLockGL lock(resource_provider, texture); 1270 ResourceProvider::ScopedWriteLockGL lock(resource_provider, texture);
1266 1271
1267 gpu::Mailbox mailbox; 1272 gpu::Mailbox mailbox;
1268 resource_provider->GraphicsContext3D()->genMailboxCHROMIUM(mailbox.name); 1273 context_provider->Context3d()->genMailboxCHROMIUM(mailbox.name);
1269 unsigned sync_point = 1274 unsigned sync_point = context_provider->Context3d()->insertSyncPoint();
1270 resource_provider->GraphicsContext3D()->insertSyncPoint();
1271 1275
1272 color_video_frame_ = VideoFrame::CreateColorFrame( 1276 color_video_frame_ = VideoFrame::CreateColorFrame(
1273 gfx::Size(4, 4), 0x80, 0x80, 0x80, base::TimeDelta()); 1277 gfx::Size(4, 4), 0x80, 0x80, 0x80, base::TimeDelta());
1274 hw_video_frame_ = VideoFrame::WrapNativeTexture( 1278 hw_video_frame_ = VideoFrame::WrapNativeTexture(
1275 new VideoFrame::MailboxHolder( 1279 new VideoFrame::MailboxHolder(
1276 mailbox, 1280 mailbox,
1277 sync_point, 1281 sync_point,
1278 VideoFrame::MailboxHolder::TextureNoLongerNeededCallback()), 1282 VideoFrame::MailboxHolder::TextureNoLongerNeededCallback()),
1279 GL_TEXTURE_2D, 1283 GL_TEXTURE_2D,
1280 gfx::Size(4, 4), gfx::Rect(0, 0, 4, 4), gfx::Size(4, 4), 1284 gfx::Size(4, 4), gfx::Rect(0, 0, 4, 4), gfx::Size(4, 4),
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after
1896 RunTest(true, false, true); 1900 RunTest(true, false, true);
1897 } 1901 }
1898 1902
1899 TEST_F(UIResourceLostBeforeActivateTree, 1903 TEST_F(UIResourceLostBeforeActivateTree,
1900 RunMultiThread_DelegatingRenderer_ImplSidePaint) { 1904 RunMultiThread_DelegatingRenderer_ImplSidePaint) {
1901 RunTest(true, true, true); 1905 RunTest(true, true, true);
1902 } 1906 }
1903 1907
1904 } // namespace 1908 } // namespace
1905 } // namespace cc 1909 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_unittest.cc ('k') | cc/trees/layer_tree_host_unittest_delegated.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698