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

Side by Side Diff: examples/ui/noodles/rasterizer.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/shadows/shadows_view.cc ('k') | examples/ui/pdf_viewer/pdf_viewer.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/noodles/rasterizer.h" 5 #include "examples/ui/noodles/rasterizer.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 "examples/ui/noodles/frame.h" 9 #include "examples/ui/noodles/frame.h"
10 #include "third_party/skia/include/core/SkCanvas.h" 10 #include "third_party/skia/include/core/SkCanvas.h"
(...skipping 10 matching lines...) Expand all
21 : gl_context_owner_(connector.get()), 21 : gl_context_owner_(connector.get()),
22 ganesh_context_(gl_context_owner_.context()), 22 ganesh_context_(gl_context_owner_.context()),
23 ganesh_renderer_(&ganesh_context_), 23 ganesh_renderer_(&ganesh_context_),
24 scene_(scene.Pass()) {} 24 scene_(scene.Pass()) {}
25 25
26 Rasterizer::~Rasterizer() {} 26 Rasterizer::~Rasterizer() {}
27 27
28 void Rasterizer::PublishFrame(std::unique_ptr<Frame> frame) { 28 void Rasterizer::PublishFrame(std::unique_ptr<Frame> frame) {
29 DCHECK(frame); 29 DCHECK(frame);
30 30
31 mojo::RectF bounds; 31 auto update = mojo::gfx::composition::SceneUpdate::New();
32 bounds.width = frame->size().width;
33 bounds.height = frame->size().height;
34 32
35 auto update = mojo::gfx::composition::SceneUpdate::New(); 33 if (frame->size().width > 0 && frame->size().height > 0) {
36 mojo::gfx::composition::ResourcePtr content_resource = 34 mojo::RectF bounds;
37 ganesh_renderer_.DrawCanvas( 35 bounds.width = frame->size().width;
38 frame->size(), 36 bounds.height = frame->size().height;
39 base::Bind(&Frame::Paint, base::Unretained(frame.get())));
40 DCHECK(content_resource);
41 update->resources.insert(kContentImageResourceId, content_resource.Pass());
42 37
43 auto root_node = mojo::gfx::composition::Node::New(); 38 mojo::gfx::composition::ResourcePtr content_resource =
44 root_node->op = mojo::gfx::composition::NodeOp::New(); 39 ganesh_renderer_.DrawCanvas(
45 root_node->op->set_image(mojo::gfx::composition::ImageNodeOp::New()); 40 frame->size(),
46 root_node->op->get_image()->content_rect = bounds.Clone(); 41 base::Bind(&Frame::Paint, base::Unretained(frame.get())));
47 root_node->op->get_image()->image_resource_id = kContentImageResourceId; 42 DCHECK(content_resource);
48 update->nodes.insert(kRootNodeId, root_node.Pass()); 43 update->resources.insert(kContentImageResourceId, content_resource.Pass());
44
45 auto root_node = mojo::gfx::composition::Node::New();
46 root_node->op = mojo::gfx::composition::NodeOp::New();
47 root_node->op->set_image(mojo::gfx::composition::ImageNodeOp::New());
48 root_node->op->get_image()->content_rect = bounds.Clone();
49 root_node->op->get_image()->image_resource_id = kContentImageResourceId;
50 update->nodes.insert(kRootNodeId, root_node.Pass());
51 } else {
52 auto root_node = mojo::gfx::composition::Node::New();
53 update->nodes.insert(kRootNodeId, root_node.Pass());
54 }
49 55
50 scene_->Update(update.Pass()); 56 scene_->Update(update.Pass());
51 scene_->Publish(frame->TakeSceneMetadata()); 57 scene_->Publish(frame->TakeSceneMetadata());
52 } 58 }
53 59
54 } // namespace examples 60 } // namespace examples
OLDNEW
« no previous file with comments | « examples/shadows/shadows_view.cc ('k') | examples/ui/pdf_viewer/pdf_viewer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698