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

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: fix includes Created 5 years 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
Index: mojo/skia/ganesh_context.h
diff --git a/mojo/skia/ganesh_context.h b/mojo/skia/ganesh_context.h
index 149981d3031d5be07ecb476cc74ac9090bc7a4d1..6432d589f172ada9f2402132365ce729ef9ee68b 100644
--- a/mojo/skia/ganesh_context.h
+++ b/mojo/skia/ganesh_context.h
@@ -11,44 +11,68 @@
#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!
+ //
+ // Entering a Ganesh scope recursively has no effect. In particular,
+ // no state will be flushed.
class Scope {
public:
- explicit Scope(GaneshContext*);
+ // Upon entry to the scope, makes the GL context active and resets
+ // the Ganesh context state.
+ explicit Scope(GaneshContext* context);
+
+ // Upon exit from the scope, flushes the Ganesh context state and
+ // restores the prior GL context.
~Scope();
private:
- gpu::gles2::GLES2Interface* previous_;
+ GaneshContext* context_;
};
explicit GaneshContext(base::WeakPtr<GLContext> gl_context);
~GaneshContext() override;
+ // Gets the underlying GL context.
+ const base::WeakPtr<GLContext>& gl_context() const { return gl_context_; }
+
+ // Gets the Ganesh renderer context.
// Note: You must be in a GaneshContext::Scope to use GrContext.
- GrContext* gr() const {
+ GrContext* gr_context() const {
DCHECK(InScope());
- return context_.get();
+ return gr_context_.get();
}
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_;
+
+ uint32_t scope_nest_count_ = 0u;
+ 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') | mojo/skia/ganesh_context.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698