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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MOJO_SKIA_GANESH_CONTEXT_H_ 5 #ifndef MOJO_SKIA_GANESH_CONTEXT_H_
6 #define MOJO_SKIA_GANESH_CONTEXT_H_ 6 #define MOJO_SKIA_GANESH_CONTEXT_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/logging.h"
9 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
10 #include "mojo/gpu/gl_context.h" 11 #include "mojo/gpu/gl_context.h"
11 #include "skia/ext/refptr.h" 12 #include "skia/ext/refptr.h"
12 #include "third_party/skia/include/gpu/GrContext.h" 13 #include "third_party/skia/include/gpu/GrContext.h"
13 14
14 namespace gpu { 15 namespace mojo {
15 namespace gles2 { 16 namespace skia {
16 class GLES2Interface;
17 }
18 }
19 17
20 namespace mojo { 18 // Binds a Ganesh rendering context to a GL context.
21 19 //
20 // This object is not thread-safe.
22 class GaneshContext : public GLContext::Observer { 21 class GaneshContext : public GLContext::Observer {
23 public: 22 public:
23 // RAII style helper for executing code within a Ganesh environment.
24 //
25 // Note that Ganesh assumes that it owns the state of the GL Context
26 // for the duration while the scope is active. Take care not to perform
27 // any significant low-level GL operations while in the Ganesh scope
28 // which might disrupt what Ganesh is doing!
29 //
30 // Recursively entering the scope of a particular GaneshContext is not
31 // allowed.
24 class Scope { 32 class Scope {
25 public: 33 public:
26 explicit Scope(GaneshContext*); 34 // Upon entry to the scope, makes the GL context active and resets
27 ~Scope(); 35 // the Ganesh context state.
36 explicit Scope(GaneshContext* context) : context_(context) {
37 DCHECK(context_);
38 context_->EnterScope();
39 }
40
41 // Upon exit from the scope, flushes the Ganesh context state and
42 // restores the prior GL context.
43 ~Scope() { context_->ExitScope(); }
44
45 // Gets the underlying GL context, may be null if the context was lost.
46 //
47 // Be careful when manipulating the GL context from within a Ganesh
48 // scope since the Ganesh renderer caches GL state. Queries are safe
49 // but operations which modify the state of the GL context, such as binding
50 // textures, should be followed by a call to |GrContext::resetContext|
51 // before performing other Ganesh related actions within the scope.
52 const base::WeakPtr<GLContext>& gl_context() const {
53 return context_->gl_context_;
54 }
55
56 // Gets the Ganesh rendering context, may be null if the context was lost.
57 GrContext* gr_context() const { return context_->gr_context_.get(); }
28 58
29 private: 59 private:
30 gpu::gles2::GLES2Interface* previous_; 60 GaneshContext* context_;
61
62 DISALLOW_COPY_AND_ASSIGN(Scope);
31 }; 63 };
32 64
33 explicit GaneshContext(base::WeakPtr<GLContext> gl_context); 65 explicit GaneshContext(base::WeakPtr<GLContext> gl_context);
34 ~GaneshContext() override; 66 ~GaneshContext() override;
35 67
36 // Note: You must be in a GaneshContext::Scope to use GrContext. 68 // Gets the underlying GL context.
37 GrContext* gr() const { 69 const base::WeakPtr<GLContext>& gl_context() const { return gl_context_; }
38 DCHECK(InScope());
39 return context_.get();
40 }
41 70
42 private: 71 private:
43 bool InScope() const;
44 void OnContextLost() override; 72 void OnContextLost() override;
73 void ReleaseContext();
74
75 void EnterScope();
76 void ExitScope();
45 77
46 base::WeakPtr<GLContext> gl_context_; 78 base::WeakPtr<GLContext> gl_context_;
47 skia::RefPtr<GrContext> context_; 79 ::skia::RefPtr<GrContext> gr_context_;
80
81 bool scope_entered_ = false;
82 MGLContext previous_mgl_context_ = MGL_NO_CONTEXT;
48 83
49 DISALLOW_COPY_AND_ASSIGN(GaneshContext); 84 DISALLOW_COPY_AND_ASSIGN(GaneshContext);
50 }; 85 };
51 86
87 } // namespace skia
52 } // namespace mojo 88 } // namespace mojo
53 89
54 #endif // MOJO_SKIA_GANESH_CONTEXT_H_ 90 #endif // MOJO_SKIA_GANESH_CONTEXT_H_
OLDNEW
« no previous file with comments | « mojo/skia/BUILD.gn ('k') | mojo/skia/ganesh_context.cc » ('j') | mojo/skia/ganesh_helpers.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698