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

Unified Diff: mojo/skia/ganesh_image_factory.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
« no previous file with comments | « mojo/skia/ganesh_image_factory.h ('k') | mojo/skia/ganesh_texture_surface.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/skia/ganesh_image_factory.cc
diff --git a/mojo/skia/ganesh_image_factory.cc b/mojo/skia/ganesh_image_factory.cc
new file mode 100644
index 0000000000000000000000000000000000000000..5300d99f40ece51cdc93710fa03108093f08a36a
--- /dev/null
+++ b/mojo/skia/ganesh_image_factory.cc
@@ -0,0 +1,95 @@
+// Copyright 2016 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.
+
+#ifndef GL_GLEXT_PROTOTYPES
+#define GL_GLEXT_PROTOTYPES
+#endif
+
+#include "mojo/skia/ganesh_image_factory.h"
+
+#include "base/logging.h"
+#include "third_party/skia/include/core/SkImage.h"
+#include "third_party/skia/include/gpu/GrContext.h"
+#include "third_party/skia/include/gpu/GrTextureProvider.h"
+#include "third_party/skia/include/gpu/gl/GrGLTypes.h"
+
+namespace mojo {
+namespace skia {
+namespace {
+void ReleaseThunk(void* data) {
+ auto release_callback = static_cast<base::Closure*>(data);
+ release_callback->Run();
+ delete release_callback;
+}
+} // namespace
+
+::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.
+ 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)));
+}
+
+MailboxTextureImageGenerator::MailboxTextureImageGenerator(
+ const GLbyte mailbox_name[GL_MAILBOX_SIZE_CHROMIUM],
+ GLuint sync_point,
+ uint32_t width,
+ uint32_t height)
+ : SkImageGenerator(SkImageInfo::MakeN32Premul(width, height)),
+ sync_point_(sync_point) {
+ DCHECK(mailbox_name);
+ memcpy(mailbox_name_, mailbox_name, GL_MAILBOX_SIZE_CHROMIUM);
+}
+
+MailboxTextureImageGenerator::~MailboxTextureImageGenerator() {}
+
+GrTexture* MailboxTextureImageGenerator::onGenerateTexture(
+ GrContext* context,
+ const SkIRect* subset) {
+ if (sync_point_)
+ glWaitSyncPointCHROMIUM(sync_point_);
+
+ GLuint texture_id =
+ glCreateAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox_name_);
+ if (!texture_id)
+ return nullptr;
+
+ // TODO(jeffbrown): Give the caller more control over these parameters.
+ GrGLTextureInfo info;
+ info.fTarget = GL_TEXTURE_2D;
+ info.fID = texture_id;
+
+ GrBackendTextureDesc desc;
+ desc.fFlags = kRenderTarget_GrBackendTextureFlag;
+ desc.fWidth = getInfo().width();
+ desc.fHeight = getInfo().height();
+ desc.fConfig = kSkia8888_GrPixelConfig;
+ desc.fOrigin = kTopLeft_GrSurfaceOrigin;
+ desc.fTextureHandle = reinterpret_cast<GrBackendObject>(&info);
+ return context->textureProvider()->wrapBackendTexture(desc,
+ kAdopt_GrWrapOwnership);
+}
+
+} // namespace skia
+} // namespace mojo
« no previous file with comments | « mojo/skia/ganesh_image_factory.h ('k') | mojo/skia/ganesh_texture_surface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698