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

Side by Side Diff: examples/ui/png_viewer/png_viewer.cc

Issue 1868093002: Mozart: Fix 0x0 crashes in example views. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 4 years, 8 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
« no previous file with comments | « examples/ui/pdf_viewer/pdf_viewer.cc ('k') | examples/ui/shapes/shapes_view.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 }
OLDNEW
« no previous file with comments | « examples/ui/pdf_viewer/pdf_viewer.cc ('k') | examples/ui/shapes/shapes_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698