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 "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) { | |
viettrungluu
2016/01/05 21:53:26
It may just be me (and my naivete), but I'm a bit
abarth
2016/01/10 23:23:39
Yeah, I'd skip this function. It's just making th
jeffbrown
2016/01/26 07:25:15
There are some subtle things going on here such as
viettrungluu
2016/01/26 18:38:40
To me the disadvantages are that it's not obvious
| |
29 std::unique_ptr<mojo::GLTexture> texture = gl_renderer_.GetTexture(size); | |
30 DCHECK(texture); | |
31 | |
32 mojo::skia::GaneshContext::Scope scope(ganesh_context_); | |
33 mojo::skia::GaneshTextureSurface texture_surface(scope, std::move(texture)); | |
34 | |
35 callback.Run(texture_surface.surface()); | |
36 | |
37 return gl_renderer_.BindTextureResource(texture_surface.TakeTexture()); | |
38 } | |
39 | |
40 static void RunCanvasCallback( | |
41 const mojo::ui::GaneshRenderer::DrawCanvasCallback& callback, | |
42 SkSurface* surface) { | |
43 callback.Run(surface->getCanvas()); | |
44 } | |
45 | |
46 mojo::gfx::composition::ResourcePtr GaneshRenderer::DrawCanvas( | |
47 const mojo::Size& size, | |
48 const DrawCanvasCallback& callback) { | |
49 return DrawSurface(size, base::Bind(&RunCanvasCallback, callback)); | |
50 } | |
51 | |
52 } // namespace ui | |
53 } // namespace mojo | |
OLD | NEW |