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

Side by Side Diff: mojo/skia/ganesh_texture_surface.cc

Issue 1534033002: Improve Ganesh helpers. (Closed) Base URL: git@github.com:domokit/mojo.git@moz-8
Patch Set: fix includes Created 5 years 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
OLDNEW
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 "mojo/skia/ganesh_context.h"
12 #include "third_party/skia/include/gpu/gl/GrGLTypes.h"
13
8 namespace mojo { 14 namespace mojo {
15 namespace skia {
9 16
10 GaneshTextureSurface::GaneshTextureSurface(GaneshContext* context, 17 GaneshTextureSurface::GaneshTextureSurface(GaneshContext* context,
11 std::unique_ptr<GLTexture> texture) 18 std::unique_ptr<GLTexture> texture)
12 : texture_(std::move(texture)) { 19 : texture_(std::move(texture)) {
13 DCHECK(context); 20 DCHECK(context);
14 DCHECK(texture_); 21 DCHECK(texture_);
15 DCHECK(texture_->texture_id()); 22 DCHECK(texture_->texture_id());
16 DCHECK(texture_->size().width > 0); 23 DCHECK(texture_->size().width > 0);
17 DCHECK(texture_->size().height > 0); 24 DCHECK(texture_->size().height > 0);
25 GaneshContext::Scope scope(context);
26
27 GrGLTextureInfo info;
28 info.fTarget = GL_TEXTURE_2D;
29 info.fID = texture_->texture_id();
18 30
19 GrBackendTextureDesc desc; 31 GrBackendTextureDesc desc;
20 desc.fFlags = kRenderTarget_GrBackendTextureFlag; 32 desc.fFlags = kRenderTarget_GrBackendTextureFlag;
33 desc.fOrigin = kTopLeft_GrSurfaceOrigin;
21 desc.fWidth = texture_->size().width; 34 desc.fWidth = texture_->size().width;
22 desc.fHeight = texture_->size().height; 35 desc.fHeight = texture_->size().height;
23 desc.fConfig = kSkia8888_GrPixelConfig; 36 desc.fConfig = kSkia8888_GrPixelConfig;
24 desc.fOrigin = kTopLeft_GrSurfaceOrigin; 37 desc.fSampleCnt = 0;
25 desc.fTextureHandle = texture_->texture_id(); 38 desc.fTextureHandle = reinterpret_cast<GrBackendObject>(&info);
26 39
27 skia::RefPtr<GrTexture> gr_texture = skia::AdoptRef( 40 surface_ = ::skia::AdoptRef(
28 context->gr()->textureProvider()->wrapBackendTexture(desc)); 41 SkSurface::NewFromBackendTexture(context->gr_context(), desc, nullptr));
29 DCHECK(gr_texture);
30
31 surface_ = skia::AdoptRef(
32 SkSurface::NewRenderTargetDirect(gr_texture->asRenderTarget()));
33 DCHECK(surface_); 42 DCHECK(surface_);
34 } 43 }
35 44
36 GaneshTextureSurface::~GaneshTextureSurface() {} 45 GaneshTextureSurface::~GaneshTextureSurface() {}
37 46
38 std::unique_ptr<GLTexture> GaneshTextureSurface::TakeTexture() { 47 std::unique_ptr<GLTexture> GaneshTextureSurface::TakeTexture() {
39 surface_.clear(); 48 surface_.clear();
40 return std::move(texture_); 49 return std::move(texture_);
41 } 50 }
42 51
52 } // namespace skia
43 } // namespace mojo 53 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698