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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 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 #ifndef GL_GLEXT_PROTOTYPES
6 #define GL_GLEXT_PROTOTYPES
7 #endif
8
9 #include "mojo/skia/ganesh_image_factory.h"
10
11 #include "base/logging.h"
12 #include "third_party/skia/include/core/SkImage.h"
13 #include "third_party/skia/include/gpu/GrContext.h"
14 #include "third_party/skia/include/gpu/GrTextureProvider.h"
15 #include "third_party/skia/include/gpu/gl/GrGLTypes.h"
16
17 namespace mojo {
18 namespace skia {
19 namespace {
20 void ReleaseThunk(void* data) {
21 auto release_callback = static_cast<base::Closure*>(data);
22 release_callback->Run();
23 delete release_callback;
24 }
25 } // namespace
26
27 ::skia::RefPtr<SkImage> CreateImageFromTexture(
28 const GaneshContext::Scope& scope,
29 uint32_t texture_id,
30 uint32_t width,
31 uint32_t height,
32 const base::Closure& release_callback) {
33 DCHECK(texture_id);
34 DCHECK(width);
35 DCHECK(height);
36
37 // TODO(jeffbrown): Give the caller more control over these parameters.
38 GrGLTextureInfo info;
39 info.fTarget = GL_TEXTURE_2D;
40 info.fID = texture_id;
41
42 GrBackendTextureDesc desc;
43 desc.fFlags = kRenderTarget_GrBackendTextureFlag;
44 desc.fWidth = width;
45 desc.fHeight = height;
46 desc.fConfig = kSkia8888_GrPixelConfig;
47 desc.fOrigin = kTopLeft_GrSurfaceOrigin;
48 desc.fTextureHandle = reinterpret_cast<GrBackendObject>(&info);
49 return ::skia::AdoptRef(SkImage::NewFromTexture(
50 scope.gr_context(), desc, kPremul_SkAlphaType, &ReleaseThunk,
51 new base::Closure(release_callback)));
52 }
53
54 MailboxTextureImageGenerator::MailboxTextureImageGenerator(
55 const GLbyte mailbox_name[GL_MAILBOX_SIZE_CHROMIUM],
56 GLuint sync_point,
57 uint32_t width,
58 uint32_t height)
59 : SkImageGenerator(SkImageInfo::MakeN32Premul(width, height)),
60 sync_point_(sync_point) {
61 DCHECK(mailbox_name);
62 memcpy(mailbox_name_, mailbox_name, GL_MAILBOX_SIZE_CHROMIUM);
63 }
64
65 MailboxTextureImageGenerator::~MailboxTextureImageGenerator() {}
66
67 GrTexture* MailboxTextureImageGenerator::onGenerateTexture(
68 GrContext* context,
69 const SkIRect* subset) {
70 if (sync_point_)
71 glWaitSyncPointCHROMIUM(sync_point_);
72
73 GLuint texture_id =
74 glCreateAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox_name_);
75 if (!texture_id)
76 return nullptr;
77
78 // TODO(jeffbrown): Give the caller more control over these parameters.
79 GrGLTextureInfo info;
80 info.fTarget = GL_TEXTURE_2D;
81 info.fID = texture_id;
82
83 GrBackendTextureDesc desc;
84 desc.fFlags = kRenderTarget_GrBackendTextureFlag;
85 desc.fWidth = getInfo().width();
86 desc.fHeight = getInfo().height();
87 desc.fConfig = kSkia8888_GrPixelConfig;
88 desc.fOrigin = kTopLeft_GrSurfaceOrigin;
89 desc.fTextureHandle = reinterpret_cast<GrBackendObject>(&info);
90 return context->textureProvider()->wrapBackendTexture(desc,
91 kAdopt_GrWrapOwnership);
92 }
93
94 } // namespace skia
95 } // namespace mojo
OLDNEW
« 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