OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "examples/ui/noodles/rasterizer.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/logging.h" |
| 9 #include "examples/ui/noodles/frame.h" |
| 10 #include "third_party/skia/include/core/SkCanvas.h" |
| 11 #include "third_party/skia/include/core/SkColor.h" |
| 12 #include "third_party/skia/include/core/SkSurface.h" |
| 13 |
| 14 namespace examples { |
| 15 |
| 16 constexpr uint32_t kContentImageResourceId = 1; |
| 17 constexpr uint32_t kRootNodeId = mojo::gfx::composition::kSceneRootNodeId; |
| 18 |
| 19 Rasterizer::Rasterizer(mojo::ApplicationConnectorPtr connector, |
| 20 mojo::gfx::composition::ScenePtr scene) |
| 21 : gl_context_owner_(connector.get()), |
| 22 ganesh_context_(gl_context_owner_.context()), |
| 23 ganesh_renderer_(&ganesh_context_), |
| 24 scene_(scene.Pass()) {} |
| 25 |
| 26 Rasterizer::~Rasterizer() {} |
| 27 |
| 28 void Rasterizer::PublishFrame(std::unique_ptr<Frame> frame) { |
| 29 DCHECK(frame); |
| 30 |
| 31 mojo::Rect bounds; |
| 32 bounds.width = frame->size().width; |
| 33 bounds.height = frame->size().height; |
| 34 |
| 35 auto update = mojo::gfx::composition::SceneUpdate::New(); |
| 36 mojo::gfx::composition::ResourcePtr content_resource = |
| 37 ganesh_renderer_.DrawCanvas( |
| 38 frame->size(), |
| 39 base::Bind(&Frame::Paint, base::Unretained(frame.get()))); |
| 40 DCHECK(content_resource); |
| 41 update->resources.insert(kContentImageResourceId, content_resource.Pass()); |
| 42 |
| 43 auto root_node = mojo::gfx::composition::Node::New(); |
| 44 root_node->op = mojo::gfx::composition::NodeOp::New(); |
| 45 root_node->op->set_image(mojo::gfx::composition::ImageNodeOp::New()); |
| 46 root_node->op->get_image()->content_rect = bounds.Clone(); |
| 47 root_node->op->get_image()->image_resource_id = kContentImageResourceId; |
| 48 update->nodes.insert(kRootNodeId, root_node.Pass()); |
| 49 |
| 50 scene_->Update(update.Pass()); |
| 51 scene_->Publish(frame->TakeSceneMetadata()); |
| 52 } |
| 53 |
| 54 } // namespace examples |
OLD | NEW |