forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Back Vulkan Rasterizer with Mozart View (flutter#3568)
This version does not recycle buffers. It is meant only as an initial solution, and the proper buffer recycling logic has been broken out into a separate change
- Loading branch information
1 parent
9bc769a
commit 2a4af69
Showing
14 changed files
with
573 additions
and
62 deletions.
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
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,90 @@ | ||
// Copyright 2017 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/content_handler/vulkan_native_rasterizer.h" | ||
|
||
#include <utility> | ||
|
||
#include "flutter/vulkan/vulkan_native_surface_magma.h" | ||
|
||
namespace flutter_runner { | ||
|
||
VulkanNativeRasterizer::VulkanNativeRasterizer() | ||
: compositor_context_(nullptr) { | ||
auto proc_table = ftl::MakeRefCounted<vulkan::VulkanProcTable>(); | ||
|
||
if (!proc_table->HasAcquiredMandatoryProcAddresses()) { | ||
return; | ||
} | ||
|
||
auto native_surface = std::make_unique<vulkan::VulkanNativeSurfaceMagma>(); | ||
|
||
if (!native_surface->IsValid()) { | ||
return; | ||
} | ||
|
||
auto window = std::make_unique<vulkan::VulkanWindow>( | ||
proc_table, std::move(native_surface)); | ||
|
||
if (!window->IsValid()) { | ||
return; | ||
} | ||
|
||
window_ = std::move(window); | ||
} | ||
|
||
VulkanNativeRasterizer::~VulkanNativeRasterizer() = default; | ||
|
||
bool VulkanNativeRasterizer::IsValid() const { | ||
return window_ == nullptr ? false : window_->IsValid(); | ||
} | ||
|
||
void VulkanNativeRasterizer::SetScene( | ||
fidl::InterfaceHandle<mozart::Scene> scene) { | ||
// TODO: Composition is currently unsupported using the Vulkan backend. | ||
} | ||
|
||
void VulkanNativeRasterizer::Draw(std::unique_ptr<flow::LayerTree> layer_tree, | ||
ftl::Closure callback) { | ||
Draw(std::move(layer_tree)); | ||
callback(); | ||
} | ||
|
||
bool VulkanNativeRasterizer::Draw(std::unique_ptr<flow::LayerTree> layer_tree) { | ||
if (layer_tree == nullptr) { | ||
FTL_DLOG(INFO) << "Layer tree was not valid."; | ||
return false; | ||
} | ||
|
||
if (!window_->IsValid()) { | ||
FTL_DLOG(INFO) << "Vulkan window was not valid."; | ||
return false; | ||
} | ||
|
||
auto surface = window_->AcquireSurface(); | ||
|
||
if (!surface && surface->getCanvas() != nullptr) { | ||
FTL_DLOG(INFO) << "Could not acquire a vulkan surface."; | ||
return false; | ||
} | ||
|
||
{ | ||
auto compositor_frame = compositor_context_.AcquireFrame( | ||
window_->GetSkiaGrContext(), // GrContext* | ||
surface->getCanvas(), // SkCanvas | ||
true // instrumentation | ||
); | ||
|
||
layer_tree->Raster(compositor_frame); | ||
} | ||
|
||
if (!window_->SwapBuffers()) { | ||
FTL_DLOG(INFO) << "Could not swap buffers successfully."; | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
} // namespace flutter_runner |
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,41 @@ | ||
// Copyright 2017 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. | ||
|
||
#ifndef FLUTTER_CONTENT_HANDLER_VULKAN_RASTERIZER_H_ | ||
#define FLUTTER_CONTENT_HANDLER_VULKAN_RASTERIZER_H_ | ||
|
||
#include <memory> | ||
|
||
#include "flutter/content_handler/rasterizer.h" | ||
#include "flutter/flow/compositor_context.h" | ||
#include "flutter/vulkan/vulkan_window.h" | ||
#include "lib/ftl/macros.h" | ||
|
||
namespace flutter_runner { | ||
|
||
class VulkanNativeRasterizer : public Rasterizer { | ||
public: | ||
VulkanNativeRasterizer(); | ||
|
||
~VulkanNativeRasterizer() override; | ||
|
||
bool IsValid() const; | ||
|
||
void SetScene(fidl::InterfaceHandle<mozart::Scene> scene) override; | ||
|
||
void Draw(std::unique_ptr<flow::LayerTree> layer_tree, | ||
ftl::Closure callback) override; | ||
|
||
private: | ||
std::unique_ptr<vulkan::VulkanWindow> window_; | ||
flow::CompositorContext compositor_context_; | ||
|
||
bool Draw(std::unique_ptr<flow::LayerTree> layer_tree); | ||
|
||
FTL_DISALLOW_COPY_AND_ASSIGN(VulkanNativeRasterizer); | ||
}; | ||
|
||
} // namespace flutter_runner | ||
|
||
#endif // FLUTTER_CONTENT_HANDLER_VULKAN_RASTERIZER_H_ |
Oops, something went wrong.