Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qq_34031325
engine
提交
2b18a40f
E
engine
项目概览
qq_34031325
/
engine
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
engine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2b18a40f
编写于
7月 26, 2016
作者:
C
Chinmay Garde
提交者:
GitHub
7月 26, 2016
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Utilities for creating texture backed SkImages. (#2829)
上级
f5c907d6
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
156 addition
and
0 deletion
+156
-0
flow/BUILD.gn
flow/BUILD.gn
+3
-0
flow/open_gl.h
flow/open_gl.h
+28
-0
flow/texture_image.cc
flow/texture_image.cc
+92
-0
flow/texture_image.h
flow/texture_image.h
+33
-0
未找到文件。
flow/BUILD.gn
浏览文件 @
2b18a40f
...
...
@@ -38,8 +38,11 @@ source_set("flow") {
"layers/shader_mask_layer.h",
"layers/transform_layer.cc",
"layers/transform_layer.h",
"open_gl.h",
"raster_cache.cc",
"raster_cache.h",
"texture_image.cc",
"texture_image.h",
]
deps = [
...
...
flow/open_gl.h
0 → 100644
浏览文件 @
2b18a40f
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLOW_OPEN_GL_H_
#define FLOW_OPEN_GL_H_
#include "build/build_config.h"
#if OS_IOS
#include <OpenGLES/ES2/gl.h>
#elif OS_MACOSX
#include <OpenGL/gl.h>
#elif OS_ANDROID
#include <GLES2/gl2.h>
#else
#error OpenGL headers not found for this platform.
#endif
#endif // FLOW_OPEN_GL_H_
flow/texture_image.cc
0 → 100644
浏览文件 @
2b18a40f
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flow/texture_image.h"
#include "flow/open_gl.h"
namespace
flow
{
inline
GLint
ToGLFormat
(
TextureImageFormat
format
)
{
switch
(
format
)
{
case
TextureImageFormat
::
RGBA
:
return
GL_RGBA
;
case
TextureImageFormat
::
RGB
:
return
GL_RGB
;
case
TextureImageFormat
::
Grey
:
return
GL_LUMINANCE
;
case
TextureImageFormat
::
GreyAlpha
:
return
GL_LUMINANCE_ALPHA
;
}
return
GL_NONE
;
}
inline
GLint
ToGLDataFormat
(
TextureImageDataFormat
dataFormat
)
{
switch
(
dataFormat
)
{
case
TextureImageDataFormat
::
UnsignedByte
:
return
GL_UNSIGNED_BYTE
;
case
TextureImageDataFormat
::
UnsignedShort565
:
return
GL_UNSIGNED_SHORT_5_6_5
;
}
return
GL_NONE
;
}
sk_sp
<
SkImage
>
TextureImageCreate
(
GrContext
*
context
,
TextureImageFormat
format
,
const
SkISize
&
size
,
TextureImageDataFormat
dataFormat
,
const
uint8_t
*
data
)
{
GLuint
handle
=
GL_NONE
;
// Generate the texture handle.
glGenTextures
(
1
,
&
handle
);
// Bind the texture.
glBindTexture
(
GL_TEXTURE_2D
,
handle
);
// Specify default texture properties.
glTexParameteri
(
GL_TEXTURE_2D
,
GL_TEXTURE_WRAP_S
,
GL_CLAMP_TO_EDGE
);
glTexParameteri
(
GL_TEXTURE_2D
,
GL_TEXTURE_WRAP_T
,
GL_CLAMP_TO_EDGE
);
glTexParameteri
(
GL_TEXTURE_2D
,
GL_TEXTURE_MIN_FILTER
,
GL_LINEAR
);
glTexParameteri
(
GL_TEXTURE_2D
,
GL_TEXTURE_MAG_FILTER
,
GL_LINEAR
);
// Update unpack alignment based on format.
glPixelStorei
(
GL_UNPACK_ALIGNMENT
,
dataFormat
==
TextureImageDataFormat
::
UnsignedByte
?
4
:
2
);
GLint
gl_format
=
ToGLFormat
(
format
);
// Upload the texture.
glTexImage2D
(
GL_TEXTURE_2D
,
// target
0
,
// level
gl_format
,
// internal format
size
.
fWidth
,
// width
size
.
fHeight
,
// height
0
,
// border
gl_format
,
// format
ToGLDataFormat
(
dataFormat
),
// format
data
);
// Clear the binding. We are done.
glBindTexture
(
GL_TEXTURE_2D
,
GL_NONE
);
// Create an SkImage handle from the texture.
GrBackendTextureDesc
desc
;
desc
.
fWidth
=
size
.
fWidth
;
desc
.
fHeight
=
size
.
fHeight
;
desc
.
fTextureHandle
=
handle
;
if
(
auto
image
=
SkImage
::
MakeFromAdoptedTexture
(
context
,
desc
))
{
// Texture handle was successfully adopted by the SkImage.
return
image
;
}
// We could not create an SkImage from the texture. Since it could not be
// adopted, delete the handle and return null.
glDeleteTextures
(
1
,
&
handle
);
return
nullptr
;
}
}
// namespace flow
flow/texture_image.h
0 → 100644
浏览文件 @
2b18a40f
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLOW_TEXTURE_IMAGE_H_
#define FLOW_TEXTURE_IMAGE_H_
#include "base/macros.h"
#include "third_party/skia/include/core/SkImage.h"
namespace
flow
{
enum
class
TextureImageFormat
{
Grey
,
GreyAlpha
,
RGB
,
RGBA
,
};
enum
class
TextureImageDataFormat
{
UnsignedByte
,
UnsignedShort565
,
};
sk_sp
<
SkImage
>
TextureImageCreate
(
GrContext
*
context
,
TextureImageFormat
format
,
const
SkISize
&
size
,
TextureImageDataFormat
dataFormat
,
const
uint8_t
*
data
);
}
// namespace flow
#endif // FLOW_TEXTURE_IMAGE_H_
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录