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

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

Issue 165393003: gpu: Generate mailboxes on client side (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: meant to remove crypto/random.cc Created 6 years, 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "gpu/command_buffer/common/mailbox.h" 5 #include "gpu/command_buffer/common/mailbox.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "crypto/random.h"
10 11
11 namespace gpu { 12 namespace gpu {
12 13
13 Mailbox::Mailbox() { 14 Mailbox::Mailbox() {
14 memset(name, 0, sizeof(name)); 15 memset(name, 0, sizeof(name));
15 } 16 }
16 17
17 bool Mailbox::IsZero() const { 18 bool Mailbox::IsZero() const {
18 for (size_t i = 0; i < arraysize(name); ++i) { 19 for (size_t i = 0; i < arraysize(name); ++i) {
19 if (name[i]) 20 if (name[i])
20 return false; 21 return false;
21 } 22 }
22 return true; 23 return true;
23 } 24 }
24 25
25 void Mailbox::SetZero() { 26 void Mailbox::SetZero() {
26 memset(name, 0, sizeof(name)); 27 memset(name, 0, sizeof(name));
27 } 28 }
28 29
29 void Mailbox::SetName(const int8* n) { 30 void Mailbox::SetName(const int8* n) {
30 DCHECK(IsZero() || !memcmp(name, n, sizeof(name))); 31 DCHECK(IsZero() || !memcmp(name, n, sizeof(name)));
31 memcpy(name, n, sizeof(name)); 32 memcpy(name, n, sizeof(name));
32 } 33 }
33 34
35 Mailbox Mailbox::Generate() {
36 Mailbox result;
37 crypto::RandBytes(result.name, sizeof(result.name));
38 #if !defined(NDEBUG)
39 int8 value = 1;
40 for (size_t i = 1; i < sizeof(result.name); ++i)
41 value ^= result.name[i];
42 result.name[0] = value;
43 #endif
44 return result;
45 }
46
47 bool Mailbox::Verify() const {
48 #if !defined(NDEBUG)
49 int8 value = 1;
50 for (size_t i = 0; i < sizeof(name); ++i)
51 value ^= name[i];
52 return value == 0;
53 #else
54 return true;
55 #endif
56 }
57
34 } // namespace gpu 58 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698