| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef GL_GLEXT_PROTOTYPES | 5 #ifndef GL_GLEXT_PROTOTYPES |
| 6 #define GL_GLEXT_PROTOTYPES | 6 #define GL_GLEXT_PROTOTYPES |
| 7 #endif | 7 #endif |
| 8 | 8 |
| 9 #include "mojo/skia/ganesh_image_factory.h" | 9 #include "mojo/skia/ganesh_image_factory.h" |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 release_callback->Run(); | 22 release_callback->Run(); |
| 23 delete release_callback; | 23 delete release_callback; |
| 24 } | 24 } |
| 25 } // namespace | 25 } // namespace |
| 26 | 26 |
| 27 ::skia::RefPtr<SkImage> CreateImageFromTexture( | 27 ::skia::RefPtr<SkImage> CreateImageFromTexture( |
| 28 const GaneshContext::Scope& scope, | 28 const GaneshContext::Scope& scope, |
| 29 uint32_t texture_id, | 29 uint32_t texture_id, |
| 30 uint32_t width, | 30 uint32_t width, |
| 31 uint32_t height, | 31 uint32_t height, |
| 32 GrSurfaceOrigin origin, |
| 32 const base::Closure& release_callback) { | 33 const base::Closure& release_callback) { |
| 33 DCHECK(texture_id); | 34 DCHECK(texture_id); |
| 34 DCHECK(width); | 35 DCHECK(width); |
| 35 DCHECK(height); | 36 DCHECK(height); |
| 36 | 37 |
| 37 // TODO(jeffbrown): Give the caller more control over these parameters. | 38 // TODO(jeffbrown): Give the caller more control over these parameters. |
| 38 GrGLTextureInfo info; | 39 GrGLTextureInfo info; |
| 39 info.fTarget = GL_TEXTURE_2D; | 40 info.fTarget = GL_TEXTURE_2D; |
| 40 info.fID = texture_id; | 41 info.fID = texture_id; |
| 41 | 42 |
| 42 GrBackendTextureDesc desc; | 43 GrBackendTextureDesc desc; |
| 43 desc.fFlags = kRenderTarget_GrBackendTextureFlag; | 44 desc.fFlags = kRenderTarget_GrBackendTextureFlag; |
| 44 desc.fWidth = width; | 45 desc.fWidth = width; |
| 45 desc.fHeight = height; | 46 desc.fHeight = height; |
| 46 desc.fConfig = kSkia8888_GrPixelConfig; | 47 desc.fConfig = kSkia8888_GrPixelConfig; |
| 47 desc.fOrigin = kTopLeft_GrSurfaceOrigin; | 48 desc.fOrigin = origin; |
| 48 desc.fTextureHandle = reinterpret_cast<GrBackendObject>(&info); | 49 desc.fTextureHandle = reinterpret_cast<GrBackendObject>(&info); |
| 49 return ::skia::AdoptRef(SkImage::NewFromTexture( | 50 return ::skia::AdoptRef(SkImage::NewFromTexture( |
| 50 scope.gr_context(), desc, kPremul_SkAlphaType, &ReleaseThunk, | 51 scope.gr_context(), desc, kPremul_SkAlphaType, &ReleaseThunk, |
| 51 new base::Closure(release_callback))); | 52 new base::Closure(release_callback))); |
| 52 } | 53 } |
| 53 | 54 |
| 54 MailboxTextureImageGenerator::MailboxTextureImageGenerator( | 55 MailboxTextureImageGenerator::MailboxTextureImageGenerator( |
| 55 const GLbyte mailbox_name[GL_MAILBOX_SIZE_CHROMIUM], | 56 const GLbyte mailbox_name[GL_MAILBOX_SIZE_CHROMIUM], |
| 56 GLuint sync_point, | 57 GLuint sync_point, |
| 57 uint32_t width, | 58 uint32_t width, |
| 58 uint32_t height) | 59 uint32_t height, |
| 60 GrSurfaceOrigin origin) |
| 59 : SkImageGenerator(SkImageInfo::MakeN32Premul(width, height)), | 61 : SkImageGenerator(SkImageInfo::MakeN32Premul(width, height)), |
| 60 sync_point_(sync_point) { | 62 sync_point_(sync_point), |
| 63 origin_(origin) { |
| 61 DCHECK(mailbox_name); | 64 DCHECK(mailbox_name); |
| 62 memcpy(mailbox_name_, mailbox_name, GL_MAILBOX_SIZE_CHROMIUM); | 65 memcpy(mailbox_name_, mailbox_name, GL_MAILBOX_SIZE_CHROMIUM); |
| 63 } | 66 } |
| 64 | 67 |
| 65 MailboxTextureImageGenerator::~MailboxTextureImageGenerator() {} | 68 MailboxTextureImageGenerator::~MailboxTextureImageGenerator() {} |
| 66 | 69 |
| 67 GrTexture* MailboxTextureImageGenerator::onGenerateTexture( | 70 GrTexture* MailboxTextureImageGenerator::onGenerateTexture( |
| 68 GrContext* context, | 71 GrContext* context, |
| 69 const SkIRect* subset) { | 72 const SkIRect* subset) { |
| 70 if (sync_point_) | 73 if (sync_point_) |
| 71 glWaitSyncPointCHROMIUM(sync_point_); | 74 glWaitSyncPointCHROMIUM(sync_point_); |
| 72 | 75 |
| 73 GLuint texture_id = | 76 GLuint texture_id = |
| 74 glCreateAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox_name_); | 77 glCreateAndConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox_name_); |
| 75 if (!texture_id) | 78 if (!texture_id) |
| 76 return nullptr; | 79 return nullptr; |
| 77 | 80 |
| 78 // TODO(jeffbrown): Give the caller more control over these parameters. | 81 // TODO(jeffbrown): Give the caller more control over these parameters. |
| 79 GrGLTextureInfo info; | 82 GrGLTextureInfo info; |
| 80 info.fTarget = GL_TEXTURE_2D; | 83 info.fTarget = GL_TEXTURE_2D; |
| 81 info.fID = texture_id; | 84 info.fID = texture_id; |
| 82 | 85 |
| 83 GrBackendTextureDesc desc; | 86 GrBackendTextureDesc desc; |
| 84 desc.fFlags = kRenderTarget_GrBackendTextureFlag; | 87 desc.fFlags = kRenderTarget_GrBackendTextureFlag; |
| 85 desc.fWidth = getInfo().width(); | 88 desc.fWidth = getInfo().width(); |
| 86 desc.fHeight = getInfo().height(); | 89 desc.fHeight = getInfo().height(); |
| 87 desc.fConfig = kSkia8888_GrPixelConfig; | 90 desc.fConfig = kSkia8888_GrPixelConfig; |
| 88 desc.fOrigin = kTopLeft_GrSurfaceOrigin; | 91 desc.fOrigin = origin_; |
| 89 desc.fTextureHandle = reinterpret_cast<GrBackendObject>(&info); | 92 desc.fTextureHandle = reinterpret_cast<GrBackendObject>(&info); |
| 90 return context->textureProvider()->wrapBackendTexture(desc, | 93 return context->textureProvider()->wrapBackendTexture(desc, |
| 91 kAdopt_GrWrapOwnership); | 94 kAdopt_GrWrapOwnership); |
| 92 } | 95 } |
| 93 | 96 |
| 94 } // namespace skia | 97 } // namespace skia |
| 95 } // namespace mojo | 98 } // namespace mojo |
| OLD | NEW |