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

Side by Side Diff: mojo/ui/gl_renderer.h

Issue 1556803002: Add helpers for creating UI components. (Closed) Base URL: git@github.com:domokit/mojo.git@moz-13
Patch Set: 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
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef MOJO_UI_GL_RENDERER_H_
6 #define MOJO_UI_GL_RENDERER_H_
7
8 #include <deque>
9 #include <memory>
10
11 #include "base/callback.h"
12 #include "base/macros.h"
13 #include "base/memory/weak_ptr.h"
14 #include "mojo/public/cpp/bindings/strong_binding.h"
15 #include "mojo/services/gfx/composition/interfaces/resources.mojom.h"
16
17 namespace mojo {
18
19 class GLContext;
20 class GLTexture;
21 class Size;
22
23 namespace ui {
24
25 // Provides support for rendering GL commands into a pool of textures
26 // and producing scene resources for them.
27 class GLRenderer {
28 public:
29 // Called with an active GL context to draw into the framebuffer.
30 using DrawGLCallback = base::Closure;
31
32 GLRenderer(base::WeakPtr<mojo::GLContext> gl_context,
33 uint32_t max_recycled_textures = 3u);
34 ~GLRenderer();
35
36 // Gets the GL context, or null if none.
37 const base::WeakPtr<mojo::GLContext>& gl_context() const {
38 return gl_context_;
39 }
40
41 // Obtains a texture of the specified size.
42 // Returns a nullptr if the GLContext was destroyed.
43 std::unique_ptr<mojo::GLTexture> GetTexture(const mojo::Size& requested_size);
44
45 // Takes ownership of the specified texture, issues GL commands to
46 // produce a mailbox texture, and returns its resource pointer.
47 // The caller should add the resource to its scene.
48 // Returns a nullptr if the GLContext was destroyed.
49 mojo::gfx::composition::ResourcePtr BindTextureResource(
50 std::unique_ptr<GLTexture> texture);
51
52 // Allocates a GL texture, binds it to a framebuffer, invokes the
53 // provided function, then returns the resulting resource.
54 // If |with_depth| is true, provides a depth buffer attachment.
55 mojo::gfx::composition::ResourcePtr DrawGL(const mojo::Size& size,
56 bool with_depth,
57 const DrawGLCallback& callback);
58
59 private:
60 using GLRecycledTextureInfo =
61 std::pair<std::unique_ptr<mojo::GLTexture>, uint32_t>;
62
63 // TODO(jeffbrown): Avoid creating new callbacks each time, perhaps by
64 // migrating to image pipes.
65 class GLTextureReleaser : mojo::gfx::composition::MailboxTextureCallback {
66 public:
67 GLTextureReleaser(const base::WeakPtr<GLRenderer>& provider,
68 GLRecycledTextureInfo info);
69 ~GLTextureReleaser() override;
70
71 mojo::gfx::composition::MailboxTextureCallbackPtr StrongBind();
72
73 private:
74 void OnMailboxTextureReleased() override;
75 void Release(bool recyclable);
76
77 base::WeakPtr<GLRenderer> provider_;
78 GLRecycledTextureInfo texture_info_;
79 mojo::StrongBinding<mojo::gfx::composition::MailboxTextureCallback>
80 binding_;
81 };
82
83 void ReleaseTexture(GLRecycledTextureInfo texture_info, bool recyclable);
84
85 const base::WeakPtr<mojo::GLContext> gl_context_;
86 const uint32_t max_recycled_textures_;
87
88 std::deque<GLRecycledTextureInfo> recycled_textures_;
89 uint32_t bound_textures_ = 0u;
90
91 base::WeakPtrFactory<mojo::ui::GLRenderer> weak_factory_;
92
93 DISALLOW_COPY_AND_ASSIGN(GLRenderer);
94 };
95
96 } // namespace ui
97 } // namespace mojo
98
99 #endif // MOJO_UI_GL_RENDERER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698