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") {
"framebuffer_manager.h",
"gl_context_virtual.cc",
"gl_context_virtual.h",
"gl_context_virtual_delegate.h",
"gl_state_restorer_impl.cc",
"gl_state_restorer_impl.h",
"gl_utils.cc",
......
......@@ -17,6 +17,7 @@
#include "gpu/command_buffer/common/context_result.h"
#include "gpu/command_buffer/service/abstract_texture.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 "ui/gfx/geometry/rect.h"
......@@ -27,7 +28,6 @@ class GLSurface;
} // namespace gl
namespace gpu {
class QueryManager;
class TextureBase;
struct ContextCreationAttribs;
......@@ -38,14 +38,14 @@ class FeatureInfo;
class GpuFenceManager;
class Outputter;
class Texture;
struct ContextState;
struct DisallowedFeatures;
} // namespace gles2
// Abstract interface implemented by {Raster,GLES2}Decoder. It is called a
// DecoderContext because all methods are about decoding commands or
// accessing context/state generated by decoded commands.
class GPU_GLES2_EXPORT DecoderContext : public AsyncAPIInterface {
class GPU_GLES2_EXPORT DecoderContext : public AsyncAPIInterface,
public GLContextVirtualDelegate {
public:
DecoderContext() = default;
~DecoderContext() override = default;
......@@ -105,9 +105,6 @@ class GPU_GLES2_EXPORT DecoderContext : public AsyncAPIInterface {
// to context loss.
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
// invalid, the callback must be called immediately.
virtual void SetQueryCallback(unsigned int query_client_id,
......@@ -134,33 +131,6 @@ class GPU_GLES2_EXPORT DecoderContext : public AsyncAPIInterface {
// Perform necessary polling.
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.
//
......@@ -232,6 +202,7 @@ class GPU_GLES2_EXPORT DecoderContext : public AsyncAPIInterface {
int width,
int height,
int depth) = 0;
//
// Methods required by InProcessCommandBuffer
//
......
......@@ -21,16 +21,17 @@
namespace gpu {
GLContextVirtual::GLContextVirtual(gl::GLShareGroup* share_group,
gl::GLContext* shared_context,
base::WeakPtr<DecoderContext> decoder)
GLContextVirtual::GLContextVirtual(
gl::GLShareGroup* share_group,
gl::GLContext* shared_context,
base::WeakPtr<GLContextVirtualDelegate> delegate)
: GLContext(share_group),
shared_context_(shared_context),
decoder_(decoder) {}
delegate_(delegate) {}
bool GLContextVirtual::Initialize(gl::GLSurface* compatible_surface,
const gl::GLContextAttribs& attribs) {
SetGLStateRestorer(new GLStateRestorerImpl(decoder_));
SetGLStateRestorer(new GLStateRestorerImpl(delegate_));
return shared_context_->MakeVirtuallyCurrent(this, compatible_surface);
}
......@@ -40,7 +41,7 @@ void GLContextVirtual::Destroy() {
}
bool GLContextVirtual::MakeCurrent(gl::GLSurface* surface) {
if (decoder_.get())
if (delegate_.get())
return shared_context_->MakeVirtuallyCurrent(this, surface);
LOG(ERROR) << "Trying to make virtual context current without decoder.";
......
......@@ -21,14 +21,14 @@ class GLSurface;
}
namespace gpu {
class DecoderContext;
class GLContextVirtualDelegate;
// Encapsulates a virtual OpenGL context.
class GPU_GLES2_EXPORT GLContextVirtual : public gl::GLContext {
public:
GLContextVirtual(gl::GLShareGroup* share_group,
gl::GLContext* shared_context,
base::WeakPtr<DecoderContext> decoder);
base::WeakPtr<GLContextVirtualDelegate> delegate);
// Implement GLContext.
bool Initialize(gl::GLSurface* compatible_surface,
......@@ -61,7 +61,7 @@ class GPU_GLES2_EXPORT GLContextVirtual : public gl::GLContext {
void Destroy();
scoped_refptr<gl::GLContext> shared_context_;
base::WeakPtr<DecoderContext> decoder_;
base::WeakPtr<GLContextVirtualDelegate> delegate_;
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 @@
#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"
namespace gpu {
GLStateRestorerImpl::GLStateRestorerImpl(base::WeakPtr<DecoderContext> decoder)
: decoder_(decoder) {}
GLStateRestorerImpl::GLStateRestorerImpl(
base::WeakPtr<GLContextVirtualDelegate> delegate)
: delegate_(delegate) {}
GLStateRestorerImpl::~GLStateRestorerImpl() = default;
bool GLStateRestorerImpl::IsInitialized() {
DCHECK(decoder_.get());
return decoder_->initialized();
DCHECK(delegate_.get());
return delegate_->initialized();
}
void GLStateRestorerImpl::RestoreState(const gl::GLStateRestorer* prev_state) {
DCHECK(decoder_.get());
DCHECK(delegate_.get());
const GLStateRestorerImpl* restorer_impl =
static_cast<const GLStateRestorerImpl*>(prev_state);
decoder_->RestoreState(restorer_impl ? restorer_impl->GetContextState()
: nullptr);
delegate_->RestoreState(restorer_impl ? restorer_impl->GetContextState()
: nullptr);
}
void GLStateRestorerImpl::RestoreAllTextureUnitAndSamplerBindings() {
DCHECK(decoder_.get());
decoder_->RestoreAllTextureUnitAndSamplerBindings(nullptr);
DCHECK(delegate_.get());
delegate_->RestoreAllTextureUnitAndSamplerBindings(nullptr);
}
void GLStateRestorerImpl::RestoreActiveTexture() {
DCHECK(decoder_.get());
decoder_->RestoreActiveTexture();
DCHECK(delegate_.get());
delegate_->RestoreActiveTexture();
}
void GLStateRestorerImpl::RestoreActiveTextureUnitBinding(unsigned int target) {
DCHECK(decoder_.get());
decoder_->RestoreActiveTextureUnitBinding(target);
DCHECK(delegate_.get());
delegate_->RestoreActiveTextureUnitBinding(target);
}
void GLStateRestorerImpl::RestoreAllExternalTextureBindingsIfNeeded() {
DCHECK(decoder_.get());
decoder_->RestoreAllExternalTextureBindingsIfNeeded();
DCHECK(delegate_.get());
delegate_->RestoreAllExternalTextureBindingsIfNeeded();
}
void GLStateRestorerImpl::RestoreFramebufferBindings() {
DCHECK(decoder_.get());
decoder_->RestoreFramebufferBindings();
DCHECK(delegate_.get());
delegate_->RestoreFramebufferBindings();
}
void GLStateRestorerImpl::RestoreProgramBindings() {
DCHECK(decoder_.get());
decoder_->RestoreProgramBindings();
DCHECK(delegate_.get());
delegate_->RestoreProgramBindings();
}
void GLStateRestorerImpl::RestoreBufferBinding(unsigned int target) {
DCHECK(decoder_.get());
decoder_->RestoreBufferBinding(target);
DCHECK(delegate_.get());
delegate_->RestoreBufferBinding(target);
}
void GLStateRestorerImpl::RestoreVertexAttribArray(unsigned int index) {
DCHECK(decoder_.get());
decoder_->RestoreVertexAttribArray(index);
DCHECK(delegate_.get());
delegate_->RestoreVertexAttribArray(index);
}
void GLStateRestorerImpl::PauseQueries() {
DCHECK(decoder_.get());
decoder_->GetQueryManager()->PauseQueries();
DCHECK(delegate_.get());
delegate_->GetQueryManager()->PauseQueries();
}
void GLStateRestorerImpl::ResumeQueries() {
DCHECK(decoder_.get());
decoder_->GetQueryManager()->ResumeQueries();
DCHECK(delegate_.get());
delegate_->GetQueryManager()->ResumeQueries();
}
const gles2::ContextState* GLStateRestorerImpl::GetContextState() const {
DCHECK(decoder_.get());
return decoder_->GetContextState();
DCHECK(delegate_.get());
return delegate_->GetContextState();
}
} // namespace gpu
......@@ -15,7 +15,7 @@
namespace gpu {
class DecoderContext;
class GLContextVirtualDelegate;
namespace gles2 {
struct ContextState;
......@@ -24,7 +24,8 @@ struct ContextState;
// This class implements a GLStateRestorer that forwards to a DecoderContext.
class GPU_GLES2_EXPORT GLStateRestorerImpl : public gl::GLStateRestorer {
public:
explicit GLStateRestorerImpl(base::WeakPtr<DecoderContext> decoder);
explicit GLStateRestorerImpl(
base::WeakPtr<GLContextVirtualDelegate> delegate);
~GLStateRestorerImpl() override;
bool IsInitialized() override;
......@@ -42,7 +43,7 @@ class GPU_GLES2_EXPORT GLStateRestorerImpl : public gl::GLStateRestorer {
private:
const gles2::ContextState* GetContextState() const;
base::WeakPtr<DecoderContext> decoder_;
base::WeakPtr<GLContextVirtualDelegate> delegate_;
DISALLOW_COPY_AND_ASSIGN(GLStateRestorerImpl);
};
......
......@@ -361,7 +361,7 @@ bool PermitsInconsistentContextState(CommandId command) {
// command doesn't inspect/modify GL state (InsertSyncPoint,
// CreateAndConsumeTexture) or it requires and maintains that GrContext
// 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
// match |state_| as necessary (see |need_context_state_reset|) in
......@@ -601,15 +601,6 @@ class RasterDecoderImpl final : public RasterDecoder,
// CommandExecutor().
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>
error::Error DoCommandsImpl(unsigned int num_commands,
const volatile void* buffer,
......@@ -1226,7 +1217,7 @@ Capabilities RasterDecoderImpl::GetCapabilities() {
}
void RasterDecoderImpl::RestoreGlobalState() const {
PessimisticallyResetGrContext();
raster_decoder_context_state_->PessimisticallyResetGrContext();
state_.RestoreGlobalState(nullptr);
}
......@@ -1245,36 +1236,36 @@ void RasterDecoderImpl::ClearAllAttributes() const {
}
void RasterDecoderImpl::RestoreAllAttributes() const {
PessimisticallyResetGrContext();
raster_decoder_context_state_->PessimisticallyResetGrContext();
state_.RestoreVertexAttribs(nullptr);
}
void RasterDecoderImpl::RestoreState(const gles2::ContextState* prev_state) {
TRACE_EVENT1("gpu", "RasterDecoderImpl::RestoreState", "context",
logger_.GetLogPrefix());
PessimisticallyResetGrContext();
raster_decoder_context_state_->PessimisticallyResetGrContext();
state_.RestoreState(prev_state);
}
void RasterDecoderImpl::RestoreActiveTexture() const {
PessimisticallyResetGrContext();
raster_decoder_context_state_->PessimisticallyResetGrContext();
state_.RestoreActiveTexture();
}
void RasterDecoderImpl::RestoreAllTextureUnitAndSamplerBindings(
const gles2::ContextState* prev_state) const {
PessimisticallyResetGrContext();
raster_decoder_context_state_->PessimisticallyResetGrContext();
state_.RestoreAllTextureUnitAndSamplerBindings(prev_state);
}
void RasterDecoderImpl::RestoreActiveTextureUnitBinding(
unsigned int target) const {
PessimisticallyResetGrContext();
raster_decoder_context_state_->PessimisticallyResetGrContext();
state_.RestoreActiveTextureUnitBinding(target);
}
void RasterDecoderImpl::RestoreBufferBinding(unsigned int target) {
PessimisticallyResetGrContext();
raster_decoder_context_state_->PessimisticallyResetGrContext();
if (target == GL_PIXEL_PACK_BUFFER) {
state_.UpdatePackParameters();
} else if (target == GL_PIXEL_UNPACK_BUFFER) {
......@@ -1286,12 +1277,12 @@ void RasterDecoderImpl::RestoreBufferBinding(unsigned int target) {
}
void RasterDecoderImpl::RestoreBufferBindings() const {
PessimisticallyResetGrContext();
raster_decoder_context_state_->PessimisticallyResetGrContext();
state_.RestoreBufferBindings();
}
void RasterDecoderImpl::RestoreFramebufferBindings() const {
PessimisticallyResetGrContext();
raster_decoder_context_state_->PessimisticallyResetGrContext();
state_.fbo_binding_for_scissor_workaround_dirty = true;
state_.stencil_state_changed_since_validation = true;
......@@ -1300,17 +1291,17 @@ void RasterDecoderImpl::RestoreFramebufferBindings() const {
}
void RasterDecoderImpl::RestoreRenderbufferBindings() {
PessimisticallyResetGrContext();
raster_decoder_context_state_->PessimisticallyResetGrContext();
state_.RestoreRenderbufferBindings();
}
void RasterDecoderImpl::RestoreProgramBindings() const {
PessimisticallyResetGrContext();
raster_decoder_context_state_->PessimisticallyResetGrContext();
state_.RestoreProgramSettings(nullptr, false);
}
void RasterDecoderImpl::RestoreTextureState(unsigned service_id) const {
PessimisticallyResetGrContext();
raster_decoder_context_state_->PessimisticallyResetGrContext();
gles2::Texture* texture =
texture_manager()->GetTextureForServiceId(service_id);
if (texture) {
......@@ -1331,7 +1322,7 @@ void RasterDecoderImpl::RestoreTextureState(unsigned service_id) const {
}
void RasterDecoderImpl::RestoreTextureUnitBindings(unsigned unit) const {
PessimisticallyResetGrContext();
raster_decoder_context_state_->PessimisticallyResetGrContext();
state_.RestoreTextureUnitBindings(unit, nullptr);
}
......@@ -1340,7 +1331,7 @@ void RasterDecoderImpl::RestoreVertexAttribArray(unsigned index) {
}
void RasterDecoderImpl::RestoreAllExternalTextureBindingsIfNeeded() {
PessimisticallyResetGrContext();
raster_decoder_context_state_->PessimisticallyResetGrContext();
if (texture_manager()->GetServiceIdGeneration() ==
texture_manager_service_id_generation_)
return;
......@@ -3393,7 +3384,7 @@ void RasterDecoderImpl::DoDeleteTransferCacheEntryINTERNAL(
}
void RasterDecoderImpl::DoBindVertexArrayOES(GLuint client_id) {
PessimisticallyResetGrContext();
raster_decoder_context_state_->PessimisticallyResetGrContext();
gles2::VertexAttribManager* vao = nullptr;
if (client_id != 0) {
vao = GetVertexAttribManager(client_id);
......@@ -3443,7 +3434,7 @@ void RasterDecoderImpl::EmulateVertexArrayState() {
void RasterDecoderImpl::RestoreStateForAttrib(GLuint attrib_index,
bool restore_array_binding) {
PessimisticallyResetGrContext();
raster_decoder_context_state_->PessimisticallyResetGrContext();
const gles2::VertexAttrib* attrib =
state_.vertex_attrib_manager->GetVertexAttrib(attrib_index);
if (restore_array_binding) {
......
......@@ -144,5 +144,13 @@ void RasterDecoderContextState::PurgeMemory(
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 gpu
......@@ -50,6 +50,8 @@ struct GPU_GLES2_EXPORT RasterDecoderContextState
void PurgeMemory(
base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level);
void PessimisticallyResetGrContext() const;
scoped_refptr<gl::GLShareGroup> share_group;
scoped_refptr<gl::GLSurface> surface;
scoped_refptr<gl::GLContext> context;
......
......@@ -72,7 +72,7 @@ class WrappedSkImage : public SharedImageBacking {
const SkSurfaceProps& surface_props) {
if (context_state_->context_lost)
return nullptr;
DCHECK(context_state_->context->IsCurrent(context_state_->surface.get()));
DCHECK(context_state_->context->IsCurrent(nullptr));
GrBackendTexture gr_texture =
image_->getBackendTexture(/*flushPendingGrContextIO=*/true);
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