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

Unified Diff: gpu/command_buffer/service/common_decoder.cc

Issue 935333002: Update from https://crrev.com/316786 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gpu/command_buffer/service/common_decoder.h ('k') | gpu/command_buffer/service/gles2_cmd_decoder.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gpu/command_buffer/service/common_decoder.cc
diff --git a/gpu/command_buffer/service/common_decoder.cc b/gpu/command_buffer/service/common_decoder.cc
index f40c7218ad12d8de2ed0af128c231774cb7a77b0..99fdb765a0841876e01f45e85430a3bdf70d2a50 100644
--- a/gpu/command_buffer/service/common_decoder.cc
+++ b/gpu/command_buffer/service/common_decoder.cc
@@ -3,6 +3,8 @@
// found in the LICENSE file.
#include "gpu/command_buffer/service/common_decoder.h"
+
+#include "base/numerics/safe_math.h"
#include "gpu/command_buffer/service/cmd_buffer_engine.h"
namespace gpu {
@@ -69,6 +71,53 @@ bool CommonDecoder::Bucket::GetAsString(std::string* str) {
return true;
}
+bool CommonDecoder::Bucket::GetAsStrings(
+ GLsizei* _count, std::vector<char*>* _string, std::vector<GLint>* _length) {
+ const size_t kMinBucketSize = sizeof(GLint);
+ // Each string has at least |length| in the header and a NUL character.
+ const size_t kMinStringSize = sizeof(GLint) + 1;
+ const size_t bucket_size = this->size();
+ if (bucket_size < kMinBucketSize) {
+ return false;
+ }
+ char* bucket_data = this->GetDataAs<char*>(0, bucket_size);
+ GLint* header = reinterpret_cast<GLint*>(bucket_data);
+ GLsizei count = static_cast<GLsizei>(header[0]);
+ if (count < 0) {
+ return false;
+ }
+ const size_t max_count = (bucket_size - kMinBucketSize) / kMinStringSize;
+ if (max_count < static_cast<size_t>(count)) {
+ return false;
+ }
+ GLint* length = header + 1;
+ std::vector<char*> strs(count);
+ base::CheckedNumeric<size_t> total_size = sizeof(GLint);
+ total_size *= count + 1; // Header size.
+ if (!total_size.IsValid())
+ return false;
+ for (GLsizei ii = 0; ii < count; ++ii) {
+ strs[ii] = bucket_data + total_size.ValueOrDefault(0);
+ total_size += length[ii];
+ total_size += 1; // NUL char at the end of each char array.
+ if (!total_size.IsValid() || total_size.ValueOrDefault(0) > bucket_size ||
+ strs[ii][length[ii]] != 0) {
+ return false;
+ }
+ }
+ if (total_size.ValueOrDefault(0) != bucket_size) {
+ return false;
+ }
+ DCHECK(_count && _string && _length);
+ *_count = count;
+ *_string = strs;
+ _length->resize(count);
+ for (GLsizei ii = 0; ii < count; ++ii) {
+ (*_length)[ii] = length[ii];
+ }
+ return true;
+}
+
CommonDecoder::CommonDecoder() : engine_(NULL) {}
CommonDecoder::~CommonDecoder() {}
« no previous file with comments | « gpu/command_buffer/service/common_decoder.h ('k') | gpu/command_buffer/service/gles2_cmd_decoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698