[email protected] | 8705654b | 2014-05-24 01:16:19 | [diff] [blame] | 1 | // 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 | |
danakj | a85bd24 | 2016-06-22 22:25:49 | [diff] [blame] | 7 | #include "android_webview/browser/aw_render_thread_context_provider.h" |
fsamuel | d63137a | 2016-06-24 23:39:51 | [diff] [blame] | 8 | #include "cc/output/compositor_frame.h" |
[email protected] | 8705654b | 2014-05-24 01:16:19 | [diff] [blame] | 9 | #include "cc/output/output_surface_client.h" |
| 10 | #include "gpu/command_buffer/client/gles2_interface.h" |
| 11 | |
| 12 | namespace android_webview { |
| 13 | |
| 14 | ParentOutputSurface::ParentOutputSurface( |
danakj | a85bd24 | 2016-06-22 22:25:49 | [diff] [blame] | 15 | scoped_refptr<AwRenderThreadContextProvider> context_provider) |
hajimehoshi | ea85b9dc | 2016-05-25 09:52:31 | [diff] [blame] | 16 | : cc::OutputSurface(std::move(context_provider), nullptr, nullptr) { |
boliu | 0ed4f65 | 2016-01-09 00:07:26 | [diff] [blame] | 17 | stencil_state_.stencil_test_enabled = false; |
[email protected] | 8705654b | 2014-05-24 01:16:19 | [diff] [blame] | 18 | } |
| 19 | |
| 20 | ParentOutputSurface::~ParentOutputSurface() { |
| 21 | } |
| 22 | |
boliu | b354724 | 2016-01-04 21:24:19 | [diff] [blame] | 23 | void ParentOutputSurface::DidLoseOutputSurface() { |
| 24 | // Android WebView does not handle context loss. |
| 25 | LOG(FATAL) << "Render thread context loss"; |
| 26 | } |
| 27 | |
jbauman | 7064ae37 | 2015-12-15 21:21:02 | [diff] [blame] | 28 | void ParentOutputSurface::Reshape(const gfx::Size& size, |
| 29 | float scale_factor, |
ccameron | 3d74bb9 | 2016-06-30 21:35:46 | [diff] [blame] | 30 | const gfx::ColorSpace& color_space, |
jbauman | 7064ae37 | 2015-12-15 21:21:02 | [diff] [blame] | 31 | bool has_alpha) { |
jbauman | a783bb0 | 2015-06-05 00:57:35 | [diff] [blame] | 32 | DCHECK_EQ(1.f, scale_factor); |
| 33 | surface_size_ = size; |
| 34 | } |
| 35 | |
fsamuel | d63137a | 2016-06-24 23:39:51 | [diff] [blame] | 36 | void ParentOutputSurface::SwapBuffers(cc::CompositorFrame frame) { |
[email protected] | 8705654b | 2014-05-24 01:16:19 | [diff] [blame] | 37 | context_provider_->ContextGL()->ShallowFlushCHROMIUM(); |
[email protected] | 8705654b | 2014-05-24 01:16:19 | [diff] [blame] | 38 | } |
| 39 | |
boliu | 0ed4f65 | 2016-01-09 00:07:26 | [diff] [blame] | 40 | void 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 | |
danakj | a85bd24 | 2016-06-22 22:25:49 | [diff] [blame] | 59 | uint32_t ParentOutputSurface::GetFramebufferCopyTextureFormat() { |
| 60 | auto* gl = static_cast<AwRenderThreadContextProvider*>(context_provider()); |
| 61 | return gl->GetCopyTextureInternalFormat(); |
| 62 | } |
| 63 | |
boliu | 0ed4f65 | 2016-01-09 00:07:26 | [diff] [blame] | 64 | void ParentOutputSurface::SetGLState(const ScopedAppGLStateRestore& gl_state) { |
| 65 | stencil_state_ = gl_state.stencil_state(); |
| 66 | SetExternalStencilTest(stencil_state_.stencil_test_enabled); |
| 67 | } |
| 68 | |
[email protected] | 8705654b | 2014-05-24 01:16:19 | [diff] [blame] | 69 | } // namespace android_webview |