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

Side by Side Diff: examples/ui/noodles/rasterizer.cc

Issue 1558813002: Add a multi-threaded rendering example. (Closed) Base URL: git@github.com:domokit/mojo.git@moz-15
Patch Set: address feedback Created 4 years, 11 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/noodles/rasterizer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
OLDNEW
« no previous file with comments | « examples/ui/noodles/rasterizer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698