Commit bea0d6b3 authored by Peng Huang's avatar Peng Huang Committed by Commit Bot

Move context state related methods out of DecoderContext

This CL adds a new GLContextVirtualDelegate interface to contain all
context state related methods from DecoderContext. After this one, I am
going to implement GLContextVirtualDelegate in RasterDecoderContextState
and only create one GLContextVirtual for all raster decoder and display
compositor.

Bug: 900941, 902904
Change-Id: I10d80bea8531885c449a2e676ce0552e9363b34c
Reviewed-on: https://chromium-review.googlesource.com/c/1312338Reviewed-by: default avatarAntoine Labour <piman@chromium.org>
Commit-Queue: Peng Huang <penghuang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606777}
parent 2b549d86
...@@ -127,6 +127,7 @@ target(link_target_type, "gles2_sources") { ...@@ -127,6 +127,7 @@ target(link_target_type, "gles2_sources") {
"framebuffer_manager.h", "framebuffer_manager.h",
"gl_context_virtual.cc", "gl_context_virtual.cc",
"gl_context_virtual.h", "gl_context_virtual.h",
"gl_context_virtual_delegate.h",
"gl_state_restorer_impl.cc", "gl_state_restorer_impl.cc",
"gl_state_restorer_impl.h", "gl_state_restorer_impl.h",
"gl_utils.cc", "gl_utils.cc",
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "gpu/command_buffer/common/context_result.h" #include "gpu/command_buffer/common/context_result.h"
#include "gpu/command_buffer/service/abstract_texture.h" #include "gpu/command_buffer/service/abstract_texture.h"
#include "gpu/command_buffer/service/async_api_interface.h" #include "gpu/command_buffer/service/async_api_interface.h"
#include "gpu/command_buffer/service/gl_context_virtual_delegate.h"
#include "gpu/gpu_gles2_export.h" #include "gpu/gpu_gles2_export.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
...@@ -27,7 +28,6 @@ class GLSurface; ...@@ -27,7 +28,6 @@ class GLSurface;
} // namespace gl } // namespace gl
namespace gpu { namespace gpu {
class QueryManager;
class TextureBase; class TextureBase;
struct ContextCreationAttribs; struct ContextCreationAttribs;
...@@ -38,14 +38,14 @@ class FeatureInfo; ...@@ -38,14 +38,14 @@ class FeatureInfo;
class GpuFenceManager; class GpuFenceManager;
class Outputter; class Outputter;
class Texture; class Texture;
struct ContextState;
struct DisallowedFeatures; struct DisallowedFeatures;
} // namespace gles2 } // namespace gles2
// Abstract interface implemented by {Raster,GLES2}Decoder. It is called a // Abstract interface implemented by {Raster,GLES2}Decoder. It is called a
// DecoderContext because all methods are about decoding commands or // DecoderContext because all methods are about decoding commands or
// accessing context/state generated by decoded commands. // accessing context/state generated by decoded commands.
class GPU_GLES2_EXPORT DecoderContext : public AsyncAPIInterface { class GPU_GLES2_EXPORT DecoderContext : public AsyncAPIInterface,
public GLContextVirtualDelegate {
public: public:
DecoderContext() = default; DecoderContext() = default;
~DecoderContext() override = default; ~DecoderContext() override = default;
...@@ -105,9 +105,6 @@ class GPU_GLES2_EXPORT DecoderContext : public AsyncAPIInterface { ...@@ -105,9 +105,6 @@ class GPU_GLES2_EXPORT DecoderContext : public AsyncAPIInterface {
// to context loss. // to context loss.
virtual bool CheckResetStatus() = 0; virtual bool CheckResetStatus() = 0;
// Gets the QueryManager for this context.
virtual QueryManager* GetQueryManager() = 0;
// Set a callback to be called when a query is complete. If the query is // Set a callback to be called when a query is complete. If the query is
// invalid, the callback must be called immediately. // invalid, the callback must be called immediately.
virtual void SetQueryCallback(unsigned int query_client_id, virtual void SetQueryCallback(unsigned int query_client_id,
...@@ -134,33 +131,6 @@ class GPU_GLES2_EXPORT DecoderContext : public AsyncAPIInterface { ...@@ -134,33 +131,6 @@ class GPU_GLES2_EXPORT DecoderContext : public AsyncAPIInterface {
// Perform necessary polling. // Perform necessary polling.
virtual void PerformPollingWork() = 0; virtual void PerformPollingWork() = 0;
//
// Methods required by GLStateRestorerImpl.
//
virtual bool initialized() const = 0;
virtual const gles2::ContextState* GetContextState() = 0;
// Restores all of the decoder GL state.
virtual void RestoreState(const gles2::ContextState* prev_state) = 0;
// Restore States.
virtual void RestoreGlobalState() const = 0;
virtual void ClearAllAttributes() const = 0;
virtual void RestoreAllAttributes() const = 0;
virtual void RestoreActiveTexture() const = 0;
virtual void RestoreAllTextureUnitAndSamplerBindings(
const gles2::ContextState* prev_state) const = 0;
virtual void RestoreActiveTextureUnitBinding(unsigned int target) const = 0;
virtual void RestoreBufferBinding(unsigned int target) = 0;
virtual void RestoreBufferBindings() const = 0;
virtual void RestoreFramebufferBindings() const = 0;
virtual void RestoreRenderbufferBindings() = 0;
virtual void RestoreProgramBindings() const = 0;
virtual void RestoreTextureState(unsigned service_id) const = 0;
virtual void RestoreTextureUnitBindings(unsigned unit) const = 0;
virtual void RestoreVertexAttribArray(unsigned index) = 0;
virtual void RestoreAllExternalTextureBindingsIfNeeded() = 0;
// //
// Methods required by GpuVideoDecodeAccelerator. // Methods required by GpuVideoDecodeAccelerator.
// //
...@@ -232,6 +202,7 @@ class GPU_GLES2_EXPORT DecoderContext : public AsyncAPIInterface { ...@@ -232,6 +202,7 @@ class GPU_GLES2_EXPORT DecoderContext : public AsyncAPIInterface {
int width, int width,
int height, int height,
int depth) = 0; int depth) = 0;
// //
// Methods required by InProcessCommandBuffer // Methods required by InProcessCommandBuffer
// //
......
...@@ -21,16 +21,17 @@ ...@@ -21,16 +21,17 @@
namespace gpu { namespace gpu {
GLContextVirtual::GLContextVirtual(gl::GLShareGroup* share_group, GLContextVirtual::GLContextVirtual(
gl::GLContext* shared_context, gl::GLShareGroup* share_group,
base::WeakPtr<DecoderContext> decoder) gl::GLContext* shared_context,
base::WeakPtr<GLContextVirtualDelegate> delegate)
: GLContext(share_group), : GLContext(share_group),
shared_context_(shared_context), shared_context_(shared_context),
decoder_(decoder) {} delegate_(delegate) {}
bool GLContextVirtual::Initialize(gl::GLSurface* compatible_surface, bool GLContextVirtual::Initialize(gl::GLSurface* compatible_surface,
const gl::GLContextAttribs& attribs) { const gl::GLContextAttribs& attribs) {
SetGLStateRestorer(new GLStateRestorerImpl(decoder_)); SetGLStateRestorer(new GLStateRestorerImpl(delegate_));
return shared_context_->MakeVirtuallyCurrent(this, compatible_surface); return shared_context_->MakeVirtuallyCurrent(this, compatible_surface);
} }
...@@ -40,7 +41,7 @@ void GLContextVirtual::Destroy() { ...@@ -40,7 +41,7 @@ void GLContextVirtual::Destroy() {
} }
bool GLContextVirtual::MakeCurrent(gl::GLSurface* surface) { bool GLContextVirtual::MakeCurrent(gl::GLSurface* surface) {
if (decoder_.get()) if (delegate_.get())
return shared_context_->MakeVirtuallyCurrent(this, surface); return shared_context_->MakeVirtuallyCurrent(this, surface);
LOG(ERROR) << "Trying to make virtual context current without decoder."; LOG(ERROR) << "Trying to make virtual context current without decoder.";
......
...@@ -21,14 +21,14 @@ class GLSurface; ...@@ -21,14 +21,14 @@ class GLSurface;
} }
namespace gpu { namespace gpu {
class DecoderContext; class GLContextVirtualDelegate;
// Encapsulates a virtual OpenGL context. // Encapsulates a virtual OpenGL context.
class GPU_GLES2_EXPORT GLContextVirtual : public gl::GLContext { class GPU_GLES2_EXPORT GLContextVirtual : public gl::GLContext {
public: public:
GLContextVirtual(gl::GLShareGroup* share_group, GLContextVirtual(gl::GLShareGroup* share_group,
gl::GLContext* shared_context, gl::GLContext* shared_context,
base::WeakPtr<DecoderContext> decoder); base::WeakPtr<GLContextVirtualDelegate> delegate);
// Implement GLContext. // Implement GLContext.
bool Initialize(gl::GLSurface* compatible_surface, bool Initialize(gl::GLSurface* compatible_surface,
...@@ -61,7 +61,7 @@ class GPU_GLES2_EXPORT GLContextVirtual : public gl::GLContext { ...@@ -61,7 +61,7 @@ class GPU_GLES2_EXPORT GLContextVirtual : public gl::GLContext {
void Destroy(); void Destroy();
scoped_refptr<gl::GLContext> shared_context_; scoped_refptr<gl::GLContext> shared_context_;
base::WeakPtr<DecoderContext> decoder_; base::WeakPtr<GLContextVirtualDelegate> delegate_;
DISALLOW_COPY_AND_ASSIGN(GLContextVirtual); DISALLOW_COPY_AND_ASSIGN(GLContextVirtual);
}; };
......
// Copyright 2018 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.
#ifndef GPU_COMMAND_BUFFER_SERVICE_GL_CONTEXT_VIRTUAL_DELEGATE_H_
#define GPU_COMMAND_BUFFER_SERVICE_GL_CONTEXT_VIRTUAL_DELEGATE_H_
#include <stddef.h>
#include <stdint.h>
#include "base/memory/weak_ptr.h"
#include "gpu/gpu_gles2_export.h"
namespace gpu {
class QueryManager;
namespace gles2 {
struct ContextState;
} // namespace gles2
class GPU_GLES2_EXPORT GLContextVirtualDelegate {
public:
GLContextVirtualDelegate() = default;
virtual ~GLContextVirtualDelegate() = default;
virtual bool initialized() const = 0;
virtual const gles2::ContextState* GetContextState() = 0;
// Restores all of the decoder GL state.
virtual void RestoreState(const gles2::ContextState* prev_state) = 0;
// Restore States.
virtual void RestoreGlobalState() const = 0;
virtual void ClearAllAttributes() const = 0;
virtual void RestoreAllAttributes() const = 0;
virtual void RestoreActiveTexture() const = 0;
virtual void RestoreAllTextureUnitAndSamplerBindings(
const gles2::ContextState* prev_state) const = 0;
virtual void RestoreActiveTextureUnitBinding(unsigned int target) const = 0;
virtual void RestoreBufferBinding(unsigned int target) = 0;
virtual void RestoreBufferBindings() const = 0;
virtual void RestoreFramebufferBindings() const = 0;
virtual void RestoreRenderbufferBindings() = 0;
virtual void RestoreProgramBindings() const = 0;
virtual void RestoreTextureState(unsigned service_id) const = 0;
virtual void RestoreTextureUnitBindings(unsigned unit) const = 0;
virtual void RestoreVertexAttribArray(unsigned index) = 0;
virtual void RestoreAllExternalTextureBindingsIfNeeded() = 0;
virtual QueryManager* GetQueryManager() = 0;
};
} // namespace gpu
#endif // GPU_COMMAND_BUFFER_SERVICE_GL_CONTEXT_VIRTUAL_DELEGATE_H_
...@@ -4,83 +4,84 @@ ...@@ -4,83 +4,84 @@
#include "gpu/command_buffer/service/gl_state_restorer_impl.h" #include "gpu/command_buffer/service/gl_state_restorer_impl.h"
#include "gpu/command_buffer/service/decoder_context.h" #include "gpu/command_buffer/service/gl_context_virtual_delegate.h"
#include "gpu/command_buffer/service/query_manager.h" #include "gpu/command_buffer/service/query_manager.h"
namespace gpu { namespace gpu {
GLStateRestorerImpl::GLStateRestorerImpl(base::WeakPtr<DecoderContext> decoder) GLStateRestorerImpl::GLStateRestorerImpl(
: decoder_(decoder) {} base::WeakPtr<GLContextVirtualDelegate> delegate)
: delegate_(delegate) {}
GLStateRestorerImpl::~GLStateRestorerImpl() = default; GLStateRestorerImpl::~GLStateRestorerImpl() = default;
bool GLStateRestorerImpl::IsInitialized() { bool GLStateRestorerImpl::IsInitialized() {
DCHECK(decoder_.get()); DCHECK(delegate_.get());
return decoder_->initialized(); return delegate_->initialized();
} }
void GLStateRestorerImpl::RestoreState(const gl::GLStateRestorer* prev_state) { void GLStateRestorerImpl::RestoreState(const gl::GLStateRestorer* prev_state) {
DCHECK(decoder_.get()); DCHECK(delegate_.get());
const GLStateRestorerImpl* restorer_impl = const GLStateRestorerImpl* restorer_impl =
static_cast<const GLStateRestorerImpl*>(prev_state); static_cast<const GLStateRestorerImpl*>(prev_state);
decoder_->RestoreState(restorer_impl ? restorer_impl->GetContextState() delegate_->RestoreState(restorer_impl ? restorer_impl->GetContextState()
: nullptr); : nullptr);
} }
void GLStateRestorerImpl::RestoreAllTextureUnitAndSamplerBindings() { void GLStateRestorerImpl::RestoreAllTextureUnitAndSamplerBindings() {
DCHECK(decoder_.get()); DCHECK(delegate_.get());
decoder_->RestoreAllTextureUnitAndSamplerBindings(nullptr); delegate_->RestoreAllTextureUnitAndSamplerBindings(nullptr);
} }
void GLStateRestorerImpl::RestoreActiveTexture() { void GLStateRestorerImpl::RestoreActiveTexture() {
DCHECK(decoder_.get()); DCHECK(delegate_.get());
decoder_->RestoreActiveTexture(); delegate_->RestoreActiveTexture();
} }
void GLStateRestorerImpl::RestoreActiveTextureUnitBinding(unsigned int target) { void GLStateRestorerImpl::RestoreActiveTextureUnitBinding(unsigned int target) {
DCHECK(decoder_.get()); DCHECK(delegate_.get());
decoder_->RestoreActiveTextureUnitBinding(target); delegate_->RestoreActiveTextureUnitBinding(target);
} }
void GLStateRestorerImpl::RestoreAllExternalTextureBindingsIfNeeded() { void GLStateRestorerImpl::RestoreAllExternalTextureBindingsIfNeeded() {
DCHECK(decoder_.get()); DCHECK(delegate_.get());
decoder_->RestoreAllExternalTextureBindingsIfNeeded(); delegate_->RestoreAllExternalTextureBindingsIfNeeded();
} }
void GLStateRestorerImpl::RestoreFramebufferBindings() { void GLStateRestorerImpl::RestoreFramebufferBindings() {
DCHECK(decoder_.get()); DCHECK(delegate_.get());
decoder_->RestoreFramebufferBindings(); delegate_->RestoreFramebufferBindings();
} }
void GLStateRestorerImpl::RestoreProgramBindings() { void GLStateRestorerImpl::RestoreProgramBindings() {
DCHECK(decoder_.get()); DCHECK(delegate_.get());
decoder_->RestoreProgramBindings(); delegate_->RestoreProgramBindings();
} }
void GLStateRestorerImpl::RestoreBufferBinding(unsigned int target) { void GLStateRestorerImpl::RestoreBufferBinding(unsigned int target) {
DCHECK(decoder_.get()); DCHECK(delegate_.get());
decoder_->RestoreBufferBinding(target); delegate_->RestoreBufferBinding(target);
} }
void GLStateRestorerImpl::RestoreVertexAttribArray(unsigned int index) { void GLStateRestorerImpl::RestoreVertexAttribArray(unsigned int index) {
DCHECK(decoder_.get()); DCHECK(delegate_.get());
decoder_->RestoreVertexAttribArray(index); delegate_->RestoreVertexAttribArray(index);
} }
void GLStateRestorerImpl::PauseQueries() { void GLStateRestorerImpl::PauseQueries() {
DCHECK(decoder_.get()); DCHECK(delegate_.get());
decoder_->GetQueryManager()->PauseQueries(); delegate_->GetQueryManager()->PauseQueries();
} }
void GLStateRestorerImpl::ResumeQueries() { void GLStateRestorerImpl::ResumeQueries() {
DCHECK(decoder_.get()); DCHECK(delegate_.get());
decoder_->GetQueryManager()->ResumeQueries(); delegate_->GetQueryManager()->ResumeQueries();
} }
const gles2::ContextState* GLStateRestorerImpl::GetContextState() const { const gles2::ContextState* GLStateRestorerImpl::GetContextState() const {
DCHECK(decoder_.get()); DCHECK(delegate_.get());
return decoder_->GetContextState(); return delegate_->GetContextState();
} }
} // namespace gpu } // namespace gpu
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
namespace gpu { namespace gpu {
class DecoderContext; class GLContextVirtualDelegate;
namespace gles2 { namespace gles2 {
struct ContextState; struct ContextState;
...@@ -24,7 +24,8 @@ struct ContextState; ...@@ -24,7 +24,8 @@ struct ContextState;
// This class implements a GLStateRestorer that forwards to a DecoderContext. // This class implements a GLStateRestorer that forwards to a DecoderContext.
class GPU_GLES2_EXPORT GLStateRestorerImpl : public gl::GLStateRestorer { class GPU_GLES2_EXPORT GLStateRestorerImpl : public gl::GLStateRestorer {
public: public:
explicit GLStateRestorerImpl(base::WeakPtr<DecoderContext> decoder); explicit GLStateRestorerImpl(
base::WeakPtr<GLContextVirtualDelegate> delegate);
~GLStateRestorerImpl() override; ~GLStateRestorerImpl() override;
bool IsInitialized() override; bool IsInitialized() override;
...@@ -42,7 +43,7 @@ class GPU_GLES2_EXPORT GLStateRestorerImpl : public gl::GLStateRestorer { ...@@ -42,7 +43,7 @@ class GPU_GLES2_EXPORT GLStateRestorerImpl : public gl::GLStateRestorer {
private: private:
const gles2::ContextState* GetContextState() const; const gles2::ContextState* GetContextState() const;
base::WeakPtr<DecoderContext> decoder_; base::WeakPtr<GLContextVirtualDelegate> delegate_;
DISALLOW_COPY_AND_ASSIGN(GLStateRestorerImpl); DISALLOW_COPY_AND_ASSIGN(GLStateRestorerImpl);
}; };
......
...@@ -361,7 +361,7 @@ bool PermitsInconsistentContextState(CommandId command) { ...@@ -361,7 +361,7 @@ bool PermitsInconsistentContextState(CommandId command) {
// command doesn't inspect/modify GL state (InsertSyncPoint, // command doesn't inspect/modify GL state (InsertSyncPoint,
// CreateAndConsumeTexture) or it requires and maintains that GrContext // CreateAndConsumeTexture) or it requires and maintains that GrContext
// state tracking matches GL context state (e.g. *RasterCHROMIUM --- see // state tracking matches GL context state (e.g. *RasterCHROMIUM --- see
// PessimisticallyResetGrContext). // raster_decoder_context_state_->PessimisticallyResetGrContext).
// //
// Case 2b: Executing a command that is not whitelisted: We force GL state to // Case 2b: Executing a command that is not whitelisted: We force GL state to
// match |state_| as necessary (see |need_context_state_reset|) in // match |state_| as necessary (see |need_context_state_reset|) in
...@@ -601,15 +601,6 @@ class RasterDecoderImpl final : public RasterDecoder, ...@@ -601,15 +601,6 @@ class RasterDecoderImpl final : public RasterDecoder,
// CommandExecutor(). // CommandExecutor().
void ExitCommandProcessingEarly() { commands_to_process_ = 0; } void ExitCommandProcessingEarly() { commands_to_process_ = 0; }
void PessimisticallyResetGrContext() const {
// Calling GrContext::resetContext() is very cheap, so we do it
// pessimistically. We could dirty less state if skia state setting
// performance becomes an issue.
if (gr_context()) {
gr_context()->resetContext();
}
}
template <bool DebugImpl> template <bool DebugImpl>
error::Error DoCommandsImpl(unsigned int num_commands, error::Error DoCommandsImpl(unsigned int num_commands,
const volatile void* buffer, const volatile void* buffer,
...@@ -1226,7 +1217,7 @@ Capabilities RasterDecoderImpl::GetCapabilities() { ...@@ -1226,7 +1217,7 @@ Capabilities RasterDecoderImpl::GetCapabilities() {
} }
void RasterDecoderImpl::RestoreGlobalState() const { void RasterDecoderImpl::RestoreGlobalState() const {
PessimisticallyResetGrContext(); raster_decoder_context_state_->PessimisticallyResetGrContext();
state_.RestoreGlobalState(nullptr); state_.RestoreGlobalState(nullptr);
} }
...@@ -1245,36 +1236,36 @@ void RasterDecoderImpl::ClearAllAttributes() const { ...@@ -1245,36 +1236,36 @@ void RasterDecoderImpl::ClearAllAttributes() const {
} }
void RasterDecoderImpl::RestoreAllAttributes() const { void RasterDecoderImpl::RestoreAllAttributes() const {
PessimisticallyResetGrContext(); raster_decoder_context_state_->PessimisticallyResetGrContext();
state_.RestoreVertexAttribs(nullptr); state_.RestoreVertexAttribs(nullptr);
} }
void RasterDecoderImpl::RestoreState(const gles2::ContextState* prev_state) { void RasterDecoderImpl::RestoreState(const gles2::ContextState* prev_state) {
TRACE_EVENT1("gpu", "RasterDecoderImpl::RestoreState", "context", TRACE_EVENT1("gpu", "RasterDecoderImpl::RestoreState", "context",
logger_.GetLogPrefix()); logger_.GetLogPrefix());
PessimisticallyResetGrContext(); raster_decoder_context_state_->PessimisticallyResetGrContext();
state_.RestoreState(prev_state); state_.RestoreState(prev_state);
} }
void RasterDecoderImpl::RestoreActiveTexture() const { void RasterDecoderImpl::RestoreActiveTexture() const {
PessimisticallyResetGrContext(); raster_decoder_context_state_->PessimisticallyResetGrContext();
state_.RestoreActiveTexture(); state_.RestoreActiveTexture();
} }
void RasterDecoderImpl::RestoreAllTextureUnitAndSamplerBindings( void RasterDecoderImpl::RestoreAllTextureUnitAndSamplerBindings(
const gles2::ContextState* prev_state) const { const gles2::ContextState* prev_state) const {
PessimisticallyResetGrContext(); raster_decoder_context_state_->PessimisticallyResetGrContext();
state_.RestoreAllTextureUnitAndSamplerBindings(prev_state); state_.RestoreAllTextureUnitAndSamplerBindings(prev_state);
} }
void RasterDecoderImpl::RestoreActiveTextureUnitBinding( void RasterDecoderImpl::RestoreActiveTextureUnitBinding(
unsigned int target) const { unsigned int target) const {
PessimisticallyResetGrContext(); raster_decoder_context_state_->PessimisticallyResetGrContext();
state_.RestoreActiveTextureUnitBinding(target); state_.RestoreActiveTextureUnitBinding(target);
} }
void RasterDecoderImpl::RestoreBufferBinding(unsigned int target) { void RasterDecoderImpl::RestoreBufferBinding(unsigned int target) {
PessimisticallyResetGrContext(); raster_decoder_context_state_->PessimisticallyResetGrContext();
if (target == GL_PIXEL_PACK_BUFFER) { if (target == GL_PIXEL_PACK_BUFFER) {
state_.UpdatePackParameters(); state_.UpdatePackParameters();
} else if (target == GL_PIXEL_UNPACK_BUFFER) { } else if (target == GL_PIXEL_UNPACK_BUFFER) {
...@@ -1286,12 +1277,12 @@ void RasterDecoderImpl::RestoreBufferBinding(unsigned int target) { ...@@ -1286,12 +1277,12 @@ void RasterDecoderImpl::RestoreBufferBinding(unsigned int target) {
} }
void RasterDecoderImpl::RestoreBufferBindings() const { void RasterDecoderImpl::RestoreBufferBindings() const {
PessimisticallyResetGrContext(); raster_decoder_context_state_->PessimisticallyResetGrContext();
state_.RestoreBufferBindings(); state_.RestoreBufferBindings();
} }
void RasterDecoderImpl::RestoreFramebufferBindings() const { void RasterDecoderImpl::RestoreFramebufferBindings() const {
PessimisticallyResetGrContext(); raster_decoder_context_state_->PessimisticallyResetGrContext();
state_.fbo_binding_for_scissor_workaround_dirty = true; state_.fbo_binding_for_scissor_workaround_dirty = true;
state_.stencil_state_changed_since_validation = true; state_.stencil_state_changed_since_validation = true;
...@@ -1300,17 +1291,17 @@ void RasterDecoderImpl::RestoreFramebufferBindings() const { ...@@ -1300,17 +1291,17 @@ void RasterDecoderImpl::RestoreFramebufferBindings() const {
} }
void RasterDecoderImpl::RestoreRenderbufferBindings() { void RasterDecoderImpl::RestoreRenderbufferBindings() {
PessimisticallyResetGrContext(); raster_decoder_context_state_->PessimisticallyResetGrContext();
state_.RestoreRenderbufferBindings(); state_.RestoreRenderbufferBindings();
} }
void RasterDecoderImpl::RestoreProgramBindings() const { void RasterDecoderImpl::RestoreProgramBindings() const {
PessimisticallyResetGrContext(); raster_decoder_context_state_->PessimisticallyResetGrContext();
state_.RestoreProgramSettings(nullptr, false); state_.RestoreProgramSettings(nullptr, false);
} }
void RasterDecoderImpl::RestoreTextureState(unsigned service_id) const { void RasterDecoderImpl::RestoreTextureState(unsigned service_id) const {
PessimisticallyResetGrContext(); raster_decoder_context_state_->PessimisticallyResetGrContext();
gles2::Texture* texture = gles2::Texture* texture =
texture_manager()->GetTextureForServiceId(service_id); texture_manager()->GetTextureForServiceId(service_id);
if (texture) { if (texture) {
...@@ -1331,7 +1322,7 @@ void RasterDecoderImpl::RestoreTextureState(unsigned service_id) const { ...@@ -1331,7 +1322,7 @@ void RasterDecoderImpl::RestoreTextureState(unsigned service_id) const {
} }
void RasterDecoderImpl::RestoreTextureUnitBindings(unsigned unit) const { void RasterDecoderImpl::RestoreTextureUnitBindings(unsigned unit) const {
PessimisticallyResetGrContext(); raster_decoder_context_state_->PessimisticallyResetGrContext();
state_.RestoreTextureUnitBindings(unit, nullptr); state_.RestoreTextureUnitBindings(unit, nullptr);
} }
...@@ -1340,7 +1331,7 @@ void RasterDecoderImpl::RestoreVertexAttribArray(unsigned index) { ...@@ -1340,7 +1331,7 @@ void RasterDecoderImpl::RestoreVertexAttribArray(unsigned index) {
} }
void RasterDecoderImpl::RestoreAllExternalTextureBindingsIfNeeded() { void RasterDecoderImpl::RestoreAllExternalTextureBindingsIfNeeded() {
PessimisticallyResetGrContext(); raster_decoder_context_state_->PessimisticallyResetGrContext();
if (texture_manager()->GetServiceIdGeneration() == if (texture_manager()->GetServiceIdGeneration() ==
texture_manager_service_id_generation_) texture_manager_service_id_generation_)
return; return;
...@@ -3393,7 +3384,7 @@ void RasterDecoderImpl::DoDeleteTransferCacheEntryINTERNAL( ...@@ -3393,7 +3384,7 @@ void RasterDecoderImpl::DoDeleteTransferCacheEntryINTERNAL(
} }
void RasterDecoderImpl::DoBindVertexArrayOES(GLuint client_id) { void RasterDecoderImpl::DoBindVertexArrayOES(GLuint client_id) {
PessimisticallyResetGrContext(); raster_decoder_context_state_->PessimisticallyResetGrContext();
gles2::VertexAttribManager* vao = nullptr; gles2::VertexAttribManager* vao = nullptr;
if (client_id != 0) { if (client_id != 0) {
vao = GetVertexAttribManager(client_id); vao = GetVertexAttribManager(client_id);
...@@ -3443,7 +3434,7 @@ void RasterDecoderImpl::EmulateVertexArrayState() { ...@@ -3443,7 +3434,7 @@ void RasterDecoderImpl::EmulateVertexArrayState() {
void RasterDecoderImpl::RestoreStateForAttrib(GLuint attrib_index, void RasterDecoderImpl::RestoreStateForAttrib(GLuint attrib_index,
bool restore_array_binding) { bool restore_array_binding) {
PessimisticallyResetGrContext(); raster_decoder_context_state_->PessimisticallyResetGrContext();
const gles2::VertexAttrib* attrib = const gles2::VertexAttrib* attrib =
state_.vertex_attrib_manager->GetVertexAttrib(attrib_index); state_.vertex_attrib_manager->GetVertexAttrib(attrib_index);
if (restore_array_binding) { if (restore_array_binding) {
......
...@@ -144,5 +144,13 @@ void RasterDecoderContextState::PurgeMemory( ...@@ -144,5 +144,13 @@ void RasterDecoderContextState::PurgeMemory(
transfer_cache->PurgeMemory(memory_pressure_level); transfer_cache->PurgeMemory(memory_pressure_level);
} }
void RasterDecoderContextState::PessimisticallyResetGrContext() const {
// Calling GrContext::resetContext() is very cheap, so we do it
// pessimistically. We could dirty less state if skia state setting
// performance becomes an issue.
if (gr_context && !use_vulkan_gr_context)
gr_context->resetContext();
}
} // namespace raster } // namespace raster
} // namespace gpu } // namespace gpu
...@@ -50,6 +50,8 @@ struct GPU_GLES2_EXPORT RasterDecoderContextState ...@@ -50,6 +50,8 @@ struct GPU_GLES2_EXPORT RasterDecoderContextState
void PurgeMemory( void PurgeMemory(
base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level); base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level);
void PessimisticallyResetGrContext() const;
scoped_refptr<gl::GLShareGroup> share_group; scoped_refptr<gl::GLShareGroup> share_group;
scoped_refptr<gl::GLSurface> surface; scoped_refptr<gl::GLSurface> surface;
scoped_refptr<gl::GLContext> context; scoped_refptr<gl::GLContext> context;
......
...@@ -72,7 +72,7 @@ class WrappedSkImage : public SharedImageBacking { ...@@ -72,7 +72,7 @@ class WrappedSkImage : public SharedImageBacking {
const SkSurfaceProps& surface_props) { const SkSurfaceProps& surface_props) {
if (context_state_->context_lost) if (context_state_->context_lost)
return nullptr; return nullptr;
DCHECK(context_state_->context->IsCurrent(context_state_->surface.get())); DCHECK(context_state_->context->IsCurrent(nullptr));
GrBackendTexture gr_texture = GrBackendTexture gr_texture =
image_->getBackendTexture(/*flushPendingGrContextIO=*/true); image_->getBackendTexture(/*flushPendingGrContextIO=*/true);
DCHECK(gr_texture.isValid()); DCHECK(gr_texture.isValid());
......
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