Commit cf5316fe authored by achaulk's avatar achaulk Committed by Commit bot

Fix for surfaceless implementation

- The image format used wasn't supported with the memory buffer framework
- The glClear on the init path causes an INVALID_FRAMEBUFFER_OPERATION error
  when executed with no framebuffer, as in the surfaceless case

BUG=380861

Review URL: https://codereview.chromium.org/592933003

Cr-Commit-Position: refs/heads/master@{#297003}
parent 2a102d23
......@@ -27,6 +27,7 @@ bool GpuMemoryBufferImpl::IsFormatValid(unsigned internalformat) {
switch (internalformat) {
case GL_BGRA8_EXT:
case GL_RGBA8_OES:
case GL_RGB8_OES:
return true;
default:
return false;
......@@ -49,6 +50,7 @@ size_t GpuMemoryBufferImpl::BytesPerPixel(unsigned internalformat) {
switch (internalformat) {
case GL_BGRA8_EXT:
case GL_RGBA8_OES:
case GL_RGB8_OES:
return 4;
default:
NOTREACHED();
......
......@@ -106,6 +106,7 @@ bool GpuMemoryBufferImplOzoneNativeBuffer::IsFormatSupported(
unsigned internalformat) {
switch (internalformat) {
case GL_RGBA8_OES:
case GL_RGB8_OES:
return true;
default:
return false;
......
......@@ -1748,6 +1748,8 @@ class GLES2DecoderImpl : public GLES2Decoder,
bool back_buffer_has_depth_;
bool back_buffer_has_stencil_;
bool surfaceless_;
// Backbuffer attachments that are currently undefined.
uint32 backbuffer_needs_clear_bits_;
......@@ -2304,6 +2306,7 @@ GLES2DecoderImpl::GLES2DecoderImpl(ContextGroup* group)
back_buffer_color_format_(0),
back_buffer_has_depth_(false),
back_buffer_has_stencil_(false),
surfaceless_(false),
backbuffer_needs_clear_bits_(0),
current_decoder_error_(error::kNoError),
use_shader_translator_(true),
......@@ -2369,6 +2372,8 @@ bool GLES2DecoderImpl::Initialize(
DCHECK(context->IsCurrent(surface.get()));
DCHECK(!context_.get());
surfaceless_ = surface->IsSurfaceless();
set_initialized();
gpu_tracer_.reset(new GPUTracer(this));
gpu_state_tracer_ = GPUStateTracer::Create(&state_);
......@@ -2626,17 +2631,19 @@ bool GLES2DecoderImpl::Initialize(
// make it appear RGB. If on the other hand we ask for RGBA nd get RGB we
// can't do anything about that.
GLint v = 0;
glGetIntegerv(GL_ALPHA_BITS, &v);
// This checks if the user requested RGBA and we have RGBA then RGBA. If the
// user requested RGB then RGB. If the user did not specify a preference
// than use whatever we were given. Same for DEPTH and STENCIL.
back_buffer_color_format_ =
(attrib_parser.alpha_size != 0 && v > 0) ? GL_RGBA : GL_RGB;
glGetIntegerv(GL_DEPTH_BITS, &v);
back_buffer_has_depth_ = attrib_parser.depth_size != 0 && v > 0;
glGetIntegerv(GL_STENCIL_BITS, &v);
back_buffer_has_stencil_ = attrib_parser.stencil_size != 0 && v > 0;
if (!surfaceless_) {
GLint v = 0;
glGetIntegerv(GL_ALPHA_BITS, &v);
// This checks if the user requested RGBA and we have RGBA then RGBA. If
// the user requested RGB then RGB. If the user did not specify a
// preference than use whatever we were given. Same for DEPTH and STENCIL.
back_buffer_color_format_ =
(attrib_parser.alpha_size != 0 && v > 0) ? GL_RGBA : GL_RGB;
glGetIntegerv(GL_DEPTH_BITS, &v);
back_buffer_has_depth_ = attrib_parser.depth_size != 0 && v > 0;
glGetIntegerv(GL_STENCIL_BITS, &v);
back_buffer_has_stencil_ = attrib_parser.stencil_size != 0 && v > 0;
}
}
// OpenGL ES 2.0 implicitly enables the desktop GL capability
......@@ -2679,7 +2686,7 @@ bool GLES2DecoderImpl::Initialize(
DoBindFramebuffer(GL_FRAMEBUFFER, 0);
DoBindRenderbuffer(GL_RENDERBUFFER, 0);
bool call_gl_clear = true;
bool call_gl_clear = !surfaceless_;
#if defined(OS_ANDROID)
// Temporary workaround for Android WebView because this clear ignores the
// clip and corrupts that external UI of the App. Not calling glClear is ok
......@@ -3123,6 +3130,8 @@ bool GLES2DecoderImpl::CheckFramebufferValid(
Framebuffer* framebuffer,
GLenum target, const char* func_name) {
if (!framebuffer) {
if (surfaceless_)
return false;
if (backbuffer_needs_clear_bits_) {
glClearColor(0, 0, 0, (GLES2Util::GetChannelsForFormat(
offscreen_target_color_format_) & 0x0008) != 0 ? 0 : 1);
......
......@@ -235,6 +235,10 @@ bool GLSurface::ScheduleOverlayPlane(int z_order,
return false;
}
bool GLSurface::IsSurfaceless() const {
return false;
}
GLSurface* GLSurface::GetCurrent() {
return current_surface_.Pointer()->Get();
}
......@@ -352,6 +356,10 @@ bool GLSurfaceAdapter::ScheduleOverlayPlane(int z_order,
z_order, transform, image, bounds_rect, crop_rect);
}
bool GLSurfaceAdapter::IsSurfaceless() const {
return surface_->IsSurfaceless();
}
GLSurfaceAdapter::~GLSurfaceAdapter() {}
} // namespace gfx
......@@ -122,6 +122,8 @@ class GL_EXPORT GLSurface : public base::RefCounted<GLSurface> {
const Rect& bounds_rect,
const RectF& crop_rect);
virtual bool IsSurfaceless() const;
// Create a GL surface that renders directly to a view.
static scoped_refptr<GLSurface> CreateViewGLSurface(
gfx::AcceleratedWidget window);
......@@ -181,6 +183,7 @@ class GL_EXPORT GLSurfaceAdapter : public GLSurface {
GLImage* image,
const Rect& bounds_rect,
const RectF& crop_rect) OVERRIDE;
virtual bool IsSurfaceless() const OVERRIDE;
GLSurface* surface() const { return surface_.get(); }
......
......@@ -144,6 +144,7 @@ class GL_EXPORT GLSurfaceOzoneSurfaceless : public SurfacelessEGL {
SwapBuffers();
return true;
}
virtual bool IsSurfaceless() const OVERRIDE { return true; }
private:
virtual ~GLSurfaceOzoneSurfaceless() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment