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

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

Issue 2083853002: exo: Recreate Surface resources on context lost. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make ContextFactory pure; hold on to buffer reference 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 <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 21 matching lines...) Expand all
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 34
35 // Set the release callback. 35 // Set the release callback.
36 int release_call_count = 0; 36 int release_call_count = 0;
37 buffer->set_release_callback( 37 buffer->set_release_callback(
38 base::Bind(&Release, base::Unretained(&release_call_count))); 38 base::Bind(&Release, base::Unretained(&release_call_count)));
39 39
40 // Produce a texture mailbox for the contents of the buffer. 40 // Produce a texture mailbox for the contents of the buffer.
41 cc::TextureMailbox texture_mailbox; 41 cc::TextureMailbox texture_mailbox;
42 base::Closure detach_callback;
42 std::unique_ptr<cc::SingleReleaseCallback> buffer_release_callback = 43 std::unique_ptr<cc::SingleReleaseCallback> buffer_release_callback =
43 buffer->ProduceTextureMailbox(&texture_mailbox, false, true); 44 buffer->ProduceTextureMailbox(&texture_mailbox, false, true,
45 &detach_callback);
44 ASSERT_TRUE(buffer_release_callback); 46 ASSERT_TRUE(buffer_release_callback);
45 47
46 // Release buffer. 48 // Release buffer.
47 buffer_release_callback->Run(gpu::SyncToken(), false); 49 buffer_release_callback->Run(gpu::SyncToken(), false);
50 detach_callback.Run();
48 51
49 // Release() should have been called exactly once. 52 // Release() should have been called exactly once.
50 ASSERT_EQ(release_call_count, 1); 53 ASSERT_EQ(release_call_count, 1);
51 } 54 }
52 55
53 TEST_F(BufferTest, IsLost) { 56 TEST_F(BufferTest, IsLost) {
54 gfx::Size buffer_size(256, 256); 57 gfx::Size buffer_size(256, 256);
55 std::unique_ptr<Buffer> buffer( 58 std::unique_ptr<Buffer> buffer(
56 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); 59 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
57 60
61 base::Closure detach_callback;
58 // Acquire a texture mailbox for the contents of the buffer. 62 // Acquire a texture mailbox for the contents of the buffer.
59 cc::TextureMailbox texture_mailbox; 63 cc::TextureMailbox texture_mailbox;
60 std::unique_ptr<cc::SingleReleaseCallback> buffer_release_callback = 64 std::unique_ptr<cc::SingleReleaseCallback> buffer_release_callback =
61 buffer->ProduceTextureMailbox(&texture_mailbox, false, true); 65 buffer->ProduceTextureMailbox(&texture_mailbox, false, true,
66 &detach_callback);
62 ASSERT_TRUE(buffer_release_callback); 67 ASSERT_TRUE(buffer_release_callback);
63 68
64 scoped_refptr<cc::ContextProvider> context_provider = 69 scoped_refptr<cc::ContextProvider> context_provider =
65 aura::Env::GetInstance() 70 aura::Env::GetInstance()
66 ->context_factory() 71 ->context_factory()
67 ->SharedMainThreadContextProvider(); 72 ->SharedMainThreadContextProvider();
68 if (context_provider) { 73 if (context_provider) {
69 gpu::gles2::GLES2Interface* gles2 = context_provider->ContextGL(); 74 gpu::gles2::GLES2Interface* gles2 = context_provider->ContextGL();
70 gles2->LoseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, 75 gles2->LoseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB,
71 GL_INNOCENT_CONTEXT_RESET_ARB); 76 GL_INNOCENT_CONTEXT_RESET_ARB);
72 } 77 }
73 78
74 // Producing a new texture mailbox for the contents of the buffer.
75 std::unique_ptr<cc::SingleReleaseCallback> buffer_release_callback2 =
76 buffer->ProduceTextureMailbox(&texture_mailbox, false, false);
77 ASSERT_TRUE(buffer_release_callback);
78
79 // Release buffer. 79 // Release buffer.
80 bool is_lost = true; 80 bool is_lost = true;
81 buffer_release_callback->Run(gpu::SyncToken(), is_lost); 81 buffer_release_callback->Run(gpu::SyncToken(), is_lost);
82
83 base::Closure detach_callback2;
84 // Producing a new texture mailbox for the contents of the buffer.
85 std::unique_ptr<cc::SingleReleaseCallback> buffer_release_callback2 =
86 buffer->ProduceTextureMailbox(&texture_mailbox, false, false,
87 &detach_callback2);
88 ASSERT_TRUE(buffer_release_callback);
89
90 detach_callback.Run();
91
82 buffer_release_callback2->Run(gpu::SyncToken(), false); 92 buffer_release_callback2->Run(gpu::SyncToken(), false);
93 detach_callback2.Run();
83 } 94 }
84 95
85 } // namespace 96 } // namespace
86 } // namespace exo 97 } // namespace exo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698