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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « mojo/ui/ganesh_renderer.h ('k') | mojo/ui/ganesh_view.h » ('j') | 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 "mojo/ui/ganesh_renderer.h"
6
7 #include "base/bind.h"
8 #include "base/logging.h"
9 #include "mojo/gpu/gl_texture.h"
10 #include "mojo/skia/ganesh_context.h"
11 #include "mojo/skia/ganesh_texture_surface.h"
12 #include "third_party/skia/include/core/SkCanvas.h"
13 #include "third_party/skia/include/core/SkSurface.h"
14
15 namespace mojo {
16 namespace ui {
17
18 GaneshRenderer::GaneshRenderer(mojo::skia::GaneshContext* ganesh_context)
19 : ganesh_context_(ganesh_context),
20 gl_renderer_(ganesh_context_->gl_context()) {
21 DCHECK(ganesh_context_);
22 }
23
24 GaneshRenderer::~GaneshRenderer() {}
25
26 mojo::gfx::composition::ResourcePtr GaneshRenderer::DrawSurface(
27 const mojo::Size& size,
28 const DrawSurfaceCallback& callback) {
29 std::unique_ptr<mojo::GLTexture> texture = gl_renderer_.GetTexture(size);
30 DCHECK(texture);
31
32 {
33 mojo::skia::GaneshContext::Scope scope(ganesh_context_);
34 mojo::skia::GaneshTextureSurface texture_surface(scope, std::move(texture));
35
36 callback.Run(texture_surface.surface());
37
38 texture = texture_surface.TakeTexture();
39 }
40
41 return gl_renderer_.BindTextureResource(std::move(texture));
42 }
43
44 static void RunCanvasCallback(
45 const mojo::ui::GaneshRenderer::DrawCanvasCallback& callback,
46 SkSurface* surface) {
47 callback.Run(surface->getCanvas());
48 }
49
50 mojo::gfx::composition::ResourcePtr GaneshRenderer::DrawCanvas(
51 const mojo::Size& size,
52 const DrawCanvasCallback& callback) {
53 return DrawSurface(size, base::Bind(&RunCanvasCallback, callback));
54 }
55
56 } // namespace ui
57 } // namespace mojo
OLDNEW
« 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