-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reland "Introduce a delegate class for gpu metal rendering (#22611)" #22777
Merged
+498
−158
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// 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/gpu/gpu_surface_metal_delegate.h" | ||
|
||
namespace flutter { | ||
|
||
GPUSurfaceMetalDelegate::GPUSurfaceMetalDelegate( | ||
MTLRenderTargetType render_target_type) | ||
: render_target_type_(render_target_type) {} | ||
|
||
GPUSurfaceMetalDelegate::~GPUSurfaceMetalDelegate() = default; | ||
|
||
MTLRenderTargetType GPUSurfaceMetalDelegate::GetRenderTargetType() { | ||
return render_target_type_; | ||
} | ||
|
||
} // namespace flutter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// 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_DELEGATE_H_ | ||
#define FLUTTER_SHELL_GPU_GPU_SURFACE_METAL_DELEGATE_H_ | ||
|
||
#include <stdint.h> | ||
|
||
#include "flutter/fml/macros.h" | ||
#include "third_party/skia/include/core/SkSize.h" | ||
#include "third_party/skia/include/core/SkSurface.h" | ||
#include "third_party/skia/include/gpu/mtl/GrMtlTypes.h" | ||
|
||
namespace flutter { | ||
|
||
// expected to be id<MTLDevice> | ||
typedef void* GPUMTLDeviceHandle; | ||
|
||
// expected to be id<MTLCommandQueues> | ||
typedef void* GPUMTLCommandQueueHandle; | ||
|
||
// expected to be CAMetalLayer* | ||
typedef void* GPUCAMetalLayerHandle; | ||
|
||
// expected to be id<MTLTexture> | ||
typedef void* GPUMTLTextureHandle; | ||
|
||
struct GPUMTLTextureInfo { | ||
intptr_t texture_id; | ||
GPUMTLTextureHandle texture; | ||
}; | ||
|
||
enum class MTLRenderTargetType { kMTLTexture, kCAMetalLayer }; | ||
|
||
//------------------------------------------------------------------------------ | ||
/// @brief Interface implemented by all platform surfaces that can present | ||
/// a metal backing store to the "screen". The GPU surface | ||
/// abstraction (which abstracts the client rendering API) uses this | ||
/// delegation pattern to tell the platform surface (which abstracts | ||
/// how backing stores fulfilled by the selected client rendering | ||
/// API end up on the "screen" on a particular platform) when the | ||
/// rasterizer needs to allocate and present the software backing | ||
/// store. | ||
/// | ||
/// @see |IOSurfaceMetal| and |EmbedderSurfaceMetal|. | ||
/// | ||
class GPUSurfaceMetalDelegate { | ||
public: | ||
//------------------------------------------------------------------------------ | ||
/// @brief Construct a new GPUSurfaceMetalDelegate object with the specified | ||
/// render_target type. | ||
/// | ||
/// @see |MTLRenderTargetType| | ||
/// | ||
explicit GPUSurfaceMetalDelegate(MTLRenderTargetType render_target); | ||
|
||
virtual ~GPUSurfaceMetalDelegate(); | ||
|
||
//------------------------------------------------------------------------------ | ||
/// @brief Returns the handle to the CAMetalLayer to render to. This is only | ||
/// called when the specifed render target type is `kCAMetalLayer`. | ||
/// | ||
virtual GPUCAMetalLayerHandle GetCAMetalLayer( | ||
const SkISize& frame_info) const = 0; | ||
|
||
//------------------------------------------------------------------------------ | ||
/// @brief Presents the drawable to the "screen". The drawable is obtained | ||
/// from the CAMetalLayer that given by `GetCAMetalLayer` call. This is only | ||
/// called when the specified render target type in `kCAMetalLayer`. | ||
/// | ||
/// @see |GPUSurfaceMetalDelegate::GetCAMetalLayer| | ||
/// | ||
virtual bool PresentDrawable(GrMTLHandle drawable) const = 0; | ||
|
||
//------------------------------------------------------------------------------ | ||
/// @brief Returns the handle to the MTLTexture to render to. This is only | ||
/// called when the specefied render target type is `kMTLTexture`. | ||
/// | ||
virtual GPUMTLTextureInfo GetMTLTexture(const SkISize& frame_info) const = 0; | ||
|
||
//------------------------------------------------------------------------------ | ||
/// @brief Presents the texture with `texture_id` to the "screen". | ||
/// `texture_id` corresponds to a texture that has been obtained by an earlier | ||
/// call to `GetMTLTexture`. This is only called when the specefied render | ||
/// target type is `kMTLTexture`. | ||
/// | ||
/// @see |GPUSurfaceMetalDelegate::GetMTLTexture| | ||
/// | ||
virtual bool PresentTexture(intptr_t texture_id) const = 0; | ||
|
||
MTLRenderTargetType GetRenderTargetType(); | ||
|
||
private: | ||
const MTLRenderTargetType render_target_type_; | ||
}; | ||
|
||
} // namespace flutter | ||
|
||
#endif // FLUTTER_SHELL_GPU_GPU_SURFACE_METAL_DELEGATE_H_ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chinmaygarde I tried to be clever by capturing the next_drawable_ in lambda, skia uses lazy proxies when we create the SKSurface from metal layer, which means that this variable can be null until canvas.flush() gets called. It only happens on real devices and not simulators for some reason hence this failed an actual device lab test during flutter roll. I've reverted to the earlier behavior.