blob: e73fecf42893ccf376741748c7b759a84ec017a5 [file] [log] [blame]
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "android_webview/browser/parent_output_surface.h"
#include "cc/output/output_surface_client.h"
#include "gpu/command_buffer/client/gles2_interface.h"
namespace android_webview {
ParentOutputSurface::ParentOutputSurface(
scoped_refptr<cc::ContextProvider> context_provider)
: cc::OutputSurface(context_provider) {
stencil_state_.stencil_test_enabled = false;
}
ParentOutputSurface::~ParentOutputSurface() {
}
void ParentOutputSurface::DidLoseOutputSurface() {
// Android WebView does not handle context loss.
LOG(FATAL) << "Render thread context loss";
}
void ParentOutputSurface::Reshape(const gfx::Size& size,
float scale_factor,
bool has_alpha) {
DCHECK_EQ(1.f, scale_factor);
surface_size_ = size;
}
void ParentOutputSurface::SwapBuffers(cc::CompositorFrame* frame) {
context_provider_->ContextGL()->ShallowFlushCHROMIUM();
client_->DidSwapBuffers();
}
void ParentOutputSurface::ApplyExternalStencil() {
DCHECK(stencil_state_.stencil_test_enabled);
gpu::gles2::GLES2Interface* gl = context_provider()->ContextGL();
gl->StencilFuncSeparate(GL_FRONT, stencil_state_.stencil_front_func,
stencil_state_.stencil_front_mask,
stencil_state_.stencil_front_ref);
gl->StencilFuncSeparate(GL_BACK, stencil_state_.stencil_back_func,
stencil_state_.stencil_back_mask,
stencil_state_.stencil_back_ref);
gl->StencilMaskSeparate(GL_FRONT, stencil_state_.stencil_front_writemask);
gl->StencilMaskSeparate(GL_BACK, stencil_state_.stencil_back_writemask);
gl->StencilOpSeparate(GL_FRONT, stencil_state_.stencil_front_fail_op,
stencil_state_.stencil_front_z_fail_op,
stencil_state_.stencil_front_z_pass_op);
gl->StencilOpSeparate(GL_BACK, stencil_state_.stencil_back_fail_op,
stencil_state_.stencil_back_z_fail_op,
stencil_state_.stencil_back_z_pass_op);
}
void ParentOutputSurface::SetGLState(const ScopedAppGLStateRestore& gl_state) {
stencil_state_ = gl_state.stencil_state();
SetExternalStencilTest(stencil_state_.stencil_test_enabled);
}
} // namespace android_webview