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

Side by Side Diff: components/exo/surface_unittest.cc

Issue 2083853002: exo: Recreate Surface resources on context lost. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix deps Created 4 years, 6 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "cc/output/compositor_frame.h"
7 #include "cc/output/delegated_frame_data.h"
8 #include "cc/surfaces/surface.h"
9 #include "cc/surfaces/surface_manager.h"
6 #include "components/exo/buffer.h" 10 #include "components/exo/buffer.h"
7 #include "components/exo/surface.h" 11 #include "components/exo/surface.h"
8 #include "components/exo/test/exo_test_base.h" 12 #include "components/exo/test/exo_test_base.h"
9 #include "components/exo/test/exo_test_helper.h" 13 #include "components/exo/test/exo_test_helper.h"
10 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "ui/aura/env.h"
11 #include "ui/compositor/layer_tree_owner.h" 16 #include "ui/compositor/layer_tree_owner.h"
12 #include "ui/gfx/gpu_memory_buffer.h" 17 #include "ui/gfx/gpu_memory_buffer.h"
13 #include "ui/wm/core/window_util.h" 18 #include "ui/wm/core/window_util.h"
14 19
15 namespace exo { 20 namespace exo {
16 namespace { 21 namespace {
17 22
18 using SurfaceTest = test::ExoTestBase; 23 using SurfaceTest = test::ExoTestBase;
19 24
20 void ReleaseBuffer(int* release_buffer_call_count) { 25 void ReleaseBuffer(int* release_buffer_call_count) {
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 180
176 surface->Attach(buffer.get()); 181 surface->Attach(buffer.get());
177 gfx::Size crop_size(12, 12); 182 gfx::Size crop_size(12, 12);
178 surface->SetCrop(gfx::RectF(gfx::PointF(2.0, 2.0), gfx::SizeF(crop_size))); 183 surface->SetCrop(gfx::RectF(gfx::PointF(2.0, 2.0), gfx::SizeF(crop_size)));
179 surface->Commit(); 184 surface->Commit();
180 EXPECT_EQ(crop_size.ToString(), 185 EXPECT_EQ(crop_size.ToString(),
181 surface->window()->bounds().size().ToString()); 186 surface->window()->bounds().size().ToString());
182 EXPECT_EQ(crop_size.ToString(), surface->content_size().ToString()); 187 EXPECT_EQ(crop_size.ToString(), surface->content_size().ToString());
183 } 188 }
184 189
190 const cc::DelegatedFrameData* GetFrameFromSurface(Surface* surface) {
191 cc::SurfaceId surface_id = surface->surface_id();
192 cc::SurfaceManager* surface_manager =
193 aura::Env::GetInstance()->context_factory()->GetSurfaceManager();
194 const cc::CompositorFrame* frame =
195 surface_manager->GetSurfaceForId(surface_id)->GetEligibleFrame();
196 return frame->delegated_frame_data.get();
197 }
198
185 TEST_F(SurfaceTest, SetBlendMode) { 199 TEST_F(SurfaceTest, SetBlendMode) {
186 gfx::Size buffer_size(1, 1); 200 gfx::Size buffer_size(1, 1);
187 std::unique_ptr<Buffer> buffer( 201 std::unique_ptr<Buffer> buffer(
188 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); 202 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
189 std::unique_ptr<Surface> surface(new Surface); 203 std::unique_ptr<Surface> surface(new Surface);
190 204
191 surface->Attach(buffer.get()); 205 surface->Attach(buffer.get());
192 surface->SetBlendMode(SkXfermode::kSrc_Mode); 206 surface->SetBlendMode(SkXfermode::kSrc_Mode);
193 surface->Commit(); 207 surface->Commit();
194 208
195 EXPECT_TRUE(surface->window()->layer()->fills_bounds_opaquely()); 209 EXPECT_FALSE(surface->window()->layer()->fills_bounds_opaquely());
210
211 const cc::DelegatedFrameData* frame_data = GetFrameFromSurface(surface.get());
212 ASSERT_EQ(1u, frame_data->render_pass_list.size());
213 ASSERT_EQ(1u, frame_data->render_pass_list.back()->quad_list.size());
214 EXPECT_FALSE(frame_data->render_pass_list.back()
215 ->quad_list.back()
216 ->ShouldDrawWithBlending());
reveman 2016/06/23 00:44:39 Thanks for doing this
196 } 217 }
197 218
198 TEST_F(SurfaceTest, SetAlpha) { 219 TEST_F(SurfaceTest, SetAlpha) {
199 gfx::Size buffer_size(1, 1); 220 gfx::Size buffer_size(1, 1);
200 std::unique_ptr<Buffer> buffer( 221 std::unique_ptr<Buffer> buffer(
201 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); 222 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
202 std::unique_ptr<Surface> surface(new Surface); 223 std::unique_ptr<Surface> surface(new Surface);
203 224
204 surface->Attach(buffer.get()); 225 surface->Attach(buffer.get());
205 surface->SetAlpha(0.5f); 226 surface->SetAlpha(0.5f);
206 surface->Commit(); 227 surface->Commit();
207 } 228 }
208 229
209 TEST_F(SurfaceTest, Commit) { 230 TEST_F(SurfaceTest, Commit) {
210 std::unique_ptr<Surface> surface(new Surface); 231 std::unique_ptr<Surface> surface(new Surface);
211 232
212 // Calling commit without a buffer should succeed. 233 // Calling commit without a buffer should succeed.
213 surface->Commit(); 234 surface->Commit();
214 } 235 }
215 236
216 } // namespace 237 } // namespace
217 } // namespace exo 238 } // namespace exo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698