2018-11-07 12:24:35 -08:00
|
|
|
// Copyright 2013 The Flutter Authors. All rights reserved.
|
2016-02-09 12:40:28 -08:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
2016-10-06 15:06:21 -07:00
|
|
|
#include "flutter/shell/gpu/gpu_surface_vulkan.h"
|
2018-07-26 12:49:34 -07:00
|
|
|
#include "flutter/fml/logging.h"
|
2016-09-23 15:33:25 -07:00
|
|
|
|
2019-04-09 17:10:46 -07:00
|
|
|
namespace flutter {
|
2016-09-23 15:33:25 -07:00
|
|
|
|
2017-01-20 14:37:10 -08:00
|
|
|
GPUSurfaceVulkan::GPUSurfaceVulkan(
|
2018-07-26 12:49:34 -07:00
|
|
|
fml::RefPtr<vulkan::VulkanProcTable> proc_table,
|
2017-01-20 14:37:10 -08:00
|
|
|
std::unique_ptr<vulkan::VulkanNativeSurface> native_surface)
|
|
|
|
|
: window_(std::move(proc_table), std::move(native_surface)),
|
|
|
|
|
weak_factory_(this) {}
|
|
|
|
|
|
|
|
|
|
GPUSurfaceVulkan::~GPUSurfaceVulkan() = default;
|
|
|
|
|
|
2019-04-09 17:10:46 -07:00
|
|
|
// |Surface|
|
2017-01-20 14:37:10 -08:00
|
|
|
bool GPUSurfaceVulkan::IsValid() {
|
|
|
|
|
return window_.IsValid();
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-09 17:10:46 -07:00
|
|
|
// |Surface|
|
2017-01-20 14:37:10 -08:00
|
|
|
std::unique_ptr<SurfaceFrame> GPUSurfaceVulkan::AcquireFrame(
|
2019-12-03 12:02:37 -08:00
|
|
|
const SkISize& size) {
|
2017-01-20 14:37:10 -08:00
|
|
|
auto surface = window_.AcquireSurface();
|
|
|
|
|
|
|
|
|
|
if (surface == nullptr) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-26 12:49:34 -07:00
|
|
|
SurfaceFrame::SubmitCallback callback =
|
|
|
|
|
[weak_this = weak_factory_.GetWeakPtr()](const SurfaceFrame&,
|
|
|
|
|
SkCanvas* canvas) -> bool {
|
2017-04-18 16:26:37 -07:00
|
|
|
// Frames are only ever acquired on the GPU thread. This is also the thread
|
|
|
|
|
// on which the weak pointer factory is collected (as this instance is owned
|
|
|
|
|
// by the rasterizer). So this use of weak pointers is safe.
|
|
|
|
|
if (canvas == nullptr || !weak_this) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return weak_this->window_.SwapBuffers();
|
|
|
|
|
};
|
2019-12-11 15:10:55 -08:00
|
|
|
return std::make_unique<SurfaceFrame>(std::move(surface), true,
|
2017-04-18 16:26:37 -07:00
|
|
|
std::move(callback));
|
2017-01-20 14:37:10 -08:00
|
|
|
}
|
|
|
|
|
|
2019-04-09 17:10:46 -07:00
|
|
|
// |Surface|
|
2018-08-28 14:13:49 -07:00
|
|
|
SkMatrix GPUSurfaceVulkan::GetRootTransformation() const {
|
|
|
|
|
// This backend does not support delegating to the underlying platform to
|
|
|
|
|
// query for root surface transformations. Just return identity.
|
|
|
|
|
SkMatrix matrix;
|
|
|
|
|
matrix.reset();
|
|
|
|
|
return matrix;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-09 17:10:46 -07:00
|
|
|
// |Surface|
|
2017-01-20 14:37:10 -08:00
|
|
|
GrContext* GPUSurfaceVulkan::GetContext() {
|
|
|
|
|
return window_.GetSkiaGrContext();
|
|
|
|
|
}
|
2016-09-23 15:33:25 -07:00
|
|
|
|
2019-04-09 17:10:46 -07:00
|
|
|
} // namespace flutter
|