summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorreveman@chromium.org <reveman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-16 00:58:56 +0000
committerreveman@chromium.org <reveman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-16 00:58:56 +0000
commit763eaf7078b84bc3b9e98b8bb90c8cf81b23eaca (patch)
tree532a010c808884b8cb09fed6eab832ca85e1db71
parent51051b1ab33ece04d6aea8f0ae78e2a6ab4901a6 (diff)
downloadchromium_src-763eaf7078b84bc3b9e98b8bb90c8cf81b23eaca.zip
chromium_src-763eaf7078b84bc3b9e98b8bb90c8cf81b23eaca.tar.gz
chromium_src-763eaf7078b84bc3b9e98b8bb90c8cf81b23eaca.tar.bz2
gpu: Add Serialize function to ContextCreationAttribParser.
Rename ContextCreationAttribParser to ContextCreationAttribHelper and add Serialize function. TEST=gl_tests BUG= Review URL: https://chromiumcodereview.appspot.com/23244002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@217898 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--gpu/command_buffer/common/gles2_cmd_utils.cc111
-rw-r--r--gpu/command_buffer/common/gles2_cmd_utils.h6
-rw-r--r--gpu/command_buffer/service/gles2_cmd_decoder.cc2
-rw-r--r--gpu/command_buffer/tests/gl_manager.cc27
4 files changed, 92 insertions, 54 deletions
diff --git a/gpu/command_buffer/common/gles2_cmd_utils.cc b/gpu/command_buffer/common/gles2_cmd_utils.cc
index 25eafcd..301ef4a 100644
--- a/gpu/command_buffer/common/gles2_cmd_utils.cc
+++ b/gpu/command_buffer/common/gles2_cmd_utils.cc
@@ -715,7 +715,29 @@ bool GLES2Util::ParseUniformName(
return true;
}
-ContextCreationAttribParser::ContextCreationAttribParser()
+namespace {
+
+// From <EGL/egl.h>.
+const int32 kAlphaSize = 0x3021; // EGL_ALPHA_SIZE
+const int32 kBlueSize = 0x3022; // EGL_BLUE_SIZE
+const int32 kGreenSize = 0x3023; // EGL_GREEN_SIZE
+const int32 kRedSize = 0x3024; // EGL_RED_SIZE
+const int32 kDepthSize = 0x3025; // EGL_DEPTH_SIZE
+const int32 kStencilSize = 0x3026; // EGL_STENCIL_SIZE
+const int32 kSamples = 0x3031; // EGL_SAMPLES
+const int32 kSampleBuffers = 0x3032; // EGL_SAMPLE_BUFFERS
+const int32 kNone = 0x3038; // EGL_NONE
+const int32 kSwapBehavior = 0x3093; // EGL_SWAP_BEHAVIOR
+const int32 kBufferPreserved = 0x3094; // EGL_BUFFER_PRESERVED
+const int32 kBufferDestroyed = 0x3095; // EGL_BUFFER_DESTROYED
+
+// Chromium only.
+const int32 kShareResources = 0x10000;
+const int32 kBindGeneratesResource = 0x10001;
+
+} // namespace
+
+ContextCreationAttribHelper::ContextCreationAttribHelper()
: alpha_size_(-1),
blue_size_(-1),
green_size_(-1),
@@ -729,28 +751,53 @@ ContextCreationAttribParser::ContextCreationAttribParser()
bind_generates_resource_(true) {
}
-bool ContextCreationAttribParser::Parse(const std::vector<int32>& attribs) {
- // From <EGL/egl.h>.
- const int32 EGL_ALPHA_SIZE = 0x3021;
- const int32 EGL_BLUE_SIZE = 0x3022;
- const int32 EGL_GREEN_SIZE = 0x3023;
- const int32 EGL_RED_SIZE = 0x3024;
- const int32 EGL_DEPTH_SIZE = 0x3025;
- const int32 EGL_STENCIL_SIZE = 0x3026;
- const int32 EGL_SAMPLES = 0x3031;
- const int32 EGL_SAMPLE_BUFFERS = 0x3032;
- const int32 EGL_NONE = 0x3038;
- const int32 EGL_SWAP_BEHAVIOR = 0x3093;
- const int32 EGL_BUFFER_PRESERVED = 0x3094;
-
- // Chromium only.
- const int32 SHARE_RESOURCES = 0x10000;
- const int32 BIND_GENERATES_RESOURCES = 0x10001;
+void ContextCreationAttribHelper::Serialize(std::vector<int32>* attribs) {
+ if (alpha_size_ != -1) {
+ attribs->push_back(kAlphaSize);
+ attribs->push_back(alpha_size_);
+ }
+ if (blue_size_ != -1) {
+ attribs->push_back(kBlueSize);
+ attribs->push_back(blue_size_);
+ }
+ if (green_size_ != -1) {
+ attribs->push_back(kGreenSize);
+ attribs->push_back(green_size_);
+ }
+ if (red_size_ != -1) {
+ attribs->push_back(kRedSize);
+ attribs->push_back(red_size_);
+ }
+ if (depth_size_ != -1) {
+ attribs->push_back(kDepthSize);
+ attribs->push_back(depth_size_);
+ }
+ if (stencil_size_ != -1) {
+ attribs->push_back(kStencilSize);
+ attribs->push_back(stencil_size_);
+ }
+ if (samples_ != -1) {
+ attribs->push_back(kSamples);
+ attribs->push_back(samples_);
+ }
+ if (sample_buffers_ != -1) {
+ attribs->push_back(kSampleBuffers);
+ attribs->push_back(sample_buffers_);
+ }
+ attribs->push_back(kSwapBehavior);
+ attribs->push_back(buffer_preserved_ ? kBufferPreserved : kBufferDestroyed);
+ attribs->push_back(kShareResources);
+ attribs->push_back(share_resources_ ? 1 : 0);
+ attribs->push_back(kBindGeneratesResource);
+ attribs->push_back(bind_generates_resource_ ? 1 : 0);
+ attribs->push_back(kNone);
+}
+bool ContextCreationAttribHelper::Parse(const std::vector<int32>& attribs) {
for (size_t i = 0; i < attribs.size(); i += 2) {
const int32 attrib = attribs[i];
if (i + 1 >= attribs.size()) {
- if (attrib == EGL_NONE) {
+ if (attrib == kNone) {
return true;
}
@@ -761,40 +808,40 @@ bool ContextCreationAttribParser::Parse(const std::vector<int32>& attribs) {
const int32 value = attribs[i+1];
switch (attrib) {
- case EGL_ALPHA_SIZE:
+ case kAlphaSize:
alpha_size_ = value;
break;
- case EGL_BLUE_SIZE:
+ case kBlueSize:
blue_size_ = value;
break;
- case EGL_GREEN_SIZE:
+ case kGreenSize:
green_size_ = value;
break;
- case EGL_RED_SIZE:
+ case kRedSize:
red_size_ = value;
break;
- case EGL_DEPTH_SIZE:
+ case kDepthSize:
depth_size_ = value;
break;
- case EGL_STENCIL_SIZE:
+ case kStencilSize:
stencil_size_ = value;
break;
- case EGL_SAMPLES:
+ case kSamples:
samples_ = value;
break;
- case EGL_SAMPLE_BUFFERS:
+ case kSampleBuffers:
sample_buffers_ = value;
break;
- case EGL_SWAP_BEHAVIOR:
- buffer_preserved_ = value == EGL_BUFFER_PRESERVED;
+ case kSwapBehavior:
+ buffer_preserved_ = value == kBufferPreserved;
break;
- case SHARE_RESOURCES:
+ case kShareResources:
share_resources_ = value != 0;
break;
- case BIND_GENERATES_RESOURCES:
+ case kBindGeneratesResource:
bind_generates_resource_ = value != 0;
break;
- case EGL_NONE:
+ case kNone:
// Terminate list, even if more attributes.
return true;
default:
diff --git a/gpu/command_buffer/common/gles2_cmd_utils.h b/gpu/command_buffer/common/gles2_cmd_utils.h
index 4bc4b1b..b8619e6 100644
--- a/gpu/command_buffer/common/gles2_cmd_utils.h
+++ b/gpu/command_buffer/common/gles2_cmd_utils.h
@@ -174,9 +174,11 @@ class GLES2_UTILS_EXPORT GLES2Util {
int num_shader_binary_formats_;
};
-class GLES2_UTILS_EXPORT ContextCreationAttribParser {
+class GLES2_UTILS_EXPORT ContextCreationAttribHelper {
public:
- ContextCreationAttribParser();
+ ContextCreationAttribHelper();
+
+ void Serialize(std::vector<int32>* attribs);
bool Parse(const std::vector<int32>& attribs);
// -1 if invalid or unspecified.
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.cc b/gpu/command_buffer/service/gles2_cmd_decoder.cc
index 44a0134..77a6b8a 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder.cc
+++ b/gpu/command_buffer/service/gles2_cmd_decoder.cc
@@ -2207,7 +2207,7 @@ bool GLES2DecoderImpl::Initialize(
glActiveTexture(GL_TEXTURE0);
CHECK_GL_ERROR();
- ContextCreationAttribParser attrib_parser;
+ ContextCreationAttribHelper attrib_parser;
if (!attrib_parser.Parse(attribs))
return false;
diff --git a/gpu/command_buffer/tests/gl_manager.cc b/gpu/command_buffer/tests/gl_manager.cc
index c4b84a2..54ff645 100644
--- a/gpu/command_buffer/tests/gl_manager.cc
+++ b/gpu/command_buffer/tests/gl_manager.cc
@@ -12,6 +12,7 @@
#include "gpu/command_buffer/client/gles2_lib.h"
#include "gpu/command_buffer/client/transfer_buffer.h"
#include "gpu/command_buffer/common/constants.h"
+#include "gpu/command_buffer/common/gles2_cmd_utils.h"
#include "gpu/command_buffer/service/command_buffer_service.h"
#include "gpu/command_buffer/service/context_group.h"
#include "gpu/command_buffer/service/gl_context_virtual.h"
@@ -100,14 +101,6 @@ void GLManager::Initialize(const GLManager::Options& options) {
real_gl_context = options.virtual_manager->context();
}
- // From <EGL/egl.h>.
- const int32 EGL_ALPHA_SIZE = 0x3021;
- const int32 EGL_BLUE_SIZE = 0x3022;
- const int32 EGL_GREEN_SIZE = 0x3023;
- const int32 EGL_RED_SIZE = 0x3024;
- const int32 EGL_DEPTH_SIZE = 0x3025;
- const int32 EGL_NONE = 0x3038;
-
mailbox_manager_ =
mailbox_manager ? mailbox_manager : new gles2::MailboxManager;
share_group_ =
@@ -116,17 +109,13 @@ void GLManager::Initialize(const GLManager::Options& options) {
gfx::GpuPreference gpu_preference(gfx::PreferDiscreteGpu);
const char* allowed_extensions = "*";
std::vector<int32> attribs;
- attribs.push_back(EGL_RED_SIZE);
- attribs.push_back(8);
- attribs.push_back(EGL_GREEN_SIZE);
- attribs.push_back(8);
- attribs.push_back(EGL_BLUE_SIZE);
- attribs.push_back(8);
- attribs.push_back(EGL_ALPHA_SIZE);
- attribs.push_back(8);
- attribs.push_back(EGL_DEPTH_SIZE);
- attribs.push_back(16);
- attribs.push_back(EGL_NONE);
+ gles2::ContextCreationAttribHelper attrib_helper;
+ attrib_helper.red_size_ = 8;
+ attrib_helper.green_size_ = 8;
+ attrib_helper.blue_size_ = 8;
+ attrib_helper.alpha_size_ = 8;
+ attrib_helper.depth_size_ = 16;
+ attrib_helper.Serialize(&attribs);
if (!context_group) {
context_group = new gles2::ContextGroup(mailbox_manager_.get(),