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

Side by Side Diff: examples/shadows/shadows_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 | « apps/moterm/moterm_view.cc ('k') | examples/ui/noodles/rasterizer.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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/shadows/shadows_view.h" 5 #include "examples/shadows/shadows_view.h"
6 6
7 #include <GLES2/gl2.h> 7 #include <GLES2/gl2.h>
8 #include <GLES2/gl2ext.h> 8 #include <GLES2/gl2ext.h>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 23 matching lines...) Expand all
34 mojo::ui::ViewPropertiesPtr old_properties) { 34 mojo::ui::ViewPropertiesPtr old_properties) {
35 choreographer_.ScheduleDraw(); 35 choreographer_.ScheduleDraw();
36 } 36 }
37 37
38 void ShadowsView::OnDraw(const mojo::gfx::composition::FrameInfo& frame_info, 38 void ShadowsView::OnDraw(const mojo::gfx::composition::FrameInfo& frame_info,
39 const base::TimeDelta& time_delta) { 39 const base::TimeDelta& time_delta) {
40 if (!properties()) 40 if (!properties())
41 return; 41 return;
42 42
43 // Update the contents of the scene. 43 // Update the contents of the scene.
44 auto update = mojo::gfx::composition::SceneUpdate::New();
45
44 const mojo::Size& size = *properties()->view_layout->size; 46 const mojo::Size& size = *properties()->view_layout->size;
45 mojo::RectF bounds; 47 if (size.width > 0 && size.height > 0) {
46 bounds.width = size.width; 48 mojo::RectF bounds;
47 bounds.height = size.height; 49 bounds.width = size.width;
50 bounds.height = size.height;
48 51
49 auto update = mojo::gfx::composition::SceneUpdate::New(); 52 mojo::gfx::composition::ResourcePtr content_resource =
50 mojo::gfx::composition::ResourcePtr content_resource = gl_renderer()->DrawGL( 53 gl_renderer()->DrawGL(
51 size, true, 54 size, true,
52 base::Bind(&ShadowsView::Render, base::Unretained(this), size)); 55 base::Bind(&ShadowsView::Render, base::Unretained(this), size));
53 DCHECK(content_resource); 56 DCHECK(content_resource);
54 update->resources.insert(kContentImageResourceId, content_resource.Pass()); 57 update->resources.insert(kContentImageResourceId, content_resource.Pass());
55 58
56 auto root_node = mojo::gfx::composition::Node::New(); 59 auto root_node = mojo::gfx::composition::Node::New();
57 root_node->content_transform = mojo::Transform::New(); 60 root_node->content_transform = mojo::Transform::New();
58 mojo::SetIdentityTransform(root_node->content_transform.get()); 61 mojo::SetIdentityTransform(root_node->content_transform.get());
59 root_node->hit_test_behavior = mojo::gfx::composition::HitTestBehavior::New(); 62 root_node->hit_test_behavior =
60 root_node->op = mojo::gfx::composition::NodeOp::New(); 63 mojo::gfx::composition::HitTestBehavior::New();
61 root_node->op->set_image(mojo::gfx::composition::ImageNodeOp::New()); 64 root_node->op = mojo::gfx::composition::NodeOp::New();
62 root_node->op->get_image()->content_rect = bounds.Clone(); 65 root_node->op->set_image(mojo::gfx::composition::ImageNodeOp::New());
63 root_node->op->get_image()->image_resource_id = kContentImageResourceId; 66 root_node->op->get_image()->content_rect = bounds.Clone();
64 update->nodes.insert(kRootNodeId, root_node.Pass()); 67 root_node->op->get_image()->image_resource_id = kContentImageResourceId;
68 update->nodes.insert(kRootNodeId, root_node.Pass());
69 } else {
70 auto root_node = mojo::gfx::composition::Node::New();
71 update->nodes.insert(kRootNodeId, root_node.Pass());
72 }
73
65 scene()->Update(update.Pass()); 74 scene()->Update(update.Pass());
66 75
67 // Publish the scene. 76 // Publish the scene.
68 auto metadata = mojo::gfx::composition::SceneMetadata::New(); 77 auto metadata = mojo::gfx::composition::SceneMetadata::New();
69 metadata->version = scene_version(); 78 metadata->version = scene_version();
70 metadata->presentation_time = frame_info.presentation_time; 79 metadata->presentation_time = frame_info.presentation_time;
71 scene()->Publish(metadata.Pass()); 80 scene()->Publish(metadata.Pass());
72 } 81 }
73 82
74 void ShadowsView::Render(const mojo::Size& size) { 83 void ShadowsView::Render(const mojo::Size& size) {
75 renderer_->Render(size); 84 renderer_->Render(size);
76 } 85 }
77 86
78 } // namespace examples 87 } // namespace examples
OLDNEW
« no previous file with comments | « apps/moterm/moterm_view.cc ('k') | examples/ui/noodles/rasterizer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698