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

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

Issue 1412093006: components: Add Exosphere component. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase on improved shared memory support Created 5 years, 1 month 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/bind.h"
6 #include "components/exo/buffer.h"
7 #include "components/exo/surface.h"
8 #include "components/exo/test/exo_test_base.h"
9 #include "components/exo/test/exo_test_helper.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "third_party/khronos/GLES2/gl2.h"
12 #include "ui/gfx/gpu_memory_buffer.h"
13 #include "ui/views/test/widget_test.h"
14
15 namespace exo {
16 namespace {
17
18 using SurfaceTest = test::ExoTestBase;
19
20 void ReleaseBuffer(int* release_buffer_call_count) {
21 (*release_buffer_call_count)++;
22 }
23
24 TEST_F(SurfaceTest, Attach) {
25 gfx::Size buffer_size(256, 256);
26 scoped_ptr<Buffer> buffer(
27 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size).Pass(),
28 GL_TEXTURE_2D));
29
30 // Set the release callback that will be run when buffer is no longer in use.
31 int release_buffer_call_count = 0;
32 buffer->set_release_callback(
33 base::Bind(&ReleaseBuffer, base::Unretained(&release_buffer_call_count)));
34
35 scoped_ptr<Surface> surface1(new Surface);
36 scoped_ptr<Surface> surface2(new Surface);
37
38 // Attach the buffer to surface1.
39 surface1->Attach(buffer.get(), gfx::Point());
40
41 // Attaching buffer to surface2 when it is already attached to surface1
42 // should fail and buffer should remain attached to surface1.
43 surface2->Attach(buffer.get(), gfx::Point());
44
45 // Attach a null buffer to surface1 before committing it, this should
46 // release the previously attached buffer.
47 surface1->Attach(nullptr, gfx::Point());
48 ASSERT_EQ(release_buffer_call_count, 1);
49 }
50
51 TEST_F(SurfaceTest, Damage) {
52 gfx::Size buffer_size(256, 256);
53 scoped_ptr<Buffer> buffer(
54 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size).Pass(),
55 GL_TEXTURE_2D));
56 scoped_ptr<Surface> surface(new Surface);
57
58 // Attach the buffer to the surface. This will update the pending bounds of
59 // the surface to the buffer size.
60 surface->Attach(buffer.get(), gfx::Point());
61
62 // Mark area inside the bounds of the surface as damaged. This should result
63 // in pending damage.
64 surface->Damage(gfx::Rect(0, 0, 10, 10));
65 EXPECT_TRUE(surface->HasPendingDamageForTesting());
66 }
67
68 void SetFrameTime(base::TimeTicks* result, base::TimeTicks frame_time) {
69 *result = frame_time;
70 }
71
72 TEST_F(SurfaceTest, RequestFrameCallback) {
73 scoped_ptr<Surface> surface(new Surface);
74
75 base::TimeTicks frame_time;
76 surface->RequestFrameCallback(
77 base::Bind(&SetFrameTime, base::Unretained(&frame_time)));
78 surface->Commit();
79
80 // Callback should not run synchronously.
81 EXPECT_TRUE(frame_time.is_null());
82 }
83
84 TEST_F(SurfaceTest, SetOpaqueRegion) {
85 scoped_ptr<Surface> surface(new Surface);
86
87 // Setting a non-empty opaque region should succeed.
88 surface->SetOpaqueRegion(cc::Region(gfx::Rect(0, 0, 256, 256)));
89
90 // Setting an empty opaque region should succeed.
91 surface->SetOpaqueRegion(cc::Region());
92 }
93
94 TEST_F(SurfaceTest, Commit) {
95 scoped_ptr<Surface> surface(new Surface);
96
97 // Calling commit without a buffer should succeed.
98 surface->Commit();
99 }
100
101 } // namespace
102 } // namespace exo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698