Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(308)

Unified Diff: mojo/skia/ganesh_context.h

Issue 1534033002: Improve Ganesh helpers. (Closed) Base URL: git@github.com:domokit/mojo.git@moz-8
Patch Set: rebase Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/skia/BUILD.gn ('k') | mojo/skia/ganesh_context.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/skia/ganesh_context.h
diff --git a/mojo/skia/ganesh_context.h b/mojo/skia/ganesh_context.h
index 149981d3031d5be07ecb476cc74ac9090bc7a4d1..e3f72db4237e91e9953a01f7e7ccc50562504205 100644
--- a/mojo/skia/ganesh_context.h
+++ b/mojo/skia/ganesh_context.h
@@ -6,49 +6,85 @@
#define MOJO_SKIA_GANESH_CONTEXT_H_
#include "base/basictypes.h"
+#include "base/logging.h"
#include "base/memory/weak_ptr.h"
#include "mojo/gpu/gl_context.h"
#include "skia/ext/refptr.h"
#include "third_party/skia/include/gpu/GrContext.h"
-namespace gpu {
-namespace gles2 {
-class GLES2Interface;
-}
-}
-
namespace mojo {
+namespace skia {
+// Binds a Ganesh rendering context to a GL context.
+//
+// This object is not thread-safe.
class GaneshContext : public GLContext::Observer {
public:
+ // RAII style helper for executing code within a Ganesh environment.
+ //
+ // Note that Ganesh assumes that it owns the state of the GL Context
+ // for the duration while the scope is active. Take care not to perform
+ // any significant low-level GL operations while in the Ganesh scope
+ // which might disrupt what Ganesh is doing!
+ //
+ // Recursively entering the scope of a particular GaneshContext is not
+ // allowed.
class Scope {
public:
- explicit Scope(GaneshContext*);
- ~Scope();
+ // Upon entry to the scope, makes the GL context active and resets
+ // the Ganesh context state.
+ explicit Scope(GaneshContext* context) : context_(context) {
+ DCHECK(context_);
+ context_->EnterScope();
+ }
+
+ // Upon exit from the scope, flushes the Ganesh context state and
+ // restores the prior GL context.
+ ~Scope() { context_->ExitScope(); }
+
+ // Gets the underlying GL context, may be null if the context was lost.
+ //
+ // Be careful when manipulating the GL context from within a Ganesh
+ // scope since the Ganesh renderer caches GL state. Queries are safe
+ // but operations which modify the state of the GL context, such as binding
+ // textures, should be followed by a call to |GrContext::resetContext|
+ // before performing other Ganesh related actions within the scope.
+ const base::WeakPtr<GLContext>& gl_context() const {
+ return context_->gl_context_;
+ }
+
+ // Gets the Ganesh rendering context, may be null if the context was lost.
+ GrContext* gr_context() const { return context_->gr_context_.get(); }
private:
- gpu::gles2::GLES2Interface* previous_;
+ GaneshContext* context_;
+
+ DISALLOW_COPY_AND_ASSIGN(Scope);
};
explicit GaneshContext(base::WeakPtr<GLContext> gl_context);
~GaneshContext() override;
- // Note: You must be in a GaneshContext::Scope to use GrContext.
- GrContext* gr() const {
- DCHECK(InScope());
- return context_.get();
- }
+ // Gets the underlying GL context.
+ const base::WeakPtr<GLContext>& gl_context() const { return gl_context_; }
private:
- bool InScope() const;
void OnContextLost() override;
+ void ReleaseContext();
+
+ void EnterScope();
+ void ExitScope();
base::WeakPtr<GLContext> gl_context_;
- skia::RefPtr<GrContext> context_;
+ ::skia::RefPtr<GrContext> gr_context_;
+
+ bool scope_entered_ = false;
+ MGLContext previous_mgl_context_ = MGL_NO_CONTEXT;
DISALLOW_COPY_AND_ASSIGN(GaneshContext);
};
+} // namespace skia
} // namespace mojo
#endif // MOJO_SKIA_GANESH_CONTEXT_H_
« no previous file with comments | « mojo/skia/BUILD.gn ('k') | mojo/skia/ganesh_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698