Skip to content

Commit

Permalink
Fold ContextCreationAttribHelper::Parse into PPB_Graphics3D_Proxy::Cr…
Browse files Browse the repository at this point in the history
…eateProxyResource

That's the only caller, and it simplifies both sides.

Bug: None
Cq-Include-Trybots: master.tryserver.chromium.android:android_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel
Change-Id: I917e2dae4f69b00cb686cc1fba636e7df4a973da
Reviewed-on: https://chromium-review.googlesource.com/834771
Commit-Queue: Antoine Labour <piman@chromium.org>
Reviewed-by: Bill Budge <bbudge@chromium.org>
Cr-Commit-Position: refs/heads/master@{#525570}
  • Loading branch information
pimanttr authored and Commit Bot committed Dec 21, 2017
1 parent 3b8e206 commit 492d57a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 117 deletions.
103 changes: 0 additions & 103 deletions gpu/command_buffer/common/gles2_cmd_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1829,37 +1829,6 @@ uint32_t GLES2Util::ConvertToSizedFormat(uint32_t format, uint32_t type) {
return format;
}

namespace {

// GL context configuration attributes. Those in the 16-bit range are the same
// as used by EGL. Those outside the 16-bit range are unique to Chromium.
// Attributes are matched using a closest fit algorithm.

// From <EGL/egl.h>.
#include <stddef.h>
#include <stdint.h>
const int32_t kAlphaSize = 0x3021; // EGL_ALPHA_SIZE
const int32_t kBlueSize = 0x3022; // EGL_BLUE_SIZE
const int32_t kGreenSize = 0x3023; // EGL_GREEN_SIZE
const int32_t kRedSize = 0x3024; // EGL_RED_SIZE
const int32_t kDepthSize = 0x3025; // EGL_DEPTH_SIZE
const int32_t kStencilSize = 0x3026; // EGL_STENCIL_SIZE
const int32_t kSamples = 0x3031; // EGL_SAMPLES
const int32_t kSampleBuffers = 0x3032; // EGL_SAMPLE_BUFFERS
const int32_t kNone = 0x3038; // EGL_NONE
const int32_t kSwapBehavior = 0x3093; // EGL_SWAP_BEHAVIOR
const int32_t kBufferPreserved = 0x3094; // EGL_BUFFER_PRESERVED
const int32_t kSingleBuffer = 0x3085; // EGL_SINGLE_BUFFER

// Chromium only.
const int32_t kBindGeneratesResource = 0x10000;
const int32_t kFailIfMajorPerfCaveat = 0x10001;
const int32_t kLoseContextWhenOutOfMemory = 0x10002;
const int32_t kShouldUseNativeGMBForBackbuffer = 0x10003;
const int32_t kContextType = 0x10004;

} // namespace

bool IsWebGLContextType(ContextType context_type) {
// Switch statement to cause a compile-time error if we miss a case.
switch (context_type) {
Expand Down Expand Up @@ -1910,78 +1879,6 @@ ContextCreationAttribHelper::ContextCreationAttribHelper() = default;
ContextCreationAttribHelper::ContextCreationAttribHelper(
const ContextCreationAttribHelper& other) = default;

bool ContextCreationAttribHelper::Parse(const std::vector<int32_t>& attribs) {
for (size_t i = 0; i < attribs.size(); i += 2) {
const int32_t attrib = attribs[i];
if (i + 1 >= attribs.size()) {
if (attrib == kNone) {
return true;
}

DLOG(ERROR) << "Missing value after context creation attribute: "
<< attrib;
return false;
}

const int32_t value = attribs[i + 1];
switch (attrib) {
case kAlphaSize:
alpha_size = value;
break;
case kBlueSize:
blue_size = value;
break;
case kGreenSize:
green_size = value;
break;
case kRedSize:
red_size = value;
break;
case kDepthSize:
depth_size = value;
break;
case kStencilSize:
stencil_size = value;
break;
case kSamples:
samples = value;
break;
case kSampleBuffers:
sample_buffers = value;
break;
case kSwapBehavior:
buffer_preserved = value == kBufferPreserved;
break;
case kBindGeneratesResource:
bind_generates_resource = value != 0;
break;
case kFailIfMajorPerfCaveat:
fail_if_major_perf_caveat = value != 0;
break;
case kLoseContextWhenOutOfMemory:
lose_context_when_out_of_memory = value != 0;
break;
case kShouldUseNativeGMBForBackbuffer:
should_use_native_gmb_for_backbuffer = value != 0;
break;
case kSingleBuffer:
single_buffer = value != 0;
break;
case kContextType:
context_type = static_cast<ContextType>(value);
break;
case kNone:
// Terminate list, even if more attributes.
return true;
default:
DLOG(ERROR) << "Invalid context creation attribute: " << attrib;
return false;
}
}

return true;
}

#include "gpu/command_buffer/common/gles2_cmd_utils_implementation_autogen.h"

} // namespace gles2
Expand Down
2 changes: 0 additions & 2 deletions gpu/command_buffer/common/gles2_cmd_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,6 @@ struct GLES2_UTILS_EXPORT ContextCreationAttribHelper {
ContextCreationAttribHelper();
ContextCreationAttribHelper(const ContextCreationAttribHelper& other);

bool Parse(const std::vector<int32_t>& attribs);

gfx::Size offscreen_framebuffer_size;
gl::GpuPreference gpu_preference = gl::PreferIntegratedGpu;
// -1 if invalid or unspecified.
Expand Down
49 changes: 37 additions & 12 deletions ppapi/proxy/ppb_graphics_3d_proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -169,36 +169,61 @@ PP_Resource PPB_Graphics3D_Proxy::CreateProxyResource(
}

gpu::gles2::ContextCreationAttribHelper attrib_helper;
std::vector<int32_t> attribs;
if (attrib_list) {
for (const int32_t* attr = attrib_list; attr[0] != PP_GRAPHICS3DATTRIB_NONE;
attr += 2) {
switch (attr[0]) {
int32_t key = attr[0];
int32_t value = attr[1];
switch (key) {
case PP_GRAPHICS3DATTRIB_ALPHA_SIZE:
attrib_helper.alpha_size = value;
break;
case PP_GRAPHICS3DATTRIB_BLUE_SIZE:
attrib_helper.blue_size = value;
break;
case PP_GRAPHICS3DATTRIB_GREEN_SIZE:
attrib_helper.green_size = value;
break;
case PP_GRAPHICS3DATTRIB_RED_SIZE:
attrib_helper.red_size = value;
break;
case PP_GRAPHICS3DATTRIB_DEPTH_SIZE:
attrib_helper.depth_size = value;
break;
case PP_GRAPHICS3DATTRIB_STENCIL_SIZE:
attrib_helper.stencil_size = value;
break;
case PP_GRAPHICS3DATTRIB_SAMPLES:
attrib_helper.samples = value;
break;
case PP_GRAPHICS3DATTRIB_SAMPLE_BUFFERS:
attrib_helper.sample_buffers = value;
break;
case PP_GRAPHICS3DATTRIB_SWAP_BEHAVIOR:
attrib_helper.buffer_preserved =
value == PP_GRAPHICS3DATTRIB_BUFFER_PRESERVED;
break;
case PP_GRAPHICS3DATTRIB_WIDTH:
attrib_helper.offscreen_framebuffer_size.set_width(attr[1]);
attrib_helper.offscreen_framebuffer_size.set_width(value);
break;
case PP_GRAPHICS3DATTRIB_HEIGHT:
attrib_helper.offscreen_framebuffer_size.set_height(attr[1]);
attrib_helper.offscreen_framebuffer_size.set_height(value);
break;
case PP_GRAPHICS3DATTRIB_GPU_PREFERENCE:
attrib_helper.gpu_preference =
(attr[1] == PP_GRAPHICS3DATTRIB_GPU_PREFERENCE_LOW_POWER)
(value == PP_GRAPHICS3DATTRIB_GPU_PREFERENCE_LOW_POWER)
? gl::PreferIntegratedGpu
: gl::PreferDiscreteGpu;
break;
case PP_GRAPHICS3DATTRIB_SINGLE_BUFFER:
attrib_helper.single_buffer = !!attr[1];
attrib_helper.single_buffer = !!value;
break;
default:
attribs.push_back(attr[0]);
attribs.push_back(attr[1]);
break;
DLOG(ERROR) << "Invalid context creation attribute: " << attr[0];
return 0;
}
}
attribs.push_back(PP_GRAPHICS3DATTRIB_NONE);
}
if (!attrib_helper.Parse(attribs))
return 0;

HostResource result;
gpu::Capabilities capabilities;
Expand Down

0 comments on commit 492d57a

Please sign in to comment.