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

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

Issue 2468123002: Change BufferManager::RequestBufferAccess signatures to avoid sprintfs. (Closed)
Patch Set: Simplified one RequestBufferAccess variant causing nested va_list usage. Created 4 years, 1 month 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/buffer_manager.h ('k') | gpu/command_buffer/service/vertex_attrib_manager.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gpu/command_buffer/service/buffer_manager.cc
diff --git a/gpu/command_buffer/service/buffer_manager.cc b/gpu/command_buffer/service/buffer_manager.cc
index e7528ec0c71185d388d2936c6be8fd939729c36f..638a20803ce9436ad0fde4802f412a0b1722f4d4 100644
--- a/gpu/command_buffer/service/buffer_manager.cc
+++ b/gpu/command_buffer/service/buffer_manager.cc
@@ -758,14 +758,14 @@ Buffer* BufferManager::RequestBufferAccess(ContextState* context_state,
DCHECK(context_state);
ErrorState* error_state = context_state->GetErrorState();
- std::string msg_tag = base::StringPrintf("bound to target 0x%04x", target);
Buffer* buffer = GetBufferInfoForTarget(context_state, target);
- if (!RequestBufferAccess(error_state, buffer, func_name, msg_tag.c_str())) {
+ if (!RequestBufferAccess(error_state, buffer, func_name,
+ "bound to target 0x%04x", target)) {
return nullptr;
}
if (!buffer->CheckRange(offset, size)) {
std::string msg = base::StringPrintf(
- "%s : offset/size out of range", msg_tag.c_str());
+ "bound to target 0x%04x : offset/size out of range", target);
ERRORSTATE_SET_GL_ERROR(
error_state, GL_INVALID_VALUE, func_name, msg.c_str());
return nullptr;
@@ -779,31 +779,24 @@ Buffer* BufferManager::RequestBufferAccess(ContextState* context_state,
DCHECK(context_state);
ErrorState* error_state = context_state->GetErrorState();
- std::string msg_tag = base::StringPrintf("bound to target 0x%04x", target);
Buffer* buffer = GetBufferInfoForTarget(context_state, target);
return RequestBufferAccess(
- error_state, buffer, func_name, msg_tag.c_str()) ? buffer : nullptr;
+ error_state, buffer, func_name,
+ "bound to target 0x%04x", target) ? buffer : nullptr;
}
bool BufferManager::RequestBufferAccess(ErrorState* error_state,
Buffer* buffer,
const char* func_name,
- const char* message_tag) {
+ const char* error_message_format, ...) {
DCHECK(error_state);
- if (!buffer || buffer->IsDeleted()) {
- std::string msg = base::StringPrintf("%s : no buffer", message_tag);
- ERRORSTATE_SET_GL_ERROR(error_state, GL_INVALID_OPERATION, func_name,
- msg.c_str());
- return false;
- }
- if (buffer->GetMappedRange()) {
- std::string msg = base::StringPrintf("%s : buffer is mapped", message_tag);
- ERRORSTATE_SET_GL_ERROR(error_state, GL_INVALID_OPERATION, func_name,
- msg.c_str());
- return false;
- }
- return true;
+ va_list varargs;
+ va_start(varargs, error_message_format);
+ bool result = RequestBufferAccessV(error_state, buffer, func_name,
+ error_message_format, varargs);
+ va_end(varargs);
+ return result;
}
bool BufferManager::RequestBufferAccess(ErrorState* error_state,
@@ -811,13 +804,13 @@ bool BufferManager::RequestBufferAccess(ErrorState* error_state,
GLintptr offset,
GLsizeiptr size,
const char* func_name,
- const char* message_tag) {
- if (!RequestBufferAccess(error_state, buffer, func_name, message_tag)) {
+ const char* error_message) {
+ if (!RequestBufferAccess(error_state, buffer, func_name, error_message)) {
return false;
}
if (!buffer->CheckRange(offset, size)) {
std::string msg = base::StringPrintf(
- "%s : offset/size out of range", message_tag);
+ "%s : offset/size out of range", error_message);
ERRORSTATE_SET_GL_ERROR(
error_state, GL_INVALID_OPERATION, func_name, msg.c_str());
return false;
@@ -876,5 +869,30 @@ void BufferManager::DecreaseMappedBufferCount() {
mapped_buffer_count_--;
}
+bool BufferManager::RequestBufferAccessV(ErrorState* error_state,
Ken Russell (switch to Gerrit) 2016/11/02 18:29:01 While there's only one caller of this now, it simp
+ Buffer* buffer,
+ const char* func_name,
+ const char* error_message_format,
+ va_list varargs) {
+ DCHECK(error_state);
+
+ if (!buffer || buffer->IsDeleted()) {
+ std::string message_tag = base::StringPrintV(error_message_format, varargs);
+ std::string msg = base::StringPrintf("%s : no buffer", message_tag.c_str());
+ ERRORSTATE_SET_GL_ERROR(error_state, GL_INVALID_OPERATION, func_name,
+ msg.c_str());
+ return false;
+ }
+ if (buffer->GetMappedRange()) {
+ std::string message_tag = base::StringPrintV(error_message_format, varargs);
+ std::string msg = base::StringPrintf("%s : buffer is mapped",
+ message_tag.c_str());
+ ERRORSTATE_SET_GL_ERROR(error_state, GL_INVALID_OPERATION, func_name,
+ msg.c_str());
+ return false;
+ }
+ return true;
+}
+
} // namespace gles2
} // namespace gpu
« no previous file with comments | « gpu/command_buffer/service/buffer_manager.h ('k') | gpu/command_buffer/service/vertex_attrib_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698