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

Unified Diff: mojo/ui/ganesh_renderer.cc

Issue 1556803002: Add helpers for creating UI components. (Closed) Base URL: git@github.com:domokit/mojo.git@moz-13
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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/ui/ganesh_renderer.h ('k') | mojo/ui/ganesh_view.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/ui/ganesh_renderer.cc
diff --git a/mojo/ui/ganesh_renderer.cc b/mojo/ui/ganesh_renderer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a1f47b3778053f4920d4ff75c0280ce90bec25a1
--- /dev/null
+++ b/mojo/ui/ganesh_renderer.cc
@@ -0,0 +1,57 @@
+// 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 "mojo/ui/ganesh_renderer.h"
+
+#include "base/bind.h"
+#include "base/logging.h"
+#include "mojo/gpu/gl_texture.h"
+#include "mojo/skia/ganesh_context.h"
+#include "mojo/skia/ganesh_texture_surface.h"
+#include "third_party/skia/include/core/SkCanvas.h"
+#include "third_party/skia/include/core/SkSurface.h"
+
+namespace mojo {
+namespace ui {
+
+GaneshRenderer::GaneshRenderer(mojo::skia::GaneshContext* ganesh_context)
+ : ganesh_context_(ganesh_context),
+ gl_renderer_(ganesh_context_->gl_context()) {
+ DCHECK(ganesh_context_);
+}
+
+GaneshRenderer::~GaneshRenderer() {}
+
+mojo::gfx::composition::ResourcePtr GaneshRenderer::DrawSurface(
+ const mojo::Size& size,
+ const DrawSurfaceCallback& callback) {
+ std::unique_ptr<mojo::GLTexture> texture = gl_renderer_.GetTexture(size);
+ DCHECK(texture);
+
+ {
+ mojo::skia::GaneshContext::Scope scope(ganesh_context_);
+ mojo::skia::GaneshTextureSurface texture_surface(scope, std::move(texture));
+
+ callback.Run(texture_surface.surface());
+
+ texture = texture_surface.TakeTexture();
+ }
+
+ return gl_renderer_.BindTextureResource(std::move(texture));
+}
+
+static void RunCanvasCallback(
+ const mojo::ui::GaneshRenderer::DrawCanvasCallback& callback,
+ SkSurface* surface) {
+ callback.Run(surface->getCanvas());
+}
+
+mojo::gfx::composition::ResourcePtr GaneshRenderer::DrawCanvas(
+ const mojo::Size& size,
+ const DrawCanvasCallback& callback) {
+ return DrawSurface(size, base::Bind(&RunCanvasCallback, callback));
+}
+
+} // namespace ui
+} // namespace mojo
« no previous file with comments | « mojo/ui/ganesh_renderer.h ('k') | mojo/ui/ganesh_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698