Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
7418e7e
wait for platform view appear
Aug 27, 2019
ab43f55
Merge branch 'master' of github.com:flutter/engine
Sep 30, 2019
e360c9d
Merge branch 'master' of github.com:flutter/engine
Sep 30, 2019
49c9b60
Merge branch 'master' of github.com:flutter/engine
Sep 30, 2019
0f46ddf
merge upstream
Oct 1, 2019
0aff271
:wq!
Oct 10, 2019
7812602
Merge branch 'master' of github.com:flutter/engine
Oct 22, 2019
8cfcc3b
add ios gl manager
Oct 22, 2019
8fe6ae9
formatting
Oct 22, 2019
3106763
adde failure testing
Oct 23, 2019
e8a7fbf
update the guard to be a stack, and adding guards
Oct 24, 2019
8d24f66
don't save flutter context in guard
Oct 24, 2019
bc2616d
fix compiler error
Oct 24, 2019
15a8aa0
formatting
Oct 24, 2019
69f5bf0
some cleanup
Oct 24, 2019
fe7bdb8
comments
Oct 24, 2019
55f1191
formatting
Oct 24, 2019
86101eb
refactor
Oct 28, 2019
0bfaf25
mnake unique ptr
Oct 29, 2019
0b3f81a
working
Oct 29, 2019
c5dc118
some refactoring
Oct 29, 2019
c74dd07
more refactoring
Oct 29, 2019
fe6ad39
cleanup and formatting
Oct 29, 2019
cbd62c9
build fix
Oct 29, 2019
c40918f
formatting
Oct 29, 2019
afb1d0b
Merge branch 'master' of github.com:flutter/engine
Oct 29, 2019
89760df
merge master
Oct 29, 2019
4d78083
remove testing scheme
Oct 29, 2019
2cbbb5d
fix android build
Oct 29, 2019
7f425aa
formatting
Oct 29, 2019
266a036
revert scheme setting
Oct 29, 2019
3357f70
fix license file
Oct 29, 2019
83f78f3
more license file fix
Oct 29, 2019
297e825
OOL
Oct 30, 2019
4d4e50b
more ool defination
Oct 30, 2019
9b4fe94
doxygen
Oct 30, 2019
df02e9b
remove unnnecessary includes
Oct 30, 2019
61b428e
remove unnecessary cast
Oct 31, 2019
9a9cb76
Merge branch 'master' into gl
Nov 7, 2019
f5208f2
Update platform_view.dart
Nov 7, 2019
55eba45
fix ci
Nov 8, 2019
1cc9477
ignore gl context switching in platform views with software rendering
Nov 8, 2019
7b684d4
remove test logs
Nov 8, 2019
6e1b9d4
rename
Nov 9, 2019
cade4b3
formatting
Nov 9, 2019
7542129
formatting
Nov 9, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,8 @@ FILE: ../../../flutter/shell/common/pointer_data_dispatcher.cc
FILE: ../../../flutter/shell/common/pointer_data_dispatcher.h
FILE: ../../../flutter/shell/common/rasterizer.cc
FILE: ../../../flutter/shell/common/rasterizer.h
FILE: ../../../flutter/shell/common/renderer_context_switch_manager.cc
FILE: ../../../flutter/shell/common/renderer_context_switch_manager.h
FILE: ../../../flutter/shell/common/run_configuration.cc
FILE: ../../../flutter/shell/common/run_configuration.h
FILE: ../../../flutter/shell/common/shell.cc
Expand Down Expand Up @@ -799,6 +801,8 @@ FILE: ../../../flutter/shell/platform/darwin/ios/ios_external_texture_gl.h
FILE: ../../../flutter/shell/platform/darwin/ios/ios_external_texture_gl.mm
FILE: ../../../flutter/shell/platform/darwin/ios/ios_gl_context.h
FILE: ../../../flutter/shell/platform/darwin/ios/ios_gl_context.mm
FILE: ../../../flutter/shell/platform/darwin/ios/ios_gl_context_switch_manager.h
FILE: ../../../flutter/shell/platform/darwin/ios/ios_gl_context_switch_manager.mm
FILE: ../../../flutter/shell/platform/darwin/ios/ios_gl_render_target.h
FILE: ../../../flutter/shell/platform/darwin/ios/ios_gl_render_target.mm
FILE: ../../../flutter/shell/platform/darwin/ios/ios_surface.h
Expand Down
2 changes: 2 additions & 0 deletions shell/common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ source_set("common") {
"pointer_data_dispatcher.h",
"rasterizer.cc",
"rasterizer.h",
"renderer_context_switch_manager.cc",
"renderer_context_switch_manager.h",
"run_configuration.cc",
"run_configuration.h",
"shell.cc",
Expand Down
4 changes: 3 additions & 1 deletion shell/common/rasterizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ sk_sp<SkImage> Rasterizer::MakeRasterSnapshot(sk_sp<SkPicture> picture,
// happen in case of software rendering.
surface = SkSurface::MakeRaster(image_info);
} else {
if (!surface_->MakeRenderContextCurrent()) {
std::unique_ptr<RendererContextSwitchManager::RendererContextSwitch>
context_switch = surface_->MakeRenderContextCurrent();
if (context_switch->GetSwitchResult()) {
return nullptr;
}

Expand Down
30 changes: 30 additions & 0 deletions shell/common/renderer_context_switch_manager.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// 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 "renderer_context_switch_manager.h"

namespace flutter {

RendererContextSwitchManager::RendererContextSwitchManager() = default;

RendererContextSwitchManager::~RendererContextSwitchManager() = default;

RendererContextSwitchManager::RendererContextSwitch::RendererContextSwitch() =
default;

RendererContextSwitchManager::RendererContextSwitch::~RendererContextSwitch(){};

RendererContextSwitchManager::RendererContextSwitchPureResult::
RendererContextSwitchPureResult(bool switch_result)
: switch_result_(switch_result){};

RendererContextSwitchManager::RendererContextSwitchPureResult::
~RendererContextSwitchPureResult() = default;

bool RendererContextSwitchManager::RendererContextSwitchPureResult::
GetSwitchResult() {
return switch_result_;
}

} // namespace flutter
116 changes: 116 additions & 0 deletions shell/common/renderer_context_switch_manager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
// 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_COMMON_GL_CONTEXT_SWITCH_MANAGER_H_
#define FLUTTER_SHELL_COMMON_GL_CONTEXT_SWITCH_MANAGER_H_

#include <memory>
#include "flutter/fml/macros.h"

namespace flutter {

//------------------------------------------------------------------------------
/// Manages `RendererContextSwitch`.
///
/// Should be subclassed for platforms that uses GL and requires context
/// switching. Always use `MakeCurrent` and `ResourceMakeCurrent` in the
/// `RendererContextSwitchManager` to set gl contexts.
///
class RendererContextSwitchManager {
public:
//------------------------------------------------------------------------------
/// Switches the gl context to the flutter's contexts.
///
/// Should be subclassed for each platform embedder that uses GL.
/// In construction, it should set the current context to a flutter's context
/// In destruction, it should rest the current context.
///
class RendererContextSwitch {
public:
RendererContextSwitch();

virtual ~RendererContextSwitch();

virtual bool GetSwitchResult() = 0;

FML_DISALLOW_COPY_AND_ASSIGN(RendererContextSwitch);
};

RendererContextSwitchManager();
~RendererContextSwitchManager();

//----------------------------------------------------------------------------
/// @brief Creates a shell instance using the provided settings. The
/// callbacks to create the various shell subcomponents will be
/// called on the appropriate threads before this method returns.
/// If this is the first instance of a shell in the process, this
/// call also bootstraps the Dart VM.
///
/// @param[in] task_runners The task runners
/// @param[in] settings The settings
/// @param[in] on_create_platform_view The callback that must return a
/// platform view. This will be called on
/// the platform task runner before this
/// method returns.
/// @param[in] on_create_rasterizer That callback that must provide a
/// valid rasterizer. This will be called
/// on the render task runner before this
/// method returns.
///
/// @return A full initialized shell if the settings and callbacks are
/// valid. The root isolate has been created but not yet launched.
/// It may be launched by obtaining the engine weak pointer and
/// posting a task onto the UI task runner with a valid run
/// configuration to run the isolate. The embedder must always
/// check the validity of the shell (using the IsSetup call)
/// immediately after getting a pointer to it.
///

//----------------------------------------------------------------------------
/// @brief Make the flutter's context as current context.
///
/// @return A `RendererContextSwitch` with `GetSwitchResult` returning
/// true if the setting process is succesful.
virtual std::unique_ptr<RendererContextSwitch> MakeCurrent() = 0;

//----------------------------------------------------------------------------
/// @brief Make the flutter's resources context as current context.
///
/// @return A `RendererContextSwitch` with `GetSwitchResult` returning
/// true if the setting process is succesful.
virtual std::unique_ptr<RendererContextSwitch> ResourceMakeCurrent() = 0;

//------------------------------------------------------------------------------
/// A representation of a `RendererContextSwitch` that doesn't require actual
/// context switching.
///
class RendererContextSwitchPureResult final : public RendererContextSwitch {
public:
// Constructor that creates an `RendererContextSwitchPureResult`.
// The `GetSwitchResult` will return the same value as `switch_result`.

//----------------------------------------------------------------------------
/// @brief Constructs a `RendererContextSwitchPureResult`.
///
/// @param[in] switch_result the switch result that will be returned
/// in `GetSwitchResult()`
///
RendererContextSwitchPureResult(bool switch_result);

~RendererContextSwitchPureResult();

bool GetSwitchResult() override;

private:
bool switch_result_;

FML_DISALLOW_COPY_AND_ASSIGN(RendererContextSwitchPureResult);
};

FML_DISALLOW_COPY_AND_ASSIGN(RendererContextSwitchManager);
};

} // namespace flutter

#endif
12 changes: 10 additions & 2 deletions shell/common/shell_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,11 @@ PointerDataDispatcherMaker ShellTestPlatformView::GetDispatcherMaker() {
}

// |GPUSurfaceGLDelegate|
bool ShellTestPlatformView::GLContextMakeCurrent() {
return gl_surface_.MakeCurrent();
std::unique_ptr<RendererContextSwitchManager::RendererContextSwitch>
ShellTestPlatformView::GLContextMakeCurrent() {
return std::make_unique<
RendererContextSwitchManager::RendererContextSwitchPureResult>(
gl_surface_.MakeCurrent());
}

// |GPUSurfaceGLDelegate|
Expand Down Expand Up @@ -387,5 +390,10 @@ ExternalViewEmbedder* ShellTestPlatformView::GetExternalViewEmbedder() {
return nullptr;
}

std::shared_ptr<RendererContextSwitchManager>
ShellTestPlatformView::GetRendererContextSwitchManager() {
return nullptr;
}

} // namespace testing
} // namespace flutter
6 changes: 5 additions & 1 deletion shell/common/shell_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ class ShellTestPlatformView : public PlatformView, public GPUSurfaceGLDelegate {
PointerDataDispatcherMaker GetDispatcherMaker() override;

// |GPUSurfaceGLDelegate|
bool GLContextMakeCurrent() override;
std::unique_ptr<RendererContextSwitchManager::RendererContextSwitch>
GLContextMakeCurrent() override;

// |GPUSurfaceGLDelegate|
bool GLContextClearCurrent() override;
Expand All @@ -161,6 +162,9 @@ class ShellTestPlatformView : public PlatformView, public GPUSurfaceGLDelegate {
// |GPUSurfaceGLDelegate|
ExternalViewEmbedder* GetExternalViewEmbedder() override;

std::shared_ptr<RendererContextSwitchManager>
GetRendererContextSwitchManager() override;

FML_DISALLOW_COPY_AND_ASSIGN(ShellTestPlatformView);
};

Expand Down
6 changes: 4 additions & 2 deletions shell/common/surface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ flutter::ExternalViewEmbedder* Surface::GetExternalViewEmbedder() {
return nullptr;
}

bool Surface::MakeRenderContextCurrent() {
return true;
std::unique_ptr<RendererContextSwitchManager::RendererContextSwitch>
Surface::MakeRenderContextCurrent() {
return std::make_unique<
RendererContextSwitchManager::RendererContextSwitchPureResult>(true);
}

} // namespace flutter
4 changes: 3 additions & 1 deletion shell/common/surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "flutter/flow/compositor_context.h"
#include "flutter/flow/embedded_views.h"
#include "flutter/fml/macros.h"
#include "flutter/shell/common/renderer_context_switch_manager.h"
#include "third_party/skia/include/core/SkCanvas.h"

namespace flutter {
Expand Down Expand Up @@ -58,7 +59,8 @@ class Surface {

virtual flutter::ExternalViewEmbedder* GetExternalViewEmbedder();

virtual bool MakeRenderContextCurrent();
virtual std::unique_ptr<RendererContextSwitchManager::RendererContextSwitch>
MakeRenderContextCurrent();

private:
FML_DISALLOW_COPY_AND_ASSIGN(Surface);
Expand Down
33 changes: 21 additions & 12 deletions shell/gpu/gpu_surface_gl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "flutter/fml/size.h"
#include "flutter/fml/trace_event.h"
#include "flutter/shell/common/persistent_cache.h"
#include "flutter/shell/common/renderer_context_switch_manager.h"
#include "third_party/skia/include/core/SkColorFilter.h"
#include "third_party/skia/include/core/SkSurface.h"
#include "third_party/skia/include/gpu/GrBackendSurface.h"
Expand Down Expand Up @@ -39,7 +40,10 @@ GPUSurfaceGL::GPUSurfaceGL(GPUSurfaceGLDelegate* delegate,
: delegate_(delegate),
render_to_surface_(render_to_surface),
weak_factory_(this) {
if (!delegate_->GLContextMakeCurrent()) {
std::unique_ptr<RendererContextSwitchManager::RendererContextSwitch>
context_switch = delegate_->GLContextMakeCurrent();

if (!context_switch->GetSwitchResult()) {
FML_LOG(ERROR)
<< "Could not make the context current to setup the gr context.";
return;
Expand Down Expand Up @@ -87,8 +91,6 @@ GPUSurfaceGL::GPUSurfaceGL(GPUSurfaceGLDelegate* delegate,
}
FML_LOG(INFO) << "Found " << caches.size() << " SkSL shaders; precompiled "
<< compiled_count;

delegate_->GLContextClearCurrent();
}

GPUSurfaceGL::GPUSurfaceGL(sk_sp<GrContext> gr_context,
Expand All @@ -98,7 +100,9 @@ GPUSurfaceGL::GPUSurfaceGL(sk_sp<GrContext> gr_context,
context_(gr_context),
render_to_surface_(render_to_surface),
weak_factory_(this) {
if (!delegate_->GLContextMakeCurrent()) {
std::unique_ptr<RendererContextSwitchManager::RendererContextSwitch>
context_switch = delegate_->GLContextMakeCurrent();
if (!context_switch->GetSwitchResult()) {
FML_LOG(ERROR)
<< "Could not make the context current to setup the gr context.";
return;
Expand All @@ -114,8 +118,9 @@ GPUSurfaceGL::~GPUSurfaceGL() {
if (!valid_) {
return;
}

if (!delegate_->GLContextMakeCurrent()) {
std::unique_ptr<RendererContextSwitchManager::RendererContextSwitch>
context_switch = delegate_->GLContextMakeCurrent();
if (!context_switch->GetSwitchResult()) {
FML_LOG(ERROR) << "Could not make the context current to destroy the "
"GrContext resources.";
return;
Expand All @@ -126,8 +131,6 @@ GPUSurfaceGL::~GPUSurfaceGL() {
context_->releaseResourcesAndAbandonContext();
}
context_ = nullptr;

delegate_->GLContextClearCurrent();
}

// |Surface|
Expand Down Expand Up @@ -253,7 +256,9 @@ std::unique_ptr<SurfaceFrame> GPUSurfaceGL::AcquireFrame(const SkISize& size) {
return nullptr;
}

if (!delegate_->GLContextMakeCurrent()) {
std::unique_ptr<RendererContextSwitchManager::RendererContextSwitch>
context_switch = delegate_->GLContextMakeCurrent();
if (!context_switch->GetSwitchResult()) {
FML_LOG(ERROR)
<< "Could not make the context current to acquire the frame.";
return nullptr;
Expand Down Expand Up @@ -285,14 +290,18 @@ std::unique_ptr<SurfaceFrame> GPUSurfaceGL::AcquireFrame(const SkISize& size) {
return weak ? weak->PresentSurface(canvas) : false;
};

return std::make_unique<SurfaceFrame>(surface, submit_callback);
std::unique_ptr<SurfaceFrame> result =
std::make_unique<SurfaceFrame>(surface, submit_callback);
return result;
}

bool GPUSurfaceGL::PresentSurface(SkCanvas* canvas) {
if (delegate_ == nullptr || canvas == nullptr || context_ == nullptr) {
return false;
}

std::unique_ptr<RendererContextSwitchManager::RendererContextSwitch>
context_switch = delegate_->GLContextMakeCurrent();
if (offscreen_surface_ != nullptr) {
TRACE_EVENT0("flutter", "CopyTextureOnscreen");
SkPaint paint;
Expand Down Expand Up @@ -329,7 +338,6 @@ bool GPUSurfaceGL::PresentSurface(SkCanvas* canvas) {

onscreen_surface_ = std::move(new_onscreen_surface);
}

return true;
}

Expand Down Expand Up @@ -360,7 +368,8 @@ flutter::ExternalViewEmbedder* GPUSurfaceGL::GetExternalViewEmbedder() {
}

// |Surface|
bool GPUSurfaceGL::MakeRenderContextCurrent() {
std::unique_ptr<RendererContextSwitchManager::RendererContextSwitch>
GPUSurfaceGL::MakeRenderContextCurrent() {
return delegate_->GLContextMakeCurrent();
}

Expand Down
3 changes: 2 additions & 1 deletion shell/gpu/gpu_surface_gl.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class GPUSurfaceGL : public Surface {
flutter::ExternalViewEmbedder* GetExternalViewEmbedder() override;

// |Surface|
bool MakeRenderContextCurrent() override;
std::unique_ptr<RendererContextSwitchManager::RendererContextSwitch>
MakeRenderContextCurrent() override;

private:
GPUSurfaceGLDelegate* delegate_;
Expand Down
Loading