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..1481b8c4e93d94f46cb3c72c9773107e152ee0ca |
--- /dev/null |
+++ b/mojo/ui/ganesh_renderer.cc |
@@ -0,0 +1,53 @@ |
+// 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) { |
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
|
+ 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()); |
+ |
+ return gl_renderer_.BindTextureResource(texture_surface.TakeTexture()); |
+} |
+ |
+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 |