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

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: 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 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/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "mojo/gpu/gl_context.h" 10 #include "mojo/gpu/gl_context.h"
11 #include "skia/ext/refptr.h" 11 #include "skia/ext/refptr.h"
12 #include "third_party/skia/include/gpu/GrContext.h" 12 #include "third_party/skia/include/gpu/GrContext.h"
13 13
14 namespace gpu { 14 namespace mojo {
15 namespace gles2 { 15 namespace skia {
16 class GLES2Interface;
17 }
18 }
19 16
20 namespace mojo { 17 // Binds a Ganesh rendering context to a GL context.
21 18 //
19 // This object is not thread-safe.
22 class GaneshContext : public GLContext::Observer { 20 class GaneshContext : public GLContext::Observer {
23 public: 21 public:
22 // RAII style helper for executing code within a Ganesh environment.
23 //
24 // Note that Ganesh assumes that it owns the state of the GL Context
25 // for the duration while the scope is active. Take care not to perform
26 // any significant low-level GL operations while in the Ganesh scope
27 // which might disrupt what Ganesh is doing!
28 //
29 // Entering a Ganesh scope recursively has no effect. In particular,
30 // no state will be flushed.
24 class Scope { 31 class Scope {
25 public: 32 public:
26 explicit Scope(GaneshContext*); 33 // Upon entry to the scope, makes the GL context active and resets
34 // the Ganesh context state.
35 explicit Scope(GaneshContext* context);
36
37 // Upon exit from the scope, flushes the Ganesh context state and
38 // restores the prior GL context.
27 ~Scope(); 39 ~Scope();
28 40
29 private: 41 private:
30 gpu::gles2::GLES2Interface* previous_; 42 GaneshContext* context_;
31 }; 43 };
32 44
33 explicit GaneshContext(base::WeakPtr<GLContext> gl_context); 45 explicit GaneshContext(base::WeakPtr<GLContext> gl_context);
34 ~GaneshContext() override; 46 ~GaneshContext() override;
35 47
48 // Gets the underlying GL context.
49 const base::WeakPtr<GLContext>& gl_context() const { return gl_context_; }
50
51 // Gets the Ganesh renderer context.
36 // Note: You must be in a GaneshContext::Scope to use GrContext. 52 // Note: You must be in a GaneshContext::Scope to use GrContext.
37 GrContext* gr() const { 53 GrContext* gr_context() const {
38 DCHECK(InScope()); 54 DCHECK(InScope());
39 return context_.get(); 55 return gr_context_.get();
40 } 56 }
41 57
42 private: 58 private:
43 bool InScope() const; 59 bool InScope() const;
44 void OnContextLost() override; 60 void OnContextLost() override;
61 void ReleaseContext();
62
63 void EnterScope();
64 void ExitScope();
45 65
46 base::WeakPtr<GLContext> gl_context_; 66 base::WeakPtr<GLContext> gl_context_;
47 skia::RefPtr<GrContext> context_; 67 ::skia::RefPtr<GrContext> gr_context_;
68
69 uint32_t scope_nest_count_ = 0u;
70 MGLContext previous_mgl_context_ = MGL_NO_CONTEXT;
48 71
49 DISALLOW_COPY_AND_ASSIGN(GaneshContext); 72 DISALLOW_COPY_AND_ASSIGN(GaneshContext);
50 }; 73 };
51 74
75 } // namespace skia
52 } // namespace mojo 76 } // namespace mojo
53 77
54 #endif // MOJO_SKIA_GANESH_CONTEXT_H_ 78 #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_context.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698