| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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_UI_SPINNING_CUBE_SPINNING_CUBE_VIEW_H_ | 5 #ifndef EXAMPLES_UI_SPINNING_CUBE_SPINNING_CUBE_VIEW_H_ |
| 6 #define EXAMPLES_UI_SPINNING_CUBE_SPINNING_CUBE_VIEW_H_ | 6 #define EXAMPLES_UI_SPINNING_CUBE_SPINNING_CUBE_VIEW_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/bind.h" | |
| 11 #include "base/memory/weak_ptr.h" | |
| 12 #include "examples/spinning_cube/spinning_cube.h" | 10 #include "examples/spinning_cube/spinning_cube.h" |
| 13 #include "mojo/gpu/gl_context.h" | 11 #include "mojo/ui/choreographer.h" |
| 14 #include "mojo/gpu/gl_context_owner.h" | 12 #include "mojo/ui/gl_view.h" |
| 15 #include "mojo/gpu/gl_texture.h" | 13 #include "mojo/ui/input_handler.h" |
| 16 #include "mojo/gpu/texture_cache.h" | |
| 17 #include "mojo/gpu/texture_uploader.h" | |
| 18 #include "mojo/public/cpp/application/application_impl.h" | |
| 19 #include "mojo/public/cpp/bindings/strong_binding.h" | |
| 20 #include "mojo/public/cpp/environment/environment.h" | |
| 21 #include "mojo/public/cpp/system/core.h" | |
| 22 #include "mojo/public/cpp/system/macros.h" | |
| 23 #include "mojo/services/surfaces/interfaces/quads.mojom.h" | |
| 24 #include "mojo/services/surfaces/interfaces/surfaces.mojom.h" | |
| 25 #include "mojo/services/ui/views/interfaces/view_manager.mojom.h" | |
| 26 #include "mojo/services/ui/views/interfaces/view_provider.mojom.h" | |
| 27 #include "mojo/services/ui/views/interfaces/views.mojom.h" | |
| 28 | 14 |
| 29 namespace examples { | 15 namespace examples { |
| 30 | 16 |
| 31 class SpinningCubeView : public mojo::ui::View { | 17 class SpinningCubeView : public mojo::ui::GLView, |
| 18 public mojo::ui::ChoreographerDelegate, |
| 19 public mojo::ui::InputListener { |
| 32 public: | 20 public: |
| 33 SpinningCubeView(mojo::ApplicationImpl* app, | 21 SpinningCubeView( |
| 34 const mojo::ui::ViewProvider::CreateViewCallback& callback); | 22 mojo::ApplicationImpl* app_impl, |
| 23 const mojo::ui::ViewProvider::CreateViewCallback& create_view_callback); |
| 35 | 24 |
| 36 ~SpinningCubeView() override; | 25 ~SpinningCubeView() override; |
| 37 | 26 |
| 38 private: | 27 private: |
| 39 // |View|: | 28 // |View|: |
| 40 void OnLayout(mojo::ui::ViewLayoutParamsPtr layout_params, | 29 void OnLayout(mojo::ui::ViewLayoutParamsPtr layout_params, |
| 41 mojo::Array<uint32_t> children_needing_layout, | 30 mojo::Array<uint32_t> children_needing_layout, |
| 42 const OnLayoutCallback& callback) override; | 31 const OnLayoutCallback& callback) override; |
| 43 void OnChildUnavailable(uint32_t child_key, | |
| 44 const OnChildUnavailableCallback& callback) override; | |
| 45 | 32 |
| 46 void OnSurfaceIdNamespaceAvailable(uint32_t id_namespace); | 33 // |ChoreographerDelegate|: |
| 34 void OnDraw(const mojo::gfx::composition::FrameInfo& frame_info, |
| 35 const base::TimeDelta& time_delta) override; |
| 47 | 36 |
| 48 void InitView(); | 37 // |InputListener|: |
| 38 void OnEvent(mojo::EventPtr event, const OnEventCallback& callback) override; |
| 49 | 39 |
| 50 void InitCube(); | 40 void DrawCubeWithGL(); |
| 51 void DrawCube(); | |
| 52 void OnSurfaceSubmitted(); | |
| 53 void ScheduleDraw(); | |
| 54 | 41 |
| 55 mojo::ui::ViewProvider::CreateViewCallback callback_; | 42 mojo::ui::Choreographer choreographer_; |
| 56 mojo::StrongBinding<mojo::ui::View> binding_; | 43 mojo::ui::InputHandler input_handler_; |
| 57 | |
| 58 mojo::GLContextOwner context_owner_; | |
| 59 mojo::ResourceReturnerPtr resource_returner_; // must be before texture cache | |
| 60 mojo::TextureCache texture_cache_; | |
| 61 | |
| 62 mojo::SurfacePtr surfaces_; | |
| 63 mojo::SurfaceIdPtr surface_id_; | |
| 64 uint32_t surface_id_namespace_; | |
| 65 | |
| 66 mojo::ui::ViewManagerPtr view_manager_; | |
| 67 mojo::ui::ViewHostPtr view_host_; | |
| 68 mojo::ServiceProviderPtr view_service_provider_; | |
| 69 | 44 |
| 70 mojo::Size size_; | 45 mojo::Size size_; |
| 71 | 46 |
| 72 SpinningCube cube_; | 47 SpinningCube cube_; |
| 73 MojoTimeTicks last_draw_; | 48 |
| 74 bool draw_scheduled_; | 49 mojo::PointF capture_point_; |
| 50 mojo::PointF last_drag_point_; |
| 51 MojoTimeTicks drag_start_time_ = 0u; |
| 75 | 52 |
| 76 base::WeakPtrFactory<SpinningCubeView> weak_ptr_factory_; | 53 base::WeakPtrFactory<SpinningCubeView> weak_ptr_factory_; |
| 77 | 54 |
| 78 DISALLOW_COPY_AND_ASSIGN(SpinningCubeView); | 55 DISALLOW_COPY_AND_ASSIGN(SpinningCubeView); |
| 79 }; | 56 }; |
| 80 | 57 |
| 81 } // namespace examples | 58 } // namespace examples |
| 82 | 59 |
| 83 #endif // EXAMPLES_UI_SPINNING_CUBE_SPINNING_CUBE_VIEW_H_ | 60 #endif // EXAMPLES_UI_SPINNING_CUBE_SPINNING_CUBE_VIEW_H_ |
| OLD | NEW |