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

Unified 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: Created 4 years, 12 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 side-by-side diff with in-line comments
Download patch
« examples/ui/noodles/noodles_view.cc ('K') | « examples/ui/noodles/rasterizer.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: examples/ui/noodles/rasterizer.cc
diff --git a/examples/ui/noodles/rasterizer.cc b/examples/ui/noodles/rasterizer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..5fa495dc24317c7bb2c58f585264a958609dc27e
--- /dev/null
+++ b/examples/ui/noodles/rasterizer.cc
@@ -0,0 +1,54 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "examples/ui/noodles/rasterizer.h"
+
+#include "base/bind.h"
+#include "base/logging.h"
+#include "examples/ui/noodles/frame.h"
+#include "third_party/skia/include/core/SkCanvas.h"
+#include "third_party/skia/include/core/SkColor.h"
+#include "third_party/skia/include/core/SkSurface.h"
+
+namespace examples {
+
+constexpr uint32_t kContentImageResourceId = 1;
+constexpr uint32_t kRootNodeId = mojo::gfx::composition::kSceneRootNodeId;
+
+Rasterizer::Rasterizer(mojo::ApplicationConnectorPtr connector,
+ mojo::gfx::composition::ScenePtr scene)
+ : gl_context_owner_(connector.get()),
+ ganesh_context_(gl_context_owner_.context()),
+ ganesh_renderer_(&ganesh_context_),
+ scene_(scene.Pass()) {}
+
+Rasterizer::~Rasterizer() {}
+
+void Rasterizer::PublishFrame(std::unique_ptr<Frame> frame) {
+ DCHECK(frame);
+
+ mojo::Rect bounds;
+ bounds.width = frame->size().width;
+ bounds.height = frame->size().height;
+
+ auto update = mojo::gfx::composition::SceneUpdate::New();
+ mojo::gfx::composition::ResourcePtr content_resource =
+ ganesh_renderer_.DrawCanvas(
+ frame->size(),
+ base::Bind(&Frame::Paint, base::Unretained(frame.get())));
+ DCHECK(content_resource);
+ update->resources.insert(kContentImageResourceId, content_resource.Pass());
+
+ auto root_node = mojo::gfx::composition::Node::New();
+ root_node->op = mojo::gfx::composition::NodeOp::New();
+ root_node->op->set_image(mojo::gfx::composition::ImageNodeOp::New());
+ root_node->op->get_image()->content_rect = bounds.Clone();
+ root_node->op->get_image()->image_resource_id = kContentImageResourceId;
+ update->nodes.insert(kRootNodeId, root_node.Pass());
+
+ scene_->Update(update.Pass());
+ scene_->Publish(frame->TakeSceneMetadata());
+}
+
+} // namespace examples
« examples/ui/noodles/noodles_view.cc ('K') | « examples/ui/noodles/rasterizer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698