blob: 79b855d7045e50cd6773734bc634ee00983d6454 [file] [log] [blame]
[email protected]8705654b2014-05-24 01:16:191// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "android_webview/browser/parent_output_surface.h"
6
danakja85bd242016-06-22 22:25:497#include "android_webview/browser/aw_render_thread_context_provider.h"
fsamueld63137a2016-06-24 23:39:518#include "cc/output/compositor_frame.h"
[email protected]8705654b2014-05-24 01:16:199#include "cc/output/output_surface_client.h"
10#include "gpu/command_buffer/client/gles2_interface.h"
11
12namespace android_webview {
13
14ParentOutputSurface::ParentOutputSurface(
danakja85bd242016-06-22 22:25:4915 scoped_refptr<AwRenderThreadContextProvider> context_provider)
hajimehoshiea85b9dc2016-05-25 09:52:3116 : cc::OutputSurface(std::move(context_provider), nullptr, nullptr) {
boliu0ed4f652016-01-09 00:07:2617 stencil_state_.stencil_test_enabled = false;
[email protected]8705654b2014-05-24 01:16:1918}
19
20ParentOutputSurface::~ParentOutputSurface() {
21}
22
boliub3547242016-01-04 21:24:1923void ParentOutputSurface::DidLoseOutputSurface() {
24 // Android WebView does not handle context loss.
25 LOG(FATAL) << "Render thread context loss";
26}
27
jbauman7064ae372015-12-15 21:21:0228void ParentOutputSurface::Reshape(const gfx::Size& size,
29 float scale_factor,
ccameron3d74bb92016-06-30 21:35:4630 const gfx::ColorSpace& color_space,
jbauman7064ae372015-12-15 21:21:0231 bool has_alpha) {
jbaumana783bb02015-06-05 00:57:3532 DCHECK_EQ(1.f, scale_factor);
33 surface_size_ = size;
34}
35
fsamueld63137a2016-06-24 23:39:5136void ParentOutputSurface::SwapBuffers(cc::CompositorFrame frame) {
[email protected]8705654b2014-05-24 01:16:1937 context_provider_->ContextGL()->ShallowFlushCHROMIUM();
[email protected]8705654b2014-05-24 01:16:1938}
39
boliu0ed4f652016-01-09 00:07:2640void ParentOutputSurface::ApplyExternalStencil() {
41 DCHECK(stencil_state_.stencil_test_enabled);
42 gpu::gles2::GLES2Interface* gl = context_provider()->ContextGL();
43 gl->StencilFuncSeparate(GL_FRONT, stencil_state_.stencil_front_func,
44 stencil_state_.stencil_front_mask,
45 stencil_state_.stencil_front_ref);
46 gl->StencilFuncSeparate(GL_BACK, stencil_state_.stencil_back_func,
47 stencil_state_.stencil_back_mask,
48 stencil_state_.stencil_back_ref);
49 gl->StencilMaskSeparate(GL_FRONT, stencil_state_.stencil_front_writemask);
50 gl->StencilMaskSeparate(GL_BACK, stencil_state_.stencil_back_writemask);
51 gl->StencilOpSeparate(GL_FRONT, stencil_state_.stencil_front_fail_op,
52 stencil_state_.stencil_front_z_fail_op,
53 stencil_state_.stencil_front_z_pass_op);
54 gl->StencilOpSeparate(GL_BACK, stencil_state_.stencil_back_fail_op,
55 stencil_state_.stencil_back_z_fail_op,
56 stencil_state_.stencil_back_z_pass_op);
57}
58
danakja85bd242016-06-22 22:25:4959uint32_t ParentOutputSurface::GetFramebufferCopyTextureFormat() {
60 auto* gl = static_cast<AwRenderThreadContextProvider*>(context_provider());
61 return gl->GetCopyTextureInternalFormat();
62}
63
boliu0ed4f652016-01-09 00:07:2664void ParentOutputSurface::SetGLState(const ScopedAppGLStateRestore& gl_state) {
65 stencil_state_ = gl_state.stencil_state();
66 SetExternalStencilTest(stencil_state_.stencil_test_enabled);
67}
68
[email protected]8705654b2014-05-24 01:16:1969} // namespace android_webview