| OLD | NEW |
| 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 Loading... |
| 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 |
| OLD | NEW |