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) { |
| 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 |
OLD | NEW |