2018-11-07 12:24:35 -08:00
|
|
|
// Copyright 2013 The Flutter Authors. All rights reserved.
|
2017-02-22 15:40:23 -08:00
|
|
|
// 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_software.h"
|
|
|
|
|
|
|
|
|
|
#include <memory>
|
2018-07-26 12:49:34 -07:00
|
|
|
#include "flutter/fml/logging.h"
|
2017-02-22 15:40:23 -08:00
|
|
|
|
2019-04-09 17:10:46 -07:00
|
|
|
namespace flutter {
|
2017-02-22 15:40:23 -08:00
|
|
|
|
2019-08-23 13:52:06 -07:00
|
|
|
GPUSurfaceSoftware::GPUSurfaceSoftware(GPUSurfaceSoftwareDelegate* delegate,
|
|
|
|
|
bool render_to_surface)
|
|
|
|
|
: delegate_(delegate),
|
|
|
|
|
render_to_surface_(render_to_surface),
|
|
|
|
|
weak_factory_(this) {}
|
2017-02-22 15:40:23 -08:00
|
|
|
|
|
|
|
|
GPUSurfaceSoftware::~GPUSurfaceSoftware() = default;
|
|
|
|
|
|
2019-04-09 17:10:46 -07:00
|
|
|
// |Surface|
|
2017-02-22 15:40:23 -08:00
|
|
|
bool GPUSurfaceSoftware::IsValid() {
|
|
|
|
|
return delegate_ != nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-09 17:10:46 -07:00
|
|
|
// |Surface|
|
2017-02-22 15:40:23 -08:00
|
|
|
std::unique_ptr<SurfaceFrame> GPUSurfaceSoftware::AcquireFrame(
|
2019-12-03 12:02:37 -08:00
|
|
|
const SkISize& logical_size) {
|
2019-08-23 13:52:06 -07:00
|
|
|
// TODO(38466): Refactor GPU surface APIs take into account the fact that an
|
|
|
|
|
// external view embedder may want to render to the root surface.
|
|
|
|
|
if (!render_to_surface_) {
|
|
|
|
|
return std::make_unique<SurfaceFrame>(
|
2019-12-11 15:10:55 -08:00
|
|
|
nullptr, true, [](const SurfaceFrame& surface_frame, SkCanvas* canvas) {
|
2019-08-23 13:52:06 -07:00
|
|
|
return true;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-22 15:40:23 -08:00
|
|
|
if (!IsValid()) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-13 13:48:15 -07:00
|
|
|
const auto size = SkISize::Make(logical_size.width(), logical_size.height());
|
2017-04-17 14:07:22 -07:00
|
|
|
|
|
|
|
|
sk_sp<SkSurface> backing_store = delegate_->AcquireBackingStore(size);
|
2017-02-22 15:40:23 -08:00
|
|
|
|
|
|
|
|
if (backing_store == nullptr) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (size != SkISize::Make(backing_store->width(), backing_store->height())) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-17 14:07:22 -07:00
|
|
|
// If the surface has been scaled, we need to apply the inverse scaling to the
|
|
|
|
|
// underlying canvas so that coordinates are mapped to the same spot
|
|
|
|
|
// irrespective of surface scaling.
|
|
|
|
|
SkCanvas* canvas = backing_store->getCanvas();
|
|
|
|
|
canvas->resetMatrix();
|
|
|
|
|
|
2018-04-13 13:48:15 -07:00
|
|
|
SurfaceFrame::SubmitCallback on_submit =
|
|
|
|
|
[self = weak_factory_.GetWeakPtr()](const SurfaceFrame& surface_frame,
|
|
|
|
|
SkCanvas* canvas) -> bool {
|
2017-02-22 15:40:23 -08:00
|
|
|
// If the surface itself went away, there is nothing more to do.
|
|
|
|
|
if (!self || !self->IsValid() || canvas == nullptr) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
canvas->flush();
|
|
|
|
|
|
|
|
|
|
return self->delegate_->PresentBackingStore(surface_frame.SkiaSurface());
|
|
|
|
|
};
|
|
|
|
|
|
2019-12-11 15:10:55 -08:00
|
|
|
return std::make_unique<SurfaceFrame>(backing_store, true, on_submit);
|
2017-02-22 15:40:23 -08:00
|
|
|
}
|
|
|
|
|
|
2019-04-09 17:10:46 -07:00
|
|
|
// |Surface|
|
2018-08-28 14:13:49 -07:00
|
|
|
SkMatrix GPUSurfaceSoftware::GetRootTransformation() const {
|
|
|
|
|
// This backend does not currently support root surface transformations. Just
|
|
|
|
|
// return identity.
|
|
|
|
|
SkMatrix matrix;
|
|
|
|
|
matrix.reset();
|
|
|
|
|
return matrix;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-09 17:10:46 -07:00
|
|
|
// |Surface|
|
2017-02-22 15:40:23 -08:00
|
|
|
GrContext* GPUSurfaceSoftware::GetContext() {
|
2018-05-28 18:51:00 -07:00
|
|
|
// There is no GrContext associated with a software surface.
|
2017-02-22 15:40:23 -08:00
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-09 17:10:46 -07:00
|
|
|
// |Surface|
|
2019-04-17 14:38:45 -07:00
|
|
|
flutter::ExternalViewEmbedder* GPUSurfaceSoftware::GetExternalViewEmbedder() {
|
2018-10-26 14:26:59 -07:00
|
|
|
return delegate_->GetExternalViewEmbedder();
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-09 17:10:46 -07:00
|
|
|
} // namespace flutter
|