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

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

Issue 2868473002: Implement aura::Window::CreateCompositorFrameSink() (Closed)
Patch Set: Address review issues Created 3 years, 7 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
« no previous file with comments | « components/exo/buffer.cc ('k') | components/exo/compositor_frame_sink.h » ('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 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 <GLES2/gl2extchromium.h> 5 #include <GLES2/gl2extchromium.h>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "cc/output/context_provider.h" 8 #include "cc/output/context_provider.h"
9 #include "cc/resources/single_release_callback.h" 9 #include "cc/resources/single_release_callback.h"
10 #include "components/exo/buffer.h" 10 #include "components/exo/buffer.h"
(...skipping 15 matching lines...) Expand all
26 void Release(int* release_call_count) { 26 void Release(int* release_call_count) {
27 (*release_call_count)++; 27 (*release_call_count)++;
28 } 28 }
29 29
30 TEST_F(BufferTest, ReleaseCallback) { 30 TEST_F(BufferTest, ReleaseCallback) {
31 gfx::Size buffer_size(256, 256); 31 gfx::Size buffer_size(256, 256);
32 std::unique_ptr<Buffer> buffer( 32 std::unique_ptr<Buffer> buffer(
33 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); 33 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
34 std::unique_ptr<Surface> surface(new Surface); 34 std::unique_ptr<Surface> surface(new Surface);
35 const cc::FrameSinkId arbitrary_frame_sink_id(1, 1); 35 const cc::FrameSinkId arbitrary_frame_sink_id(1, 1);
36 scoped_refptr<CompositorFrameSinkHolder> compositor_frame_sink_holder = 36 CompositorFrameSinkHolder* compositor_frame_sink_holder =
37 new CompositorFrameSinkHolder(surface.get(), arbitrary_frame_sink_id, 37 surface->compositor_frame_sink_holder();
38 aura::Env::GetInstance()
39 ->context_factory_private()
40 ->GetSurfaceManager());
41 38
42 // Set the release callback. 39 // Set the release callback.
43 int release_call_count = 0; 40 int release_call_count = 0;
44 buffer->set_release_callback( 41 buffer->set_release_callback(
45 base::Bind(&Release, base::Unretained(&release_call_count))); 42 base::Bind(&Release, base::Unretained(&release_call_count)));
46 43
47 buffer->OnAttach(); 44 buffer->OnAttach();
48 cc::TransferableResource resource; 45 cc::TransferableResource resource;
49 // Produce a transferable resource for the contents of the buffer. 46 // Produce a transferable resource for the contents of the buffer.
50 bool rv = buffer->ProduceTransferableResource( 47 bool rv = buffer->ProduceTransferableResource(compositor_frame_sink_holder, 0,
51 compositor_frame_sink_holder.get(), 0, false, true, &resource); 48 false, true, &resource);
52 ASSERT_TRUE(rv); 49 ASSERT_TRUE(rv);
53 50
54 // Release buffer. 51 // Release buffer.
55 cc::ReturnedResource returned_resource; 52 cc::ReturnedResource returned_resource;
56 returned_resource.id = resource.id; 53 returned_resource.id = resource.id;
57 returned_resource.sync_token = resource.mailbox_holder.sync_token; 54 returned_resource.sync_token = resource.mailbox_holder.sync_token;
58 returned_resource.lost = false; 55 returned_resource.lost = false;
59 cc::ReturnedResourceArray resources = {returned_resource}; 56 cc::ReturnedResourceArray resources = {returned_resource};
60 compositor_frame_sink_holder->ReclaimResources(resources); 57 compositor_frame_sink_holder->ReclaimResources(resources);
61 58
62 RunAllPendingInMessageLoop(); 59 RunAllPendingInMessageLoop();
63 ASSERT_EQ(release_call_count, 0); 60 ASSERT_EQ(release_call_count, 0);
64 61
65 buffer->OnDetach(); 62 buffer->OnDetach();
66 63
67 // Release() should have been called exactly once. 64 // Release() should have been called exactly once.
68 ASSERT_EQ(release_call_count, 1); 65 ASSERT_EQ(release_call_count, 1);
69 } 66 }
70 67
71 TEST_F(BufferTest, IsLost) { 68 TEST_F(BufferTest, IsLost) {
72 gfx::Size buffer_size(256, 256); 69 gfx::Size buffer_size(256, 256);
73 std::unique_ptr<Buffer> buffer( 70 std::unique_ptr<Buffer> buffer(
74 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); 71 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
75 const cc::FrameSinkId arbitrary_frame_sink_id(1, 1); 72 const cc::FrameSinkId arbitrary_frame_sink_id(1, 1);
76 std::unique_ptr<Surface> surface(new Surface); 73 std::unique_ptr<Surface> surface(new Surface);
77 scoped_refptr<CompositorFrameSinkHolder> compositor_frame_sink_holder = 74 CompositorFrameSinkHolder* compositor_frame_sink_holder =
78 new CompositorFrameSinkHolder(surface.get(), arbitrary_frame_sink_id, 75 surface->compositor_frame_sink_holder();
79 aura::Env::GetInstance()
80 ->context_factory_private()
81 ->GetSurfaceManager());
82 cc::ResourceId resource_id = 0; 76 cc::ResourceId resource_id = 0;
83 77
84 buffer->OnAttach(); 78 buffer->OnAttach();
85 // Acquire a texture transferable resource for the contents of the buffer. 79 // Acquire a texture transferable resource for the contents of the buffer.
86 cc::TransferableResource resource; 80 cc::TransferableResource resource;
87 bool rv = buffer->ProduceTransferableResource( 81 bool rv = buffer->ProduceTransferableResource(
88 compositor_frame_sink_holder.get(), resource_id, false, true, &resource); 82 compositor_frame_sink_holder, resource_id, false, true, &resource);
89 ASSERT_TRUE(rv); 83 ASSERT_TRUE(rv);
90 84
91 scoped_refptr<cc::ContextProvider> context_provider = 85 scoped_refptr<cc::ContextProvider> context_provider =
92 aura::Env::GetInstance() 86 aura::Env::GetInstance()
93 ->context_factory() 87 ->context_factory()
94 ->SharedMainThreadContextProvider(); 88 ->SharedMainThreadContextProvider();
95 if (context_provider) { 89 if (context_provider) {
96 gpu::gles2::GLES2Interface* gles2 = context_provider->ContextGL(); 90 gpu::gles2::GLES2Interface* gles2 = context_provider->ContextGL();
97 gles2->LoseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, 91 gles2->LoseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB,
98 GL_INNOCENT_CONTEXT_RESET_ARB); 92 GL_INNOCENT_CONTEXT_RESET_ARB);
99 } 93 }
100 94
101 // Release buffer. 95 // Release buffer.
102 bool is_lost = true; 96 bool is_lost = true;
103 cc::ReturnedResource returned_resource; 97 cc::ReturnedResource returned_resource;
104 returned_resource.id = resource_id; 98 returned_resource.id = resource_id;
105 returned_resource.sync_token = gpu::SyncToken(); 99 returned_resource.sync_token = gpu::SyncToken();
106 returned_resource.lost = is_lost; 100 returned_resource.lost = is_lost;
107 cc::ReturnedResourceArray resources = {returned_resource}; 101 cc::ReturnedResourceArray resources = {returned_resource};
108 compositor_frame_sink_holder->ReclaimResources(resources); 102 compositor_frame_sink_holder->ReclaimResources(resources);
109 RunAllPendingInMessageLoop(); 103 RunAllPendingInMessageLoop();
110 104
111 // Producing a new texture transferable resource for the contents of the 105 // Producing a new texture transferable resource for the contents of the
112 // buffer. 106 // buffer.
113 ++resource_id; 107 ++resource_id;
114 cc::TransferableResource new_resource; 108 cc::TransferableResource new_resource;
115 rv = buffer->ProduceTransferableResource(compositor_frame_sink_holder.get(), 109 rv = buffer->ProduceTransferableResource(
116 resource_id, false, false, 110 compositor_frame_sink_holder, resource_id, false, false, &new_resource);
117 &new_resource);
118 ASSERT_TRUE(rv); 111 ASSERT_TRUE(rv);
119 buffer->OnDetach(); 112 buffer->OnDetach();
120 113
121 cc::ReturnedResource returned_resource2; 114 cc::ReturnedResource returned_resource2;
122 returned_resource2.id = resource_id; 115 returned_resource2.id = resource_id;
123 returned_resource2.sync_token = gpu::SyncToken(); 116 returned_resource2.sync_token = gpu::SyncToken();
124 returned_resource2.lost = false; 117 returned_resource2.lost = false;
125 cc::ReturnedResourceArray resources2 = {returned_resource2}; 118 cc::ReturnedResourceArray resources2 = {returned_resource2};
126 compositor_frame_sink_holder->ReclaimResources(resources2); 119 compositor_frame_sink_holder->ReclaimResources(resources2);
127 RunAllPendingInMessageLoop(); 120 RunAllPendingInMessageLoop();
128 } 121 }
129 122
130 } // namespace 123 } // namespace
131 } // namespace exo 124 } // namespace exo
OLDNEW
« no previous file with comments | « components/exo/buffer.cc ('k') | components/exo/compositor_frame_sink.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698