| 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 #include "examples/ui/spinning_cube/spinning_cube_view.h" | 5 #include "examples/ui/spinning_cube/spinning_cube_view.h" |
| 6 | 6 |
| 7 #ifndef GL_GLEXT_PROTOTYPES | 7 #ifndef GL_GLEXT_PROTOTYPES |
| 8 #define GL_GLEXT_PROTOTYPES | 8 #define GL_GLEXT_PROTOTYPES |
| 9 #endif | 9 #endif |
| 10 | 10 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 void SpinningCubeView::OnDraw( | 137 void SpinningCubeView::OnDraw( |
| 138 const mojo::gfx::composition::FrameInfo& frame_info, | 138 const mojo::gfx::composition::FrameInfo& frame_info, |
| 139 const base::TimeDelta& time_delta) { | 139 const base::TimeDelta& time_delta) { |
| 140 if (!properties()) | 140 if (!properties()) |
| 141 return; | 141 return; |
| 142 | 142 |
| 143 // Update the state of the cube. | 143 // Update the state of the cube. |
| 144 cube_.UpdateForTimeDelta(time_delta.InSecondsF()); | 144 cube_.UpdateForTimeDelta(time_delta.InSecondsF()); |
| 145 | 145 |
| 146 // Update the contents of the scene. | 146 // Update the contents of the scene. |
| 147 auto update = mojo::gfx::composition::SceneUpdate::New(); |
| 148 |
| 147 const mojo::Size& size = *properties()->view_layout->size; | 149 const mojo::Size& size = *properties()->view_layout->size; |
| 148 mojo::RectF bounds; | 150 if (size.width > 0 && size.height > 0) { |
| 149 bounds.width = size.width; | 151 mojo::RectF bounds; |
| 150 bounds.height = size.height; | 152 bounds.width = size.width; |
| 153 bounds.height = size.height; |
| 151 | 154 |
| 152 auto update = mojo::gfx::composition::SceneUpdate::New(); | 155 mojo::gfx::composition::ResourcePtr cube_resource = gl_renderer()->DrawGL( |
| 153 mojo::gfx::composition::ResourcePtr cube_resource = gl_renderer()->DrawGL( | 156 size, true, base::Bind(&SpinningCubeView::DrawCubeWithGL, |
| 154 size, true, base::Bind(&SpinningCubeView::DrawCubeWithGL, | 157 base::Unretained(this), size)); |
| 155 base::Unretained(this), size)); | 158 DCHECK(cube_resource); |
| 156 DCHECK(cube_resource); | 159 update->resources.insert(kCubeImageResourceId, cube_resource.Pass()); |
| 157 update->resources.insert(kCubeImageResourceId, cube_resource.Pass()); | |
| 158 | 160 |
| 159 auto root_node = mojo::gfx::composition::Node::New(); | 161 auto root_node = mojo::gfx::composition::Node::New(); |
| 160 root_node->content_transform = mojo::Transform::New(); | 162 root_node->content_transform = mojo::Transform::New(); |
| 161 mojo::SetIdentityTransform(root_node->content_transform.get()); | 163 mojo::SetIdentityTransform(root_node->content_transform.get()); |
| 162 root_node->hit_test_behavior = mojo::gfx::composition::HitTestBehavior::New(); | 164 root_node->hit_test_behavior = |
| 163 root_node->op = mojo::gfx::composition::NodeOp::New(); | 165 mojo::gfx::composition::HitTestBehavior::New(); |
| 164 root_node->op->set_image(mojo::gfx::composition::ImageNodeOp::New()); | 166 root_node->op = mojo::gfx::composition::NodeOp::New(); |
| 165 root_node->op->get_image()->content_rect = bounds.Clone(); | 167 root_node->op->set_image(mojo::gfx::composition::ImageNodeOp::New()); |
| 166 root_node->op->get_image()->image_resource_id = kCubeImageResourceId; | 168 root_node->op->get_image()->content_rect = bounds.Clone(); |
| 167 update->nodes.insert(kRootNodeId, root_node.Pass()); | 169 root_node->op->get_image()->image_resource_id = kCubeImageResourceId; |
| 170 update->nodes.insert(kRootNodeId, root_node.Pass()); |
| 171 } else { |
| 172 auto root_node = mojo::gfx::composition::Node::New(); |
| 173 update->nodes.insert(kRootNodeId, root_node.Pass()); |
| 174 } |
| 168 | 175 |
| 169 scene()->Update(update.Pass()); | 176 scene()->Update(update.Pass()); |
| 170 | 177 |
| 171 // Publish the scene. | 178 // Publish the scene. |
| 172 auto metadata = mojo::gfx::composition::SceneMetadata::New(); | 179 auto metadata = mojo::gfx::composition::SceneMetadata::New(); |
| 173 metadata->version = scene_version(); | 180 metadata->version = scene_version(); |
| 174 metadata->presentation_time = frame_info.presentation_time; | 181 metadata->presentation_time = frame_info.presentation_time; |
| 175 scene()->Publish(metadata.Pass()); | 182 scene()->Publish(metadata.Pass()); |
| 176 | 183 |
| 177 // Loop! | 184 // Loop! |
| 178 choreographer_.ScheduleDraw(); | 185 choreographer_.ScheduleDraw(); |
| 179 } | 186 } |
| 180 | 187 |
| 181 void SpinningCubeView::DrawCubeWithGL(const mojo::Size& size) { | 188 void SpinningCubeView::DrawCubeWithGL(const mojo::Size& size) { |
| 182 cube_.set_size(size.width, size.height); | 189 cube_.set_size(size.width, size.height); |
| 183 cube_.Draw(); | 190 cube_.Draw(); |
| 184 } | 191 } |
| 185 | 192 |
| 186 } // namespace examples | 193 } // namespace examples |
| OLD | NEW |