| 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 #include <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "mojo/application/application_runner_chromium.h" | 10 #include "mojo/application/application_runner_chromium.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 void OnPropertiesChanged( | 42 void OnPropertiesChanged( |
| 43 uint32_t old_scene_version, | 43 uint32_t old_scene_version, |
| 44 mojo::ui::ViewPropertiesPtr old_properties) override { | 44 mojo::ui::ViewPropertiesPtr old_properties) override { |
| 45 UpdateScene(); | 45 UpdateScene(); |
| 46 } | 46 } |
| 47 | 47 |
| 48 void UpdateScene() { | 48 void UpdateScene() { |
| 49 if (!properties()) | 49 if (!properties()) |
| 50 return; | 50 return; |
| 51 | 51 |
| 52 auto update = mojo::gfx::composition::SceneUpdate::New(); |
| 53 |
| 52 const mojo::Size& size = *properties()->view_layout->size; | 54 const mojo::Size& size = *properties()->view_layout->size; |
| 53 mojo::RectF bounds; | 55 if (size.width > 0 && size.height > 0) { |
| 54 bounds.width = size.width; | 56 mojo::RectF bounds; |
| 55 bounds.height = size.height; | 57 bounds.width = size.width; |
| 58 bounds.height = size.height; |
| 56 | 59 |
| 57 auto update = mojo::gfx::composition::SceneUpdate::New(); | 60 mojo::gfx::composition::ResourcePtr content_resource = |
| 58 mojo::gfx::composition::ResourcePtr content_resource = | 61 ganesh_renderer()->DrawCanvas( |
| 59 ganesh_renderer()->DrawCanvas( | 62 size, |
| 60 size, | 63 base::Bind(&PNGView::DrawContent, base::Unretained(this), size)); |
| 61 base::Bind(&PNGView::DrawContent, base::Unretained(this), size)); | 64 DCHECK(content_resource); |
| 62 DCHECK(content_resource); | 65 update->resources.insert(kContentImageResourceId, |
| 63 update->resources.insert(kContentImageResourceId, content_resource.Pass()); | 66 content_resource.Pass()); |
| 64 | 67 |
| 65 auto root_node = mojo::gfx::composition::Node::New(); | 68 auto root_node = mojo::gfx::composition::Node::New(); |
| 66 root_node->op = mojo::gfx::composition::NodeOp::New(); | 69 root_node->op = mojo::gfx::composition::NodeOp::New(); |
| 67 root_node->op->set_image(mojo::gfx::composition::ImageNodeOp::New()); | 70 root_node->op->set_image(mojo::gfx::composition::ImageNodeOp::New()); |
| 68 root_node->op->get_image()->content_rect = bounds.Clone(); | 71 root_node->op->get_image()->content_rect = bounds.Clone(); |
| 69 root_node->op->get_image()->image_resource_id = kContentImageResourceId; | 72 root_node->op->get_image()->image_resource_id = kContentImageResourceId; |
| 70 update->nodes.insert(kRootNodeId, root_node.Pass()); | 73 update->nodes.insert(kRootNodeId, root_node.Pass()); |
| 74 } else { |
| 75 auto root_node = mojo::gfx::composition::Node::New(); |
| 76 update->nodes.insert(kRootNodeId, root_node.Pass()); |
| 77 } |
| 71 | 78 |
| 72 scene()->Update(update.Pass()); | 79 scene()->Update(update.Pass()); |
| 73 | 80 |
| 74 auto metadata = mojo::gfx::composition::SceneMetadata::New(); | 81 auto metadata = mojo::gfx::composition::SceneMetadata::New(); |
| 75 metadata->version = scene_version(); | 82 metadata->version = scene_version(); |
| 76 scene()->Publish(metadata.Pass()); | 83 scene()->Publish(metadata.Pass()); |
| 77 } | 84 } |
| 78 | 85 |
| 79 void DrawContent(const mojo::Size& size, SkCanvas* canvas) { | 86 void DrawContent(const mojo::Size& size, SkCanvas* canvas) { |
| 80 canvas->clear(SK_ColorBLACK); | 87 canvas->clear(SK_ColorBLACK); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 private: | 154 private: |
| 148 DISALLOW_COPY_AND_ASSIGN(PNGContentViewerApp); | 155 DISALLOW_COPY_AND_ASSIGN(PNGContentViewerApp); |
| 149 }; | 156 }; |
| 150 | 157 |
| 151 } // namespace examples | 158 } // namespace examples |
| 152 | 159 |
| 153 MojoResult MojoMain(MojoHandle application_request) { | 160 MojoResult MojoMain(MojoHandle application_request) { |
| 154 mojo::ApplicationRunnerChromium runner(new examples::PNGContentViewerApp()); | 161 mojo::ApplicationRunnerChromium runner(new examples::PNGContentViewerApp()); |
| 155 return runner.Run(application_request); | 162 return runner.Run(application_request); |
| 156 } | 163 } |
| OLD | NEW |