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

Side by Side Diff: gpu/command_buffer/common/gles2_cmd_format_test.cc

Issue 116863003: gpu: Reuse transfer buffers more aggresively (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Unset texture and texture_ref after deleting Created 6 years, 8 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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // This file contains unit tests for gles2 commmands 5 // This file contains unit tests for gles2 commmands
6 6
7 #include <limits>
8
9 #include "base/bind.h"
10 #include "base/synchronization/waitable_event.h"
11 #include "base/threading/thread.h"
7 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
8 #include "gpu/command_buffer/common/gles2_cmd_format.h" 13 #include "gpu/command_buffer/common/gles2_cmd_format.h"
9 14
10 namespace gpu { 15 namespace gpu {
11 namespace gles2 { 16 namespace gles2 {
12 17
13 class GLES2FormatTest : public testing::Test { 18 class GLES2FormatTest : public testing::Test {
14 protected: 19 protected:
15 static const unsigned char kInitialValue = 0xBD; 20 static const unsigned char kInitialValue = 0xBD;
16 21
(...skipping 22 matching lines...) Expand all
39 44
40 void CheckBytesWrittenMatchesExpectedSize( 45 void CheckBytesWrittenMatchesExpectedSize(
41 const void* end, size_t expected_size) { 46 const void* end, size_t expected_size) {
42 CheckBytesWritten(end, expected_size, expected_size); 47 CheckBytesWritten(end, expected_size, expected_size);
43 } 48 }
44 49
45 private: 50 private:
46 unsigned char buffer_[1024]; 51 unsigned char buffer_[1024];
47 }; 52 };
48 53
54 void SignalCompletion(uint32* assigned_async_token_ptr,
55 uint32 async_token,
56 AsyncUploadSync* sync) {
57 EXPECT_EQ(async_token, *assigned_async_token_ptr);
58 sync->SetAsyncUploadToken(async_token);
59 }
60
61 TEST(GLES2FormatAsyncUploadSyncTest, AsyncUploadSync) {
62 const size_t kSize = 10;
63 const size_t kCount = 1000;
64
65 base::Thread thread("GLES2FormatUploadSyncTest - Fake Upload Thread");
66 thread.Start();
67
68 // Run the same test 50 times so we retest the wrap as well.
69 for (size_t test_run = 0; test_run < 50; ++test_run) {
70 AsyncUploadSync sync;
71 sync.Reset();
72
73 uint32 buffer_tokens[kSize];
74 memset(buffer_tokens, 0, sizeof(buffer_tokens));
75
76 // Start with a token large enough so that we'll wrap.
77 uint32 async_token = std::numeric_limits<uint32>::max() - kCount / 2;
78
79 // Set initial async token.
80 sync.SetAsyncUploadToken(async_token);
81
82 for (size_t i = 0; i < kCount; ++i) {
83 size_t buffer = i % kSize;
84
85 // Loop until previous async token has passed if any was set.
86 while (buffer_tokens[buffer] &&
87 !sync.HasAsyncUploadTokenPassed(buffer_tokens[buffer]))
88 base::PlatformThread::YieldCurrentThread();
89
90 // Next token, skip 0.
91 async_token++;
92 if (async_token == 0)
93 async_token++;
94
95 // Set the buffer's associated token.
96 buffer_tokens[buffer] = async_token;
97
98 // Set the async upload token on the fake upload thread and assert that
99 // the associated buffer still has the given token.
100 thread.message_loop()->PostTask(FROM_HERE,
101 base::Bind(&SignalCompletion,
102 &buffer_tokens[buffer],
103 async_token,
104 &sync));
105 }
106
107 // Flush the thread message loop before starting again.
108 base::WaitableEvent waitable(false, false);
109 thread.message_loop()->PostTask(FROM_HERE,
110 base::Bind(&base::WaitableEvent::Signal,
111 base::Unretained(&waitable)));
112 waitable.Wait();
113 }
114 }
115
49 // GCC requires these declarations, but MSVC requires they not be present 116 // GCC requires these declarations, but MSVC requires they not be present
50 #ifndef _MSC_VER 117 #ifndef _MSC_VER
51 const unsigned char GLES2FormatTest::kInitialValue; 118 const unsigned char GLES2FormatTest::kInitialValue;
52 #endif 119 #endif
53 120
54 #include "gpu/command_buffer/common/gles2_cmd_format_test_autogen.h" 121 #include "gpu/command_buffer/common/gles2_cmd_format_test_autogen.h"
55 122
56 } // namespace gles2 123 } // namespace gles2
57 } // namespace gpu 124 } // namespace gpu
58 125
OLDNEW
« no previous file with comments | « gpu/command_buffer/common/gles2_cmd_format_autogen.h ('k') | gpu/command_buffer/common/gles2_cmd_format_test_autogen.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698