OLD | NEW |
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 EXAMPLES_SURFACES_APP_CHILD_GL_IMPL_H_ | 5 #ifndef EXAMPLES_SURFACES_APP_CHILD_GL_IMPL_H_ |
6 #define EXAMPLES_SURFACES_APP_CHILD_GL_IMPL_H_ | 6 #define EXAMPLES_SURFACES_APP_CHILD_GL_IMPL_H_ |
7 | 7 |
8 #include "base/containers/hash_tables.h" | 8 #include "base/containers/hash_tables.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/memory/weak_ptr.h" | |
12 #include "base/time/time.h" | 11 #include "base/time/time.h" |
13 #include "cc/surfaces/surface_id.h" | 12 #include "cc/surfaces/surface_id.h" |
14 #include "cc/surfaces/surface_id_allocator.h" | |
15 #include "examples/sample_app/spinning_cube.h" | 13 #include "examples/sample_app/spinning_cube.h" |
16 #include "examples/surfaces_app/child.mojom.h" | 14 #include "examples/surfaces_app/child.mojom.h" |
17 #include "mojo/public/c/gles2/gles2.h" | 15 #include "mojo/public/c/gles2/gles2.h" |
18 #include "mojo/public/cpp/bindings/string.h" | 16 #include "mojo/public/cpp/bindings/string.h" |
19 #include "mojo/services/surfaces/public/interfaces/surface_id.mojom.h" | 17 #include "mojo/services/surfaces/public/interfaces/surface_id.mojom.h" |
20 #include "mojo/services/surfaces/public/interfaces/surfaces.mojom.h" | 18 #include "mojo/services/surfaces/public/interfaces/surfaces.mojom.h" |
21 #include "third_party/skia/include/core/SkColor.h" | 19 #include "third_party/skia/include/core/SkColor.h" |
22 #include "ui/gfx/size.h" | 20 #include "ui/gfx/size.h" |
23 | 21 |
24 namespace cc { | 22 namespace cc { |
25 class CompositorFrame; | 23 class CompositorFrame; |
26 } | 24 } |
27 | 25 |
28 namespace mojo { | 26 namespace mojo { |
29 | 27 |
30 class ApplicationConnection; | 28 class ApplicationConnection; |
31 | 29 |
32 namespace examples { | 30 namespace examples { |
33 | 31 |
34 // Simple example of a child app using surfaces + GL. | 32 // Simple example of a child app using surfaces + GL. |
35 class ChildGLImpl : public InterfaceImpl<Child>, public SurfaceClient { | 33 class ChildGLImpl : public InterfaceImpl<Child>, public SurfaceClient { |
36 public: | 34 public: |
37 ChildGLImpl(ApplicationConnection* surfaces_service_connection, | 35 ChildGLImpl(ApplicationConnection* surfaces_service_connection, |
38 CommandBufferPtr command_buffer); | 36 CommandBufferPtr command_buffer); |
39 ~ChildGLImpl() override; | 37 ~ChildGLImpl() override; |
40 | 38 |
| 39 private: |
| 40 using ProduceCallback = mojo::Callback<void(SurfaceIdPtr id)>; |
| 41 |
| 42 // Child implementation. |
| 43 void ProduceFrame(ColorPtr color, |
| 44 SizePtr size, |
| 45 const ProduceCallback& callback) override; |
| 46 |
41 // SurfaceClient implementation | 47 // SurfaceClient implementation |
42 void SetIdNamespace(uint32_t id_namespace) override; | 48 void SetIdNamespace(uint32_t id_namespace) override; |
43 void ReturnResources(Array<ReturnedResourcePtr> resources) override; | 49 void ReturnResources(Array<ReturnedResourcePtr> resources) override; |
44 | 50 |
45 private: | |
46 // Child implementation. | |
47 void ProduceFrame( | |
48 ColorPtr color, | |
49 SizePtr size, | |
50 const mojo::Callback<void(SurfaceIdPtr id)>& callback) override; | |
51 | |
52 void AllocateSurface(); | |
53 void Draw(); | 51 void Draw(); |
| 52 void RunProduceCallback(); |
54 | 53 |
55 SkColor color_; | 54 SkColor color_; |
56 gfx::Size size_; | 55 gfx::Size size_; |
57 scoped_ptr<cc::SurfaceIdAllocator> allocator_; | |
58 SurfacePtr surface_; | 56 SurfacePtr surface_; |
59 MojoGLES2Context context_; | 57 MojoGLES2Context context_; |
60 cc::SurfaceId id_; | 58 uint32_t id_namespace_; |
| 59 uint32_t local_id_; |
61 ::examples::SpinningCube cube_; | 60 ::examples::SpinningCube cube_; |
62 base::TimeTicks start_time_; | 61 base::TimeTicks start_time_; |
63 uint32_t next_resource_id_; | 62 uint32_t next_resource_id_; |
64 base::hash_map<uint32_t, GLuint> id_to_tex_map_; | 63 base::hash_map<uint32_t, GLuint> id_to_tex_map_; |
65 base::WeakPtrFactory<ChildGLImpl> weak_factory_; | 64 ProduceCallback produce_callback_; |
66 | 65 |
67 DISALLOW_COPY_AND_ASSIGN(ChildGLImpl); | 66 DISALLOW_COPY_AND_ASSIGN(ChildGLImpl); |
68 }; | 67 }; |
69 | 68 |
70 } // namespace examples | 69 } // namespace examples |
71 } // namespace mojo | 70 } // namespace mojo |
72 | 71 |
73 #endif // EXAMPLES_SURFACES_APP_CHILD_GL_IMPL_H_ | 72 #endif // EXAMPLES_SURFACES_APP_CHILD_GL_IMPL_H_ |
OLD | NEW |