mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Explicitly tell the platform view to update its backing store. (flutter/engine#3181)
This commit is contained in:
parent
b5219d5dcf
commit
dd6331d3ad
@ -14,11 +14,11 @@
|
||||
#include "flutter/shell/gpu/gpu_surface_gl.h"
|
||||
#include "flutter/shell/platform/darwin/common/platform_mac.h"
|
||||
#include "flutter/shell/platform/darwin/common/string_conversions.h"
|
||||
#include "flutter/shell/platform/darwin/ios/framework/Source/flutter_touch_mapper.h"
|
||||
#include "flutter/shell/platform/darwin/ios/framework/Source/FlutterDartProject_Internal.h"
|
||||
#include "flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.h"
|
||||
#include "flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputDelegate.h"
|
||||
#include "flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.h"
|
||||
#include "flutter/shell/platform/darwin/ios/framework/Source/flutter_touch_mapper.h"
|
||||
#include "flutter/shell/platform/darwin/ios/platform_view_ios.h"
|
||||
#include "lib/ftl/functional/make_copyable.h"
|
||||
#include "lib/ftl/time/time_delta.h"
|
||||
@ -330,10 +330,13 @@ static inline PointerChangeMapperPhase PointerChangePhaseFromUITouchPhase(
|
||||
|
||||
- (void)updateViewportMetrics {
|
||||
blink::Threads::UI()->PostTask([
|
||||
engine = _platformView->engine().GetWeakPtr(), metrics = _viewportMetrics
|
||||
weak_platform_view = _platformView->GetWeakPtr(), metrics = _viewportMetrics
|
||||
] {
|
||||
if (engine.get())
|
||||
engine->SetViewportMetrics(metrics);
|
||||
if (!weak_platform_view) {
|
||||
return;
|
||||
}
|
||||
weak_platform_view->UpdateSurfaceSize();
|
||||
weak_platform_view->engine().SetViewportMetrics(metrics);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -38,6 +38,10 @@ class PlatformViewIOS : public PlatformView, public GPUSurfaceGLDelegate {
|
||||
return platform_message_router_;
|
||||
}
|
||||
|
||||
ftl::WeakPtr<PlatformViewIOS> GetWeakPtr();
|
||||
|
||||
void UpdateSurfaceSize();
|
||||
|
||||
VsyncWaiter* GetVsyncWaiter() override;
|
||||
|
||||
bool ResourceContextMakeCurrent() override;
|
||||
@ -64,6 +68,7 @@ class PlatformViewIOS : public PlatformView, public GPUSurfaceGLDelegate {
|
||||
sky::SkyEnginePtr engine_;
|
||||
PlatformMessageRouter platform_message_router_;
|
||||
std::unique_ptr<AccessibilityBridge> accessibility_bridge_;
|
||||
ftl::WeakPtrFactory<PlatformViewIOS> weak_factory_;
|
||||
|
||||
void SetupAndLoadFromSource(const std::string& main,
|
||||
const std::string& packages,
|
||||
|
||||
@ -3,16 +3,14 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "flutter/shell/platform/darwin/ios/platform_view_ios.h"
|
||||
|
||||
#import <OpenGLES/EAGL.h>
|
||||
#import <OpenGLES/ES2/gl.h>
|
||||
#import <OpenGLES/ES2/glext.h>
|
||||
#import <QuartzCore/CAEAGLLayer.h>
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "base/mac/scoped_nsautorelease_pool.h"
|
||||
#include "base/trace_event/trace_event.h"
|
||||
#include "flutter/common/threads.h"
|
||||
#include "flutter/shell/gpu/gpu_rasterizer.h"
|
||||
#include "flutter/shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.h"
|
||||
#include "lib/ftl/synchronization/waitable_event.h"
|
||||
@ -170,32 +168,6 @@ class IOSGLContext {
|
||||
|
||||
GLuint framebuffer() const { return framebuffer_; }
|
||||
|
||||
bool MakeCurrent() {
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
|
||||
return UpdateStorageSizeIfNecessary() &&
|
||||
[EAGLContext setCurrentContext:context_.get()];
|
||||
}
|
||||
|
||||
bool ResourceMakeCurrent() {
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
|
||||
return [EAGLContext setCurrentContext:resource_context_.get()];
|
||||
}
|
||||
|
||||
private:
|
||||
base::scoped_nsobject<CAEAGLLayer> layer_;
|
||||
base::scoped_nsobject<EAGLContext> context_;
|
||||
base::scoped_nsobject<EAGLContext> resource_context_;
|
||||
|
||||
GLuint framebuffer_;
|
||||
GLuint colorbuffer_;
|
||||
GLuint depthbuffer_;
|
||||
GLuint stencilbuffer_;
|
||||
GLuint depth_stencil_packed_buffer_;
|
||||
|
||||
GLintSize storage_size_;
|
||||
|
||||
bool UpdateStorageSizeIfNecessary() {
|
||||
GLintSize size([layer_.get() bounds].size);
|
||||
|
||||
@ -270,12 +242,37 @@ class IOSGLContext {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MakeCurrent() {
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
|
||||
return UpdateStorageSizeIfNecessary() &&
|
||||
[EAGLContext setCurrentContext:context_.get()];
|
||||
}
|
||||
|
||||
bool ResourceMakeCurrent() {
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
|
||||
return [EAGLContext setCurrentContext:resource_context_.get()];
|
||||
}
|
||||
|
||||
private:
|
||||
base::scoped_nsobject<CAEAGLLayer> layer_;
|
||||
base::scoped_nsobject<EAGLContext> context_;
|
||||
base::scoped_nsobject<EAGLContext> resource_context_;
|
||||
GLuint framebuffer_;
|
||||
GLuint colorbuffer_;
|
||||
GLuint depthbuffer_;
|
||||
GLuint stencilbuffer_;
|
||||
GLuint depth_stencil_packed_buffer_;
|
||||
GLintSize storage_size_;
|
||||
|
||||
FTL_DISALLOW_COPY_AND_ASSIGN(IOSGLContext);
|
||||
};
|
||||
|
||||
PlatformViewIOS::PlatformViewIOS(CAEAGLLayer* layer)
|
||||
: PlatformView(std::make_unique<GPURasterizer>()),
|
||||
context_(std::make_unique<IOSGLContext>(surface_config_, layer)) {
|
||||
context_(std::make_unique<IOSGLContext>(surface_config_, layer)),
|
||||
weak_factory_(this) {
|
||||
CreateEngine();
|
||||
|
||||
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
|
||||
@ -313,6 +310,18 @@ void PlatformViewIOS::SetupAndLoadFromSource(
|
||||
engine_->RunFromFile(main, packages, assets_directory);
|
||||
}
|
||||
|
||||
ftl::WeakPtr<PlatformViewIOS> PlatformViewIOS::GetWeakPtr() {
|
||||
return weak_factory_.GetWeakPtr();
|
||||
}
|
||||
|
||||
void PlatformViewIOS::UpdateSurfaceSize() {
|
||||
blink::Threads::Gpu()->PostTask([self = GetWeakPtr()]() {
|
||||
if (self && self->context_ != nullptr) {
|
||||
self->context_->UpdateStorageSizeIfNecessary();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
VsyncWaiter* PlatformViewIOS::GetVsyncWaiter() {
|
||||
if (!vsync_waiter_)
|
||||
vsync_waiter_ = std::make_unique<VsyncWaiterIOS>();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user