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

Unified Diff: mojo/skia/ganesh_helpers.cc

Issue 1534033002: Improve Ganesh helpers. (Closed) Base URL: git@github.com:domokit/mojo.git@moz-8
Patch Set: rebase 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
Index: mojo/skia/ganesh_helpers.cc
diff --git a/mojo/skia/ganesh_helpers.cc b/mojo/skia/ganesh_helpers.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6ad7360836ddb370b2b934dfc6b96ee27908ba91
--- /dev/null
+++ b/mojo/skia/ganesh_helpers.cc
@@ -0,0 +1,51 @@
+// Copyright 2014 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/skia/ganesh_helpers.h"
+
+#include <GLES2/gl2.h>
+
+#include "base/logging.h"
+#include "third_party/skia/include/core/SkImage.h"
+#include "third_party/skia/include/gpu/gl/GrGLTypes.h"
+
+namespace mojo {
+namespace skia {
+
+static void ReleaseThunk(void* data) {
+ auto release_callback = static_cast<base::Closure*>(data);
+ release_callback->Run();
+ delete release_callback;
+}
+
+::skia::RefPtr<SkImage> CreateImageFromTexture(
+ const GaneshContext::Scope& scope,
+ uint32_t texture_id,
+ uint32_t width,
+ uint32_t height,
+ const base::Closure& release_callback) {
+ DCHECK(texture_id);
+ DCHECK(width);
+ DCHECK(height);
+
+ // TODO(jeffbrown): Give the caller more control over these parameters
+ // as required.
+ GrGLTextureInfo info;
+ info.fTarget = GL_TEXTURE_2D;
+ info.fID = texture_id;
+
+ GrBackendTextureDesc desc;
+ desc.fFlags = kRenderTarget_GrBackendTextureFlag;
+ desc.fWidth = width;
+ desc.fHeight = height;
+ desc.fConfig = kSkia8888_GrPixelConfig;
+ desc.fOrigin = kTopLeft_GrSurfaceOrigin;
+ desc.fTextureHandle = reinterpret_cast<GrBackendObject>(&info);
+ return ::skia::AdoptRef(SkImage::NewFromTexture(
+ scope.gr_context(), desc, kPremul_SkAlphaType, &ReleaseThunk,
+ new base::Closure(release_callback)));
+}
+
+} // namespace skia
+} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698