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

Side by Side Diff: examples/ui/shapes/shapes_view.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/png_viewer/png_viewer.cc ('k') | examples/ui/spinning_cube/spinning_cube_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 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/shapes/shapes_view.h" 5 #include "examples/ui/shapes/shapes_view.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "third_party/skia/include/core/SkCanvas.h" 9 #include "third_party/skia/include/core/SkCanvas.h"
10 #include "third_party/skia/include/core/SkColor.h" 10 #include "third_party/skia/include/core/SkColor.h"
(...skipping 16 matching lines...) Expand all
27 void ShapesView::OnPropertiesChanged( 27 void ShapesView::OnPropertiesChanged(
28 uint32_t old_scene_version, 28 uint32_t old_scene_version,
29 mojo::ui::ViewPropertiesPtr old_properties) { 29 mojo::ui::ViewPropertiesPtr old_properties) {
30 UpdateScene(); 30 UpdateScene();
31 } 31 }
32 32
33 void ShapesView::UpdateScene() { 33 void ShapesView::UpdateScene() {
34 if (!properties()) 34 if (!properties())
35 return; 35 return;
36 36
37 const mojo::Size& size = *properties()->view_layout->size;
38 mojo::RectF bounds;
39 bounds.width = size.width;
40 bounds.height = size.height;
41
42 auto update = mojo::gfx::composition::SceneUpdate::New(); 37 auto update = mojo::gfx::composition::SceneUpdate::New();
43 38
44 // Draw the content of the view to a texture and include it as an 39 const mojo::Size& size = *properties()->view_layout->size;
45 // image resource in the scene. 40 if (size.width > 0 && size.height > 0) {
46 mojo::gfx::composition::ResourcePtr content_resource = 41 mojo::RectF bounds;
47 ganesh_renderer()->DrawCanvas( 42 bounds.width = size.width;
48 size, 43 bounds.height = size.height;
49 base::Bind(&ShapesView::DrawContent, base::Unretained(this), size));
50 DCHECK(content_resource);
51 update->resources.insert(kContentImageResourceId, content_resource.Pass());
52 44
53 // Add a root node to the scene graph to draw the image resource to 45 // Draw the content of the view to a texture and include it as an
54 // the screen such that it fills the entire view. 46 // image resource in the scene.
55 auto root_node = mojo::gfx::composition::Node::New(); 47 mojo::gfx::composition::ResourcePtr content_resource =
56 root_node->op = mojo::gfx::composition::NodeOp::New(); 48 ganesh_renderer()->DrawCanvas(
57 root_node->op->set_image(mojo::gfx::composition::ImageNodeOp::New()); 49 size,
58 root_node->op->get_image()->content_rect = bounds.Clone(); 50 base::Bind(&ShapesView::DrawContent, base::Unretained(this), size));
59 root_node->op->get_image()->image_resource_id = kContentImageResourceId; 51 DCHECK(content_resource);
60 update->nodes.insert(kRootNodeId, root_node.Pass()); 52 update->resources.insert(kContentImageResourceId, content_resource.Pass());
53
54 // Add a root node to the scene graph to draw the image resource to
55 // the screen such that it fills the entire view.
56 auto root_node = mojo::gfx::composition::Node::New();
57 root_node->op = mojo::gfx::composition::NodeOp::New();
58 root_node->op->set_image(mojo::gfx::composition::ImageNodeOp::New());
59 root_node->op->get_image()->content_rect = bounds.Clone();
60 root_node->op->get_image()->image_resource_id = kContentImageResourceId;
61 update->nodes.insert(kRootNodeId, root_node.Pass());
62 } else {
63 auto root_node = mojo::gfx::composition::Node::New();
64 update->nodes.insert(kRootNodeId, root_node.Pass());
65 }
61 66
62 // Submit the scene update. 67 // Submit the scene update.
63 scene()->Update(update.Pass()); 68 scene()->Update(update.Pass());
64 69
65 // Publish the scene update, taking care to supply the expected scene version. 70 // Publish the scene update, taking care to supply the expected scene version.
66 auto metadata = mojo::gfx::composition::SceneMetadata::New(); 71 auto metadata = mojo::gfx::composition::SceneMetadata::New();
67 metadata->version = scene_version(); 72 metadata->version = scene_version();
68 scene()->Publish(metadata.Pass()); 73 scene()->Publish(metadata.Pass());
69 } 74 }
70 75
71 void ShapesView::DrawContent(const mojo::Size& size, SkCanvas* canvas) { 76 void ShapesView::DrawContent(const mojo::Size& size, SkCanvas* canvas) {
72 canvas->clear(SK_ColorCYAN); 77 canvas->clear(SK_ColorCYAN);
73 78
74 SkPaint paint; 79 SkPaint paint;
75 paint.setColor(SK_ColorGREEN); 80 paint.setColor(SK_ColorGREEN);
76 SkRect rect = SkRect::MakeWH(size.width, size.height); 81 SkRect rect = SkRect::MakeWH(size.width, size.height);
77 rect.inset(10, 10); 82 rect.inset(10, 10);
78 canvas->drawRect(rect, paint); 83 canvas->drawRect(rect, paint);
79 84
80 paint.setColor(SK_ColorRED); 85 paint.setColor(SK_ColorRED);
81 paint.setFlags(SkPaint::kAntiAlias_Flag); 86 paint.setFlags(SkPaint::kAntiAlias_Flag);
82 canvas->drawCircle(50, 100, 100, paint); 87 canvas->drawCircle(50, 100, 100, paint);
83 } 88 }
84 89
85 } // namespace examples 90 } // namespace examples
OLDNEW
« no previous file with comments | « examples/ui/png_viewer/png_viewer.cc ('k') | examples/ui/spinning_cube/spinning_cube_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698