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)
63 lines
1.6 KiB
Objective-C
63 lines
1.6 KiB
Objective-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 FLUTTER_SHELL_GPU_GPU_SURFACE_METAL_H_
|
|
#define FLUTTER_SHELL_GPU_GPU_SURFACE_METAL_H_
|
|
|
|
#include <Metal/Metal.h>
|
|
|
|
#include "flutter/fml/macros.h"
|
|
#include "flutter/fml/platform/darwin/scoped_nsobject.h"
|
|
#include "flutter/shell/common/surface.h"
|
|
#include "flutter/shell/gpu/gpu_surface_delegate.h"
|
|
#include "third_party/skia/include/gpu/GrContext.h"
|
|
|
|
@class CAMetalLayer;
|
|
|
|
namespace flutter {
|
|
|
|
class GPUSurfaceMetal : public Surface {
|
|
public:
|
|
GPUSurfaceMetal(GPUSurfaceDelegate* delegate,
|
|
fml::scoped_nsobject<CAMetalLayer> layer,
|
|
sk_sp<GrContext> context,
|
|
fml::scoped_nsprotocol<id<MTLCommandQueue>> command_queue);
|
|
|
|
// |Surface|
|
|
~GPUSurfaceMetal() override;
|
|
|
|
private:
|
|
GPUSurfaceDelegate* delegate_;
|
|
fml::scoped_nsobject<CAMetalLayer> layer_;
|
|
sk_sp<GrContext> context_;
|
|
fml::scoped_nsprotocol<id<MTLCommandQueue>> command_queue_;
|
|
GrMTLHandle next_drawable_ = nullptr;
|
|
|
|
// |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;
|
|
|
|
void ReleaseUnusedDrawableIfNecessary();
|
|
|
|
FML_DISALLOW_COPY_AND_ASSIGN(GPUSurfaceMetal);
|
|
};
|
|
|
|
} // namespace flutter
|
|
|
|
#endif // FLUTTER_SHELL_GPU_GPU_SURFACE_METAL_H_
|