| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 #include "base/logging.h" | |
| 6 #include "mojo/skia/ganesh_texture_surface.h" | 5 #include "mojo/skia/ganesh_texture_surface.h" |
| 7 | 6 |
| 7 #include <GLES2/gl2.h> |
| 8 |
| 9 #include "base/logging.h" |
| 10 #include "mojo/gpu/gl_texture.h" |
| 11 #include "third_party/skia/include/gpu/gl/GrGLTypes.h" |
| 12 |
| 8 namespace mojo { | 13 namespace mojo { |
| 14 namespace skia { |
| 9 | 15 |
| 10 GaneshTextureSurface::GaneshTextureSurface(GaneshContext* context, | 16 GaneshTextureSurface::GaneshTextureSurface(const GaneshContext::Scope& scope, |
| 11 std::unique_ptr<GLTexture> texture) | 17 std::unique_ptr<GLTexture> texture) |
| 12 : texture_(std::move(texture)) { | 18 : texture_(std::move(texture)) { |
| 13 DCHECK(context); | |
| 14 DCHECK(texture_); | 19 DCHECK(texture_); |
| 15 DCHECK(texture_->texture_id()); | 20 DCHECK(texture_->texture_id()); |
| 16 DCHECK(texture_->size().width > 0); | 21 DCHECK(texture_->size().width > 0); |
| 17 DCHECK(texture_->size().height > 0); | 22 DCHECK(texture_->size().height > 0); |
| 23 GrGLTextureInfo info; |
| 24 info.fTarget = GL_TEXTURE_2D; |
| 25 info.fID = texture_->texture_id(); |
| 18 | 26 |
| 19 GrBackendTextureDesc desc; | 27 GrBackendTextureDesc desc; |
| 20 desc.fFlags = kRenderTarget_GrBackendTextureFlag; | 28 desc.fFlags = kRenderTarget_GrBackendTextureFlag; |
| 29 desc.fOrigin = kTopLeft_GrSurfaceOrigin; |
| 21 desc.fWidth = texture_->size().width; | 30 desc.fWidth = texture_->size().width; |
| 22 desc.fHeight = texture_->size().height; | 31 desc.fHeight = texture_->size().height; |
| 23 desc.fConfig = kSkia8888_GrPixelConfig; | 32 desc.fConfig = kSkia8888_GrPixelConfig; |
| 24 desc.fOrigin = kTopLeft_GrSurfaceOrigin; | 33 desc.fSampleCnt = 0; |
| 25 desc.fTextureHandle = texture_->texture_id(); | 34 desc.fTextureHandle = reinterpret_cast<GrBackendObject>(&info); |
| 26 | 35 |
| 27 skia::RefPtr<GrTexture> gr_texture = skia::AdoptRef( | 36 surface_ = ::skia::AdoptRef( |
| 28 context->gr()->textureProvider()->wrapBackendTexture(desc)); | 37 SkSurface::NewFromBackendTexture(scope.gr_context(), desc, nullptr)); |
| 29 DCHECK(gr_texture); | |
| 30 | |
| 31 surface_ = skia::AdoptRef( | |
| 32 SkSurface::NewRenderTargetDirect(gr_texture->asRenderTarget())); | |
| 33 DCHECK(surface_); | 38 DCHECK(surface_); |
| 34 } | 39 } |
| 35 | 40 |
| 36 GaneshTextureSurface::~GaneshTextureSurface() {} | 41 GaneshTextureSurface::~GaneshTextureSurface() {} |
| 37 | 42 |
| 38 std::unique_ptr<GLTexture> GaneshTextureSurface::TakeTexture() { | 43 std::unique_ptr<GLTexture> GaneshTextureSurface::TakeTexture() { |
| 39 surface_.clear(); | 44 surface_.clear(); |
| 40 return std::move(texture_); | 45 return std::move(texture_); |
| 41 } | 46 } |
| 42 | 47 |
| 48 } // namespace skia |
| 43 } // namespace mojo | 49 } // namespace mojo |
| OLD | NEW |