OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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 #include "mojo/skia/ganesh_helpers.h" |
| 6 |
| 7 #include <GLES2/gl2.h> |
| 8 |
| 9 #include "mojo/skia/ganesh_context.h" |
| 10 #include "third_party/skia/include/core/SkImage.h" |
| 11 #include "third_party/skia/include/gpu/gl/GrGLTypes.h" |
| 12 |
| 13 namespace mojo { |
| 14 namespace skia { |
| 15 |
| 16 static void ReleaseThunk(void* data) { |
| 17 auto release_callback = static_cast<base::Closure*>(data); |
| 18 release_callback->Run(); |
| 19 delete release_callback; |
| 20 } |
| 21 |
| 22 ::skia::RefPtr<SkImage> CreateImageFromTexture( |
| 23 GaneshContext* context, |
| 24 uint32_t texture_id, |
| 25 uint32_t width, |
| 26 uint32_t height, |
| 27 const base::Closure& release_callback) { |
| 28 DCHECK(context); |
| 29 GaneshContext::Scope scope(context); |
| 30 |
| 31 // TODO(jeffbrown): Give the caller more control over these parameters |
| 32 // as required. |
| 33 GrGLTextureInfo info; |
| 34 info.fTarget = GL_TEXTURE_2D; |
| 35 info.fID = texture_id; |
| 36 |
| 37 GrBackendTextureDesc desc; |
| 38 desc.fFlags = kRenderTarget_GrBackendTextureFlag; |
| 39 desc.fWidth = width; |
| 40 desc.fHeight = height; |
| 41 desc.fConfig = kSkia8888_GrPixelConfig; |
| 42 desc.fOrigin = kTopLeft_GrSurfaceOrigin; |
| 43 desc.fTextureHandle = reinterpret_cast<GrBackendObject>(&info); |
| 44 return ::skia::AdoptRef(SkImage::NewFromTexture( |
| 45 context->gr_context(), desc, kPremul_SkAlphaType, &ReleaseThunk, |
| 46 new base::Closure(release_callback))); |
| 47 } |
| 48 |
| 49 } // namespace skia |
| 50 } // namespace mojo |
OLD | NEW |