mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
This moves the Metal `GrContext` creation utilities from `GPUSurfaceMetal` into a separate `IOSContext` object subclass. An analogue of this object was used in the GL regime for the management of onscreen and offscreen contexts that were not tied to the lifecycle of the `GPUSurface`. This pattern has now been generalized for use with all backends that need a resource context (`IOSContextGL` and `IOContextMetal`). The platform views controller management in the `ExternalViewEmbedder` interface implementation was repeated three times for [Metal][metal], [OpenGL](opengl) and [Software](software) rendering. This repetition has been removed and a single implementation present in the base `IOSSurface` and used on all platforms. Addition of new client rendering APIs should not affect how the engine renders into the platform view interleaving levels. All rendering API selection logic has been moved into a single set of utilities in `rendering_api_selection.h`. This enables the removal of a lot of code blocks guarded by `FLUTTER_SHELL_ENABLE_METAL`. The remaining uses of this will be removed when unified builds are enabled. The Metal backend now also adds traces similar to the GL backend. The `IOGLContext` has been renamed to `IOContextGL` to be more in line with the convention used in this library. Fixes https://github.com/flutter/flutter/issues/41827 Adds https://github.com/flutter/flutter/issues/52150 [metal]:1194ba2b21/shell/platform/darwin/ios/ios_surface_metal.mm (L55)[opengl]:1194ba2b21/shell/platform/darwin/ios/ios_surface_gl.mm (L95)[software]:1194ba2b21/shell/platform/darwin/ios/ios_surface_software.mm (L146)
77 lines
2.1 KiB
C++
77 lines
2.1 KiB
C++
// 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 SHELL_GPU_GPU_SURFACE_GL_H_
|
|
#define SHELL_GPU_GPU_SURFACE_GL_H_
|
|
|
|
#include <functional>
|
|
#include <memory>
|
|
|
|
#include "flutter/flow/embedded_views.h"
|
|
#include "flutter/fml/macros.h"
|
|
#include "flutter/fml/memory/weak_ptr.h"
|
|
#include "flutter/shell/common/surface.h"
|
|
#include "flutter/shell/gpu/gpu_surface_gl_delegate.h"
|
|
#include "third_party/skia/include/gpu/GrContext.h"
|
|
|
|
namespace flutter {
|
|
|
|
class GPUSurfaceGL : public Surface {
|
|
public:
|
|
GPUSurfaceGL(GPUSurfaceGLDelegate* delegate, bool render_to_surface);
|
|
|
|
// Creates a new GL surface reusing an existing GrContext.
|
|
GPUSurfaceGL(sk_sp<GrContext> gr_context,
|
|
GPUSurfaceGLDelegate* delegate,
|
|
bool render_to_surface);
|
|
|
|
// |Surface|
|
|
~GPUSurfaceGL() override;
|
|
|
|
// |Surface|
|
|
bool IsValid() override;
|
|
|
|
// |Surface|
|
|
std::unique_ptr<SurfaceFrame> AcquireFrame(const SkISize& size) override;
|
|
|
|
// |Surface|
|
|
SkMatrix GetRootTransformation() const override;
|
|
|
|
// |Surface|
|
|
GrContext* GetContext() override;
|
|
|
|
// |Surface|
|
|
flutter::ExternalViewEmbedder* GetExternalViewEmbedder() override;
|
|
|
|
// |Surface|
|
|
bool MakeRenderContextCurrent() override;
|
|
|
|
private:
|
|
GPUSurfaceGLDelegate* delegate_;
|
|
sk_sp<GrContext> context_;
|
|
sk_sp<SkSurface> onscreen_surface_;
|
|
bool context_owner_;
|
|
// TODO(38466): Refactor GPU surface APIs take into account the fact that an
|
|
// external view embedder may want to render to the root surface. This is a
|
|
// hack to make avoid allocating resources for the root surface when an
|
|
// external view embedder is present.
|
|
const bool render_to_surface_;
|
|
bool valid_ = false;
|
|
fml::WeakPtrFactory<GPUSurfaceGL> weak_factory_;
|
|
|
|
bool CreateOrUpdateSurfaces(const SkISize& size);
|
|
|
|
sk_sp<SkSurface> AcquireRenderSurface(
|
|
const SkISize& untransformed_size,
|
|
const SkMatrix& root_surface_transformation);
|
|
|
|
bool PresentSurface(SkCanvas* canvas);
|
|
|
|
FML_DISALLOW_COPY_AND_ASSIGN(GPUSurfaceGL);
|
|
};
|
|
|
|
} // namespace flutter
|
|
|
|
#endif // SHELL_GPU_GPU_SURFACE_GL_H_
|