Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sxychenjing
engine
提交
fafccf8a
E
engine
项目概览
sxychenjing
/
engine
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
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,发现更多精彩内容 >>
未验证
提交
fafccf8a
编写于
6月 05, 2020
作者:
E
Emmanuel Garcia
提交者:
GitHub
6月 05, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor AndroidContextGL, AndroidSurface and AndroidSurfaceGL (#18670)
上级
e87a05fb
变更
16
隐藏空白更改
内联
并排
Showing
16 changed file
with
344 addition
and
204 deletion
+344
-204
ci/licenses_golden/licenses_flutter
ci/licenses_golden/licenses_flutter
+2
-0
shell/platform/android/BUILD.gn
shell/platform/android/BUILD.gn
+2
-0
shell/platform/android/android_context.cc
shell/platform/android/android_context.cc
+37
-0
shell/platform/android/android_context.h
shell/platform/android/android_context.h
+43
-0
shell/platform/android/android_context_gl.cc
shell/platform/android/android_context_gl.cc
+57
-80
shell/platform/android/android_context_gl.h
shell/platform/android/android_context_gl.h
+84
-20
shell/platform/android/android_surface.cc
shell/platform/android/android_surface.cc
+16
-11
shell/platform/android/android_surface.h
shell/platform/android/android_surface.h
+6
-3
shell/platform/android/android_surface_gl.cc
shell/platform/android/android_surface_gl.cc
+65
-72
shell/platform/android/android_surface_gl.h
shell/platform/android/android_surface_gl.h
+7
-7
shell/platform/android/android_surface_software.cc
shell/platform/android/android_surface_software.cc
+3
-2
shell/platform/android/android_surface_software.h
shell/platform/android/android_surface_software.h
+2
-2
shell/platform/android/android_surface_vulkan.cc
shell/platform/android/android_surface_vulkan.cc
+3
-2
shell/platform/android/android_surface_vulkan.h
shell/platform/android/android_surface_vulkan.h
+2
-2
shell/platform/android/platform_view_android.cc
shell/platform/android/platform_view_android.cc
+13
-2
shell/platform/android/platform_view_android.h
shell/platform/android/platform_view_android.h
+2
-1
未找到文件。
ci/licenses_golden/licenses_flutter
浏览文件 @
fafccf8a
...
...
@@ -645,6 +645,8 @@ FILE: ../../../flutter/shell/gpu/gpu_surface_vulkan.h
FILE: ../../../flutter/shell/gpu/gpu_surface_vulkan_delegate.cc
FILE: ../../../flutter/shell/gpu/gpu_surface_vulkan_delegate.h
FILE: ../../../flutter/shell/platform/android/AndroidManifest.xml
FILE: ../../../flutter/shell/platform/android/android_context.cc
FILE: ../../../flutter/shell/platform/android/android_context.h
FILE: ../../../flutter/shell/platform/android/android_context_gl.cc
FILE: ../../../flutter/shell/platform/android/android_context_gl.h
FILE: ../../../flutter/shell/platform/android/android_environment_gl.cc
...
...
shell/platform/android/BUILD.gn
浏览文件 @
fafccf8a
...
...
@@ -23,6 +23,8 @@ shared_library("flutter_shell_native") {
sources = [
"$root_build_dir/flutter_icu/icudtl.o",
"android_context.cc",
"android_context.h",
"android_context_gl.cc",
"android_context_gl.h",
"android_environment_gl.cc",
...
...
shell/platform/android/android_context.cc
0 → 100644
浏览文件 @
fafccf8a
// Copyright 2013 The Flutter 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 "flutter/shell/platform/android/android_context.h"
#include "flutter/shell/platform/android/android_context_gl.h"
#include "flutter/shell/platform/android/android_environment_gl.h"
namespace
flutter
{
std
::
shared_ptr
<
AndroidContext
>
CreateContextGL
()
{
auto
context_gl
=
std
::
make_shared
<
AndroidContextGL
>
(
AndroidRenderingAPI
::
kOpenGLES
,
fml
::
MakeRefCounted
<
AndroidEnvironmentGL
>
());
FML_CHECK
(
context_gl
->
IsValid
())
<<
"Could not create an Android context GL."
;
return
context_gl
;
}
AndroidContext
::
AndroidContext
(
AndroidRenderingAPI
rendering_api
)
:
rendering_api_
(
rendering_api
)
{}
AndroidContext
::~
AndroidContext
()
=
default
;
AndroidRenderingAPI
AndroidContext
::
RenderingApi
()
const
{
return
rendering_api_
;
}
std
::
shared_ptr
<
AndroidContext
>
AndroidContext
::
Create
(
AndroidRenderingAPI
rendering_api
)
{
if
(
rendering_api
==
AndroidRenderingAPI
::
kOpenGLES
)
{
return
CreateContextGL
();
}
return
std
::
make_shared
<
AndroidContext
>
(
rendering_api
);
}
}
// namespace flutter
shell/platform/android/android_context.h
0 → 100644
浏览文件 @
fafccf8a
// Copyright 2013 The Flutter 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 FLUTTER_SHELL_PLATFORM_ANDROID_ANDROID_CONTEXT_H_
#define FLUTTER_SHELL_PLATFORM_ANDROID_ANDROID_CONTEXT_H_
#include "flutter/fml/macros.h"
#include "flutter/fml/memory/ref_counted.h"
#include "flutter/fml/memory/ref_ptr.h"
#include "flutter/shell/common/platform_view.h"
namespace
flutter
{
enum
class
AndroidRenderingAPI
{
kSoftware
,
kOpenGLES
,
kVulkan
,
};
//------------------------------------------------------------------------------
/// @brief Holds state that is shared across Android surfaces.
///
class
AndroidContext
{
public:
AndroidContext
(
AndroidRenderingAPI
rendering_api
);
~
AndroidContext
();
static
std
::
shared_ptr
<
AndroidContext
>
Create
(
AndroidRenderingAPI
rendering_api
);
AndroidRenderingAPI
RenderingApi
()
const
;
private:
const
AndroidRenderingAPI
rendering_api_
;
FML_DISALLOW_COPY_AND_ASSIGN
(
AndroidContext
);
};
}
// namespace flutter
#endif // FLUTTER_SHELL_PLATFORM_ANDROID_ANDROID_CONTEXT_H_
shell/platform/android/android_context_gl.cc
浏览文件 @
fafccf8a
...
...
@@ -105,62 +105,21 @@ static bool TeardownContext(EGLDisplay display, EGLContext context) {
return
true
;
}
static
bool
TeardownSurface
(
EGLDisplay
display
,
EGLSurface
surface
)
{
if
(
surface
!=
EGL_NO_SURFACE
)
{
return
eglDestroySurface
(
display
,
surface
)
==
EGL_TRUE
;
}
return
true
;
}
// For onscreen rendering.
bool
AndroidContextGL
::
CreateWindowSurface
(
fml
::
RefPtr
<
AndroidNativeWindow
>
window
)
{
// The configurations are only required when dealing with extensions or VG.
// We do neither.
window_
=
std
::
move
(
window
);
EGLDisplay
display
=
environment_
->
Display
();
const
EGLint
attribs
[]
=
{
EGL_NONE
};
surface_
=
eglCreateWindowSurface
(
display
,
config_
,
reinterpret_cast
<
EGLNativeWindowType
>
(
window_
->
handle
()),
attribs
);
return
surface_
!=
EGL_NO_SURFACE
;
}
// For offscreen rendering.
bool
AndroidContextGL
::
CreatePBufferSurface
()
{
// We only ever create pbuffer surfaces for background resource loading
// contexts. We never bind the pbuffer to anything.
EGLDisplay
display
=
environment_
->
Display
();
const
EGLint
attribs
[]
=
{
EGL_WIDTH
,
1
,
EGL_HEIGHT
,
1
,
EGL_NONE
};
surface_
=
eglCreatePbufferSurface
(
display
,
config_
,
attribs
);
return
surface_
!=
EGL_NO_SURFACE
;
}
AndroidContextGL
::
AndroidContextGL
(
fml
::
RefPtr
<
AndroidEnvironmentGL
>
env
,
const
AndroidContextGL
*
share_context
)
:
environment_
(
env
),
window_
(
nullptr
),
config_
(
nullptr
),
surface_
(
EGL_NO_SURFACE
),
context_
(
EGL_NO_CONTEXT
),
valid_
(
false
)
{
AndroidContextGL
::
AndroidContextGL
(
AndroidRenderingAPI
rendering_api
,
fml
::
RefPtr
<
AndroidEnvironmentGL
>
environment
)
:
AndroidContext
(
AndroidRenderingAPI
::
kOpenGLES
),
environment_
(
environment
),
config_
(
nullptr
)
{
if
(
!
environment_
->
IsValid
())
{
FML_LOG
(
ERROR
)
<<
"Could not create an Android GL environment."
;
return
;
}
bool
success
=
false
;
// Choose a valid configuration.
std
::
tie
(
success
,
config_
)
=
ChooseEGLConfiguration
(
environment_
->
Display
());
if
(
!
success
)
{
FML_LOG
(
ERROR
)
<<
"Could not choose an EGL configuration."
;
LogLastEGLError
();
...
...
@@ -168,19 +127,18 @@ AndroidContextGL::AndroidContextGL(fml::RefPtr<AndroidEnvironmentGL> env,
}
// Create a context for the configuration.
std
::
tie
(
success
,
context_
)
=
CreateContext
(
environment_
->
Display
(),
config_
,
share_context
!=
nullptr
?
share_context
->
context_
:
EGL_NO_CONTEXT
);
std
::
tie
(
success
,
context_
)
=
CreateContext
(
environment_
->
Display
(),
config_
,
EGL_NO_CONTEXT
);
if
(
!
success
)
{
FML_LOG
(
ERROR
)
<<
"Could not create an EGL context"
;
LogLastEGLError
();
return
;
}
if
(
!
this
->
CreatePBufferSurface
())
{
FML_LOG
(
ERROR
)
<<
"Could not create the EGL surface."
;
std
::
tie
(
success
,
resource_context_
)
=
CreateContext
(
environment_
->
Display
(),
config_
,
context_
);
if
(
!
success
)
{
FML_LOG
(
ERROR
)
<<
"Could not create an EGL resource context"
;
LogLastEGLError
();
return
;
}
...
...
@@ -196,13 +154,34 @@ AndroidContextGL::~AndroidContextGL() {
LogLastEGLError
();
}
if
(
!
Teardown
Surface
(
environment_
->
Display
(),
surface
_
))
{
FML_LOG
(
ERROR
)
<<
"Could not tear down the EGL surface. Possible
resource leak."
;
if
(
!
Teardown
Context
(
environment_
->
Display
(),
resource_context
_
))
{
FML_LOG
(
ERROR
)
<<
"Could not tear down the EGL resource context. Possible "
"
resource leak."
;
LogLastEGLError
();
}
}
EGLSurface
AndroidContextGL
::
CreateOnscreenSurface
(
fml
::
RefPtr
<
AndroidNativeWindow
>
window
)
const
{
EGLDisplay
display
=
environment_
->
Display
();
const
EGLint
attribs
[]
=
{
EGL_NONE
};
return
eglCreateWindowSurface
(
display
,
config_
,
reinterpret_cast
<
EGLNativeWindowType
>
(
window
->
handle
()),
attribs
);
}
EGLSurface
AndroidContextGL
::
CreateOffscreenSurface
()
const
{
// We only ever create pbuffer surfaces for background resource loading
// contexts. We never bind the pbuffer to anything.
EGLDisplay
display
=
environment_
->
Display
();
const
EGLint
attribs
[]
=
{
EGL_WIDTH
,
1
,
EGL_HEIGHT
,
1
,
EGL_NONE
};
return
eglCreatePbufferSurface
(
display
,
config_
,
attribs
);
}
fml
::
RefPtr
<
AndroidEnvironmentGL
>
AndroidContextGL
::
Environment
()
const
{
return
environment_
;
}
...
...
@@ -211,8 +190,8 @@ bool AndroidContextGL::IsValid() const {
return
valid_
;
}
bool
AndroidContextGL
::
MakeCurrent
()
{
if
(
eglMakeCurrent
(
environment_
->
Display
(),
surface
_
,
surface_
,
context_
)
!=
bool
AndroidContextGL
::
MakeCurrent
(
EGLSurface
&
surface
)
{
if
(
eglMakeCurrent
(
environment_
->
Display
(),
surface
,
surface
,
context_
)
!=
EGL_TRUE
)
{
FML_LOG
(
ERROR
)
<<
"Could not make the context current"
;
LogLastEGLError
();
...
...
@@ -221,6 +200,16 @@ bool AndroidContextGL::MakeCurrent() {
return
true
;
}
bool
AndroidContextGL
::
ResourceMakeCurrent
(
EGLSurface
&
surface
)
{
if
(
eglMakeCurrent
(
environment_
->
Display
(),
surface
,
surface
,
resource_context_
)
!=
EGL_TRUE
)
{
FML_LOG
(
ERROR
)
<<
"Could not make the context current"
;
LogLastEGLError
();
return
false
;
}
return
true
;
}
bool
AndroidContextGL
::
ClearCurrent
()
{
if
(
eglGetCurrentContext
()
!=
context_
)
{
return
true
;
...
...
@@ -234,18 +223,17 @@ bool AndroidContextGL::ClearCurrent() {
return
true
;
}
bool
AndroidContextGL
::
SwapBuffers
()
{
bool
AndroidContextGL
::
SwapBuffers
(
EGLSurface
&
surface
)
{
TRACE_EVENT0
(
"flutter"
,
"AndroidContextGL::SwapBuffers"
);
return
eglSwapBuffers
(
environment_
->
Display
(),
surface
_
);
return
eglSwapBuffers
(
environment_
->
Display
(),
surface
);
}
SkISize
AndroidContextGL
::
GetSize
()
{
SkISize
AndroidContextGL
::
GetSize
(
EGLSurface
&
surface
)
{
EGLint
width
=
0
;
EGLint
height
=
0
;
if
(
!
eglQuerySurface
(
environment_
->
Display
(),
surface_
,
EGL_WIDTH
,
&
width
)
||
!
eglQuerySurface
(
environment_
->
Display
(),
surface_
,
EGL_HEIGHT
,
&
height
))
{
if
(
!
eglQuerySurface
(
environment_
->
Display
(),
surface
,
EGL_WIDTH
,
&
width
)
||
!
eglQuerySurface
(
environment_
->
Display
(),
surface
,
EGL_HEIGHT
,
&
height
))
{
FML_LOG
(
ERROR
)
<<
"Unable to query EGL surface size"
;
LogLastEGLError
();
return
SkISize
::
Make
(
0
,
0
);
...
...
@@ -253,22 +241,11 @@ SkISize AndroidContextGL::GetSize() {
return
SkISize
::
Make
(
width
,
height
);
}
bool
AndroidContextGL
::
Resize
(
const
SkISize
&
size
)
{
if
(
size
==
GetSize
())
{
return
true
;
}
ClearCurrent
();
TeardownSurface
(
environment_
->
Display
(),
surface_
);
if
(
!
this
->
CreateWindowSurface
(
window_
))
{
FML_LOG
(
ERROR
)
<<
"Unable to create EGL window surface on resize."
;
return
false
;
bool
AndroidContextGL
::
TeardownSurface
(
EGLSurface
&
surface
)
{
if
(
surface
!=
EGL_NO_SURFACE
)
{
return
eglDestroySurface
(
environment_
->
Display
(),
surface
)
==
EGL_TRUE
;
}
MakeCurrent
();
return
true
;
}
...
...
shell/platform/android/android_context_gl.h
浏览文件 @
fafccf8a
...
...
@@ -9,47 +9,111 @@
#include "flutter/fml/memory/ref_counted.h"
#include "flutter/fml/memory/ref_ptr.h"
#include "flutter/shell/common/platform_view.h"
#include "flutter/shell/platform/android/android_context.h"
#include "flutter/shell/platform/android/android_environment_gl.h"
#include "flutter/shell/platform/android/android_native_window.h"
#include "third_party/skia/include/core/SkSize.h"
namespace
flutter
{
class
AndroidContextGL
:
public
fml
::
RefCountedThreadSafe
<
AndroidContextGL
>
{
//------------------------------------------------------------------------------
/// The Android context is used by `AndroidSurfaceGL` to create and manage
/// EGL surfaces.
///
/// This context binds `EGLContext` to the current rendering thread and to the
/// draw and read `EGLSurface`s.
///
class
AndroidContextGL
:
public
AndroidContext
{
public:
bool
CreateWindowSurface
(
fml
::
RefPtr
<
AndroidNativeWindow
>
window
);
AndroidContextGL
(
AndroidRenderingAPI
rendering_api
,
fml
::
RefPtr
<
AndroidEnvironmentGL
>
environment
);
bool
CreatePBufferSurface
();
~
AndroidContextGL
();
//----------------------------------------------------------------------------
/// @brief Allocates an new EGL window surface that is used for on-screen
/// pixels.
///
/// @attention Consumers must tear down the surface by calling
/// `AndroidContextGL::TeardownSurface`.
///
/// @return The window surface.
///
EGLSurface
CreateOnscreenSurface
(
fml
::
RefPtr
<
AndroidNativeWindow
>
window
)
const
;
//----------------------------------------------------------------------------
/// @brief Allocates an 1x1 pbuffer surface that is used for making the
/// offscreen current for texture uploads.
///
/// @attention Consumers must tear down the surface by calling
/// `AndroidContextGL::TeardownSurface`.
///
/// @return The pbuffer surface.
///
EGLSurface
CreateOffscreenSurface
()
const
;
//----------------------------------------------------------------------------
/// @return The Android environment that contains a reference to the
/// display.
///
fml
::
RefPtr
<
AndroidEnvironmentGL
>
Environment
()
const
;
//----------------------------------------------------------------------------
/// @return Whether the current context is valid. That is, if the EGL
/// contexts
/// were successfully created.
///
bool
IsValid
()
const
;
bool
MakeCurrent
();
//----------------------------------------------------------------------------
/// @return Whether the current context was successfully clear.
///
bool
ClearCurrent
();
bool
SwapBuffers
();
SkISize
GetSize
();
bool
Resize
(
const
SkISize
&
size
);
//----------------------------------------------------------------------------
/// @brief Binds the EGLContext context to the current rendering thread
/// and to the draw and read surface.
///
/// @return Whether the surface was made current.
///
bool
MakeCurrent
(
EGLSurface
&
surface
);
//----------------------------------------------------------------------------
/// @brief Binds the resource EGLContext context to the current rendering
/// thread and to the draw and read surface.
///
/// @return Whether the surface was made current.
///
bool
ResourceMakeCurrent
(
EGLSurface
&
surface
);
//----------------------------------------------------------------------------
/// @brief This only applies to on-screen surfaces such as those created
/// by `AndroidContextGL::CreateOnscreenSurface`.
///
/// @return Whether the EGL surface color buffer was swapped.
///
bool
SwapBuffers
(
EGLSurface
&
surface
);
//----------------------------------------------------------------------------
/// @return The size of an `EGLSurface`.
///
SkISize
GetSize
(
EGLSurface
&
surface
);
//----------------------------------------------------------------------------
/// @brief Destroys an `EGLSurface`.
///
/// @return Whether the surface was destroyed.
///
bool
TeardownSurface
(
EGLSurface
&
surface
);
private:
fml
::
RefPtr
<
AndroidEnvironmentGL
>
environment_
;
fml
::
RefPtr
<
AndroidNativeWindow
>
window_
;
EGLConfig
config_
;
EGLSurface
surface_
;
EGLContext
context_
;
bool
valid_
;
AndroidContextGL
(
fml
::
RefPtr
<
AndroidEnvironmentGL
>
env
,
const
AndroidContextGL
*
share_context
=
nullptr
);
~
AndroidContextGL
();
EGLContext
resource_context_
;
bool
valid_
=
false
;
FML_FRIEND_MAKE_REF_COUNTED
(
AndroidContextGL
);
FML_FRIEND_REF_COUNTED_THREAD_SAFE
(
AndroidContextGL
);
FML_DISALLOW_COPY_AND_ASSIGN
(
AndroidContextGL
);
};
...
...
shell/platform/android/android_surface.cc
浏览文件 @
fafccf8a
...
...
@@ -15,19 +15,24 @@
namespace
flutter
{
std
::
unique_ptr
<
AndroidSurface
>
AndroidSurface
::
Create
(
bool
use_software_rendering
)
{
if
(
use_software_rendering
)
{
auto
software_surface
=
std
::
make_unique
<
AndroidSurfaceSoftware
>
();
return
software_surface
->
IsValid
()
?
std
::
move
(
software_surface
)
:
nullptr
;
}
std
::
shared_ptr
<
AndroidContext
>
android_context
)
{
std
::
unique_ptr
<
AndroidSurface
>
surface
;
switch
(
android_context
->
RenderingApi
())
{
case
AndroidRenderingAPI
::
kSoftware
:
surface
=
std
::
make_unique
<
AndroidSurfaceSoftware
>
();
break
;
case
AndroidRenderingAPI
::
kOpenGLES
:
surface
=
std
::
make_unique
<
AndroidSurfaceGL
>
(
android_context
);
break
;
case
AndroidRenderingAPI
::
kVulkan
:
#if SHELL_ENABLE_VULKAN
auto
vulkan_surface
=
std
::
make_unique
<
AndroidSurfaceVulkan
>
();
return
vulkan_surface
->
IsValid
()
?
std
::
move
(
vulkan_surface
)
:
nullptr
;
#else // SHELL_ENABLE_VULKAN
auto
gl_surface
=
std
::
make_unique
<
AndroidSurfaceGL
>
();
return
gl_surface
->
IsOffscreenContextValid
()
?
std
::
move
(
gl_surface
)
:
nullptr
;
surface
=
std
::
make_unique
<
AndroidSurfaceVulkan
>
();
#endif // SHELL_ENABLE_VULKAN
break
;
}
FML_CHECK
(
surface
);
return
surface
->
IsValid
()
?
std
::
move
(
surface
)
:
nullptr
;
;
}
AndroidSurface
::~
AndroidSurface
()
=
default
;
...
...
shell/platform/android/android_surface.h
浏览文件 @
fafccf8a
...
...
@@ -12,6 +12,7 @@
#include "flutter/fml/platform/android/jni_weak_ref.h"
#include "flutter/shell/common/platform_view.h"
#include "flutter/shell/common/surface.h"
#include "flutter/shell/platform/android/android_context.h"
#include "flutter/shell/platform/android/android_native_window.h"
#include "third_party/skia/include/core/SkSize.h"
...
...
@@ -19,7 +20,8 @@ namespace flutter {
class
AndroidSurface
{
public:
static
std
::
unique_ptr
<
AndroidSurface
>
Create
(
bool
use_software_rendering
);
static
std
::
unique_ptr
<
AndroidSurface
>
Create
(
std
::
shared_ptr
<
AndroidContext
>
android_context
);
virtual
~
AndroidSurface
();
...
...
@@ -27,9 +29,10 @@ class AndroidSurface {
virtual
void
TeardownOnScreenContext
()
=
0
;
virtual
std
::
unique_ptr
<
Surface
>
CreateGPUSurface
()
=
0
;
virtual
std
::
unique_ptr
<
Surface
>
CreateGPUSurface
(
GrContext
*
gr_context
=
nullptr
)
=
0
;
virtual
bool
OnScreenSurfaceResize
(
const
SkISize
&
size
)
const
=
0
;
virtual
bool
OnScreenSurfaceResize
(
const
SkISize
&
size
)
=
0
;
virtual
bool
ResourceContextMakeCurrent
()
=
0
;
...
...
shell/platform/android/android_surface_gl.cc
浏览文件 @
fafccf8a
...
...
@@ -11,120 +11,113 @@
namespace
flutter
{
static
fml
::
RefPtr
<
AndroidContextGL
>
CreateResourceLoadingContext
()
{
auto
environment
=
fml
::
MakeRefCounted
<
AndroidEnvironmentGL
>
();
if
(
!
environment
->
IsValid
())
{
return
nullptr
;
AndroidSurfaceGL
::
AndroidSurfaceGL
(
std
::
shared_ptr
<
AndroidContext
>
android_context
)
:
native_window_
(
nullptr
),
onscreen_surface_
(
nullptr
),
offscreen_surface_
(
nullptr
)
{
android_context_
=
std
::
static_pointer_cast
<
AndroidContextGL
>
(
android_context
);
// Acquire the offscreen surface.
offscreen_surface_
=
android_context_
->
CreateOffscreenSurface
();
if
(
offscreen_surface_
==
EGL_NO_SURFACE
)
{
offscreen_surface_
=
nullptr
;
}
auto
context
=
fml
::
MakeRefCounted
<
AndroidContextGL
>
(
environment
);
if
(
!
context
->
IsValid
())
{
return
nullptr
;
}
return
context
;
external_view_embedder_
=
std
::
make_unique
<
AndroidExternalViewEmbedder
>
();
}
AndroidSurfaceGL
::
AndroidSurfaceGL
()
{
// Acquire the offscreen context.
offscreen_context_
=
CreateResourceLoadingContext
();
if
(
!
offscreen_context_
||
!
offscreen_context_
->
IsValid
())
{
offscreen_context_
=
nullptr
;
AndroidSurfaceGL
::~
AndroidSurfaceGL
()
{
if
(
offscreen_surface_
)
{
android_context_
->
TeardownSurface
(
offscreen_surface_
);
offscreen_surface_
=
nullptr
;
}
if
(
onscreen_surface_
)
{
android_context_
->
TeardownSurface
(
onscreen_surface_
);
onscreen_surface_
=
nullptr
;
}
external_view_embedder_
=
std
::
make_unique
<
AndroidExternalViewEmbedder
>
();
}
AndroidSurfaceGL
::~
AndroidSurfaceGL
()
=
default
;
void
AndroidSurfaceGL
::
TeardownOnScreenContext
()
{
android_context_
->
ClearCurrent
();
}
bool
AndroidSurfaceGL
::
Is
OffscreenContext
Valid
()
const
{
return
offscreen_
context_
&&
offscreen
_context_
->
IsValid
();
bool
AndroidSurfaceGL
::
IsValid
()
const
{
return
offscreen_
surface_
&&
android
_context_
->
IsValid
();
}
void
AndroidSurfaceGL
::
TeardownOnScreenContext
()
{
if
(
onscreen_context_
)
{
onscreen_context_
->
ClearCurrent
();
std
::
unique_ptr
<
Surface
>
AndroidSurfaceGL
::
CreateGPUSurface
(
GrContext
*
gr_context
)
{
if
(
gr_context
)
{
return
std
::
make_unique
<
GPUSurfaceGL
>
(
sk_ref_sp
(
gr_context
),
this
,
true
);
}
onscreen_context_
=
nullptr
;
return
std
::
make_unique
<
GPUSurfaceGL
>
(
this
,
true
)
;
}
bool
AndroidSurfaceGL
::
IsValid
()
const
{
if
(
!
onscreen_context_
||
!
offscreen_context_
)
{
return
false
;
}
bool
AndroidSurfaceGL
::
OnScreenSurfaceResize
(
const
SkISize
&
size
)
{
FML_DCHECK
(
IsValid
());
FML_DCHECK
(
onscreen_surface_
)
;
FML_DCHECK
(
native_window_
);
return
onscreen_context_
->
IsValid
()
&&
offscreen_context_
->
IsValid
();
}
if
(
size
==
android_context_
->
GetSize
(
onscreen_surface_
))
{
return
true
;
}
std
::
unique_ptr
<
Surface
>
AndroidSurfaceGL
::
CreateGPUSurface
()
{
auto
surface
=
std
::
make_unique
<
GPUSurfaceGL
>
(
this
,
true
);
return
surface
->
IsValid
()
?
std
::
move
(
surface
)
:
nullptr
;
}
android_context_
->
ClearCurrent
();
android_context_
->
TeardownSurface
(
onscreen_surface_
);
bool
AndroidSurfaceGL
::
OnScreenSurfaceResize
(
const
SkISize
&
size
)
const
{
FML_DCHECK
(
onscreen_context_
&&
onscreen_context_
->
IsValid
());
return
onscreen_context_
->
Resize
(
size
);
onscreen_surface_
=
android_context_
->
CreateOnscreenSurface
(
native_window_
);
if
(
!
onscreen_surface_
||
onscreen_surface_
==
EGL_NO_SURFACE
)
{
FML_LOG
(
ERROR
)
<<
"Unable to create EGL window surface on resize."
;
return
false
;
}
android_context_
->
MakeCurrent
(
onscreen_surface_
);
return
true
;
}
bool
AndroidSurfaceGL
::
ResourceContextMakeCurrent
()
{
FML_DCHECK
(
offscreen_context_
&&
offscreen_context_
->
IsValid
());
return
offscreen_context_
->
MakeCurrent
(
);
FML_DCHECK
(
IsValid
());
return
android_context_
->
ResourceMakeCurrent
(
offscreen_surface_
);
}
bool
AndroidSurfaceGL
::
ResourceContextClearCurrent
()
{
FML_DCHECK
(
offscreen_context_
&&
offscreen_context_
->
IsValid
());
return
offscreen
_context_
->
ClearCurrent
();
FML_DCHECK
(
IsValid
());
return
android
_context_
->
ClearCurrent
();
}
bool
AndroidSurfaceGL
::
SetNativeWindow
(
fml
::
RefPtr
<
AndroidNativeWindow
>
window
)
{
// In any case, we want to get rid of our current onscreen context.
onscreen_context_
=
nullptr
;
//
If the offscreen context has not been setup, we dont have the sharegroup
.
// So bail.
if
(
!
offscreen_context_
||
!
offscreen_context_
->
IsValid
()
)
{
FML_DCHECK
(
IsValid
());
FML_DCHECK
(
window
)
;
native_window_
=
window
;
//
Create the onscreen surface
.
onscreen_surface_
=
android_context_
->
CreateOnscreenSurface
(
window
);
if
(
onscreen_surface_
==
EGL_NO_SURFACE
)
{
return
false
;
}
// Create the onscreen context.
onscreen_context_
=
fml
::
MakeRefCounted
<
AndroidContextGL
>
(
offscreen_context_
->
Environment
(),
offscreen_context_
.
get
()
/* sharegroup */
);
if
(
!
onscreen_context_
->
IsValid
())
{
onscreen_context_
=
nullptr
;
return
false
;
}
if
(
!
onscreen_context_
->
CreateWindowSurface
(
std
::
move
(
window
)))
{
onscreen_context_
=
nullptr
;
return
false
;
}
return
true
;
}
std
::
unique_ptr
<
GLContextResult
>
AndroidSurfaceGL
::
GLContextMakeCurrent
()
{
FML_DCHECK
(
onscreen_context_
&&
onscreen_context_
->
IsValid
());
FML_DCHECK
(
IsValid
());
FML_DCHECK
(
onscreen_surface_
);
auto
default_context_result
=
std
::
make_unique
<
GLContextDefaultResult
>
(
onscreen_context_
->
MakeCurrent
(
));
android_context_
->
MakeCurrent
(
onscreen_surface_
));
return
std
::
move
(
default_context_result
);
}
bool
AndroidSurfaceGL
::
GLContextClearCurrent
()
{
FML_DCHECK
(
onscreen_context_
&&
onscreen_context_
->
IsValid
());
return
onscreen
_context_
->
ClearCurrent
();
FML_DCHECK
(
IsValid
());
return
android
_context_
->
ClearCurrent
();
}
bool
AndroidSurfaceGL
::
GLContextPresent
()
{
FML_DCHECK
(
onscreen_context_
&&
onscreen_context_
->
IsValid
());
return
onscreen_context_
->
SwapBuffers
();
FML_DCHECK
(
IsValid
());
FML_DCHECK
(
onscreen_surface_
);
return
android_context_
->
SwapBuffers
(
onscreen_surface_
);
}
intptr_t
AndroidSurfaceGL
::
GLContextFBO
()
const
{
FML_DCHECK
(
onscreen_context_
&&
onscreen_context_
->
IsValid
());
FML_DCHECK
(
IsValid
());
// The default window bound framebuffer on Android.
return
0
;
}
...
...
shell/platform/android/android_surface_gl.h
浏览文件 @
fafccf8a
...
...
@@ -20,23 +20,21 @@ namespace flutter {
class
AndroidSurfaceGL
final
:
public
GPUSurfaceGLDelegate
,
public
AndroidSurface
{
public:
AndroidSurfaceGL
();
AndroidSurfaceGL
(
std
::
shared_ptr
<
AndroidContext
>
android_context
);
~
AndroidSurfaceGL
()
override
;
bool
IsOffscreenContextValid
()
const
;
// |AndroidSurface|
bool
IsValid
()
const
override
;
// |AndroidSurface|
std
::
unique_ptr
<
Surface
>
CreateGPUSurface
()
override
;
std
::
unique_ptr
<
Surface
>
CreateGPUSurface
(
GrContext
*
gr_context
)
override
;
// |AndroidSurface|
void
TeardownOnScreenContext
()
override
;
// |AndroidSurface|
bool
OnScreenSurfaceResize
(
const
SkISize
&
size
)
const
override
;
bool
OnScreenSurfaceResize
(
const
SkISize
&
size
)
override
;
// |AndroidSurface|
bool
ResourceContextMakeCurrent
()
override
;
...
...
@@ -63,9 +61,11 @@ class AndroidSurfaceGL final : public GPUSurfaceGLDelegate,
ExternalViewEmbedder
*
GetExternalViewEmbedder
()
override
;
private:
fml
::
RefPtr
<
AndroidContextGL
>
onscreen_context_
;
fml
::
RefPtr
<
AndroidContextGL
>
offscreen_context_
;
fml
::
RefPtr
<
AndroidNativeWindow
>
native_window_
;
std
::
unique_ptr
<
AndroidExternalViewEmbedder
>
external_view_embedder_
;
std
::
shared_ptr
<
AndroidContextGL
>
android_context_
;
EGLSurface
onscreen_surface_
;
EGLSurface
offscreen_surface_
;
FML_DISALLOW_COPY_AND_ASSIGN
(
AndroidSurfaceGL
);
};
...
...
shell/platform/android/android_surface_software.cc
浏览文件 @
fafccf8a
...
...
@@ -57,7 +57,8 @@ bool AndroidSurfaceSoftware::ResourceContextClearCurrent() {
return
false
;
}
std
::
unique_ptr
<
Surface
>
AndroidSurfaceSoftware
::
CreateGPUSurface
()
{
std
::
unique_ptr
<
Surface
>
AndroidSurfaceSoftware
::
CreateGPUSurface
(
GrContext
*
gr_context
)
{
if
(
!
IsValid
())
{
return
nullptr
;
}
...
...
@@ -143,7 +144,7 @@ ExternalViewEmbedder* AndroidSurfaceSoftware::GetExternalViewEmbedder() {
void
AndroidSurfaceSoftware
::
TeardownOnScreenContext
()
{}
bool
AndroidSurfaceSoftware
::
OnScreenSurfaceResize
(
const
SkISize
&
size
)
const
{
bool
AndroidSurfaceSoftware
::
OnScreenSurfaceResize
(
const
SkISize
&
size
)
{
return
true
;
}
...
...
shell/platform/android/android_surface_software.h
浏览文件 @
fafccf8a
...
...
@@ -31,13 +31,13 @@ class AndroidSurfaceSoftware final : public AndroidSurface,
bool
ResourceContextClearCurrent
()
override
;
// |AndroidSurface|
std
::
unique_ptr
<
Surface
>
CreateGPUSurface
()
override
;
std
::
unique_ptr
<
Surface
>
CreateGPUSurface
(
GrContext
*
gr_context
)
override
;
// |AndroidSurface|
void
TeardownOnScreenContext
()
override
;
// |AndroidSurface|
bool
OnScreenSurfaceResize
(
const
SkISize
&
size
)
const
override
;
bool
OnScreenSurfaceResize
(
const
SkISize
&
size
)
override
;
// |AndroidSurface|
bool
SetNativeWindow
(
fml
::
RefPtr
<
AndroidNativeWindow
>
window
)
override
;
...
...
shell/platform/android/android_surface_vulkan.cc
浏览文件 @
fafccf8a
...
...
@@ -27,7 +27,8 @@ void AndroidSurfaceVulkan::TeardownOnScreenContext() {
// Nothing to do.
}
std
::
unique_ptr
<
Surface
>
AndroidSurfaceVulkan
::
CreateGPUSurface
()
{
std
::
unique_ptr
<
Surface
>
AndroidSurfaceVulkan
::
CreateGPUSurface
(
GrContext
*
gr_context
)
{
if
(
!
IsValid
())
{
return
nullptr
;
}
...
...
@@ -54,7 +55,7 @@ std::unique_ptr<Surface> AndroidSurfaceVulkan::CreateGPUSurface() {
return
gpu_surface
;
}
bool
AndroidSurfaceVulkan
::
OnScreenSurfaceResize
(
const
SkISize
&
size
)
const
{
bool
AndroidSurfaceVulkan
::
OnScreenSurfaceResize
(
const
SkISize
&
size
)
{
return
true
;
}
...
...
shell/platform/android/android_surface_vulkan.h
浏览文件 @
fafccf8a
...
...
@@ -27,13 +27,13 @@ class AndroidSurfaceVulkan : public AndroidSurface,
bool
IsValid
()
const
override
;
// |AndroidSurface|
std
::
unique_ptr
<
Surface
>
CreateGPUSurface
()
override
;
std
::
unique_ptr
<
Surface
>
CreateGPUSurface
(
GrContext
*
gr_context
)
override
;
// |AndroidSurface|
void
TeardownOnScreenContext
()
override
;
// |AndroidSurface|
bool
OnScreenSurfaceResize
(
const
SkISize
&
size
)
const
override
;
bool
OnScreenSurfaceResize
(
const
SkISize
&
size
)
override
;
// |AndroidSurface|
bool
ResourceContextMakeCurrent
()
override
;
...
...
shell/platform/android/platform_view_android.cc
浏览文件 @
fafccf8a
...
...
@@ -10,6 +10,7 @@
#include "flutter/fml/synchronization/waitable_event.h"
#include "flutter/shell/common/shell_io_manager.h"
#include "flutter/shell/gpu/gpu_surface_gl_delegate.h"
#include "flutter/shell/platform/android/android_context.h"
#include "flutter/shell/platform/android/android_external_texture_gl.h"
#include "flutter/shell/platform/android/android_surface_gl.h"
#include "flutter/shell/platform/android/platform_message_response_android.h"
...
...
@@ -24,8 +25,18 @@ PlatformViewAndroid::PlatformViewAndroid(
fml
::
jni
::
JavaObjectWeakGlobalRef
java_object
,
bool
use_software_rendering
)
:
PlatformView
(
delegate
,
std
::
move
(
task_runners
)),
java_object_
(
java_object
),
android_surface_
(
AndroidSurface
::
Create
(
use_software_rendering
))
{
java_object_
(
java_object
)
{
std
::
shared_ptr
<
AndroidContext
>
android_context
;
if
(
use_software_rendering
)
{
android_context
=
AndroidContext
::
Create
(
AndroidRenderingAPI
::
kSoftware
);
}
else
{
#if SHELL_ENABLE_VULKAN
android_context
=
AndroidContext
::
Create
(
AndroidRenderingAPI
::
kVulkan
);
#else // SHELL_ENABLE_VULKAN
android_context
=
AndroidContext
::
Create
(
AndroidRenderingAPI
::
kOpenGLES
);
#endif // SHELL_ENABLE_VULKAN
}
android_surface_
=
AndroidSurface
::
Create
(
android_context
);
FML_CHECK
(
android_surface_
)
<<
"Could not create an OpenGL, Vulkan or Software surface to setup "
"rendering."
;
...
...
shell/platform/android/platform_view_android.h
浏览文件 @
fafccf8a
...
...
@@ -75,7 +75,8 @@ class PlatformViewAndroid final : public PlatformView {
private:
const
fml
::
jni
::
JavaObjectWeakGlobalRef
java_object_
;
const
std
::
unique_ptr
<
AndroidSurface
>
android_surface_
;
std
::
unique_ptr
<
AndroidSurface
>
android_surface_
;
// We use id 0 to mean that no response is expected.
int
next_response_id_
=
1
;
std
::
unordered_map
<
int
,
fml
::
RefPtr
<
flutter
::
PlatformMessageResponse
>>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录