mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
* Re-land "Support multiple shells in a single process. (#4932)" This reverts commit 723c7d01439da4261bc836075fb55651ce9e7f03.
82 lines
2.0 KiB
C++
82 lines
2.0 KiB
C++
// Copyright 2016 The Chromium 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/common/surface.h"
|
|
|
|
#include "lib/fxl/logging.h"
|
|
#include "third_party/skia/include/core/SkColorSpaceXformCanvas.h"
|
|
#include "third_party/skia/include/core/SkSurface.h"
|
|
|
|
namespace shell {
|
|
|
|
SurfaceFrame::SurfaceFrame(sk_sp<SkSurface> surface,
|
|
SubmitCallback submit_callback)
|
|
: submitted_(false), surface_(surface), submit_callback_(submit_callback) {
|
|
FXL_DCHECK(submit_callback_);
|
|
if (surface_) {
|
|
xform_canvas_ = SkCreateColorSpaceXformCanvas(surface_->getCanvas(),
|
|
SkColorSpace::MakeSRGB());
|
|
}
|
|
}
|
|
|
|
SurfaceFrame::~SurfaceFrame() {
|
|
if (submit_callback_) {
|
|
// Dropping without a Submit.
|
|
submit_callback_(*this, nullptr);
|
|
}
|
|
}
|
|
|
|
bool SurfaceFrame::Submit() {
|
|
if (submitted_) {
|
|
return false;
|
|
}
|
|
|
|
submitted_ = PerformSubmit();
|
|
|
|
return submitted_;
|
|
}
|
|
|
|
SkCanvas* SurfaceFrame::SkiaCanvas() {
|
|
if (xform_canvas_) {
|
|
return xform_canvas_.get();
|
|
}
|
|
return surface_ != nullptr ? surface_->getCanvas() : nullptr;
|
|
}
|
|
|
|
sk_sp<SkSurface> SurfaceFrame::SkiaSurface() const {
|
|
return surface_;
|
|
}
|
|
|
|
bool SurfaceFrame::PerformSubmit() {
|
|
if (submit_callback_ == nullptr) {
|
|
return false;
|
|
}
|
|
|
|
if (submit_callback_(*this, SkiaCanvas())) {
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
Surface::Surface() : Surface(std::make_unique<flow::CompositorContext>()) {}
|
|
|
|
Surface::Surface(std::unique_ptr<flow::CompositorContext> compositor_context)
|
|
: compositor_context_(std::move(compositor_context)) {
|
|
FXL_DCHECK(compositor_context_);
|
|
// TODO: Get rid of these explicit calls and move the logic to the c/dtors of
|
|
// the compositor context.
|
|
compositor_context_->OnGrContextCreated();
|
|
}
|
|
|
|
Surface::~Surface() {
|
|
compositor_context_->OnGrContextDestroyed();
|
|
}
|
|
|
|
flow::CompositorContext& Surface::GetCompositorContext() {
|
|
return *compositor_context_;
|
|
}
|
|
|
|
} // namespace shell
|