forked from chromium/chromium
-
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.
Add SkiaOutputDeviceDawn and create a Dawn GrContext
Create a Dawn device using D3D12 on Windows and Vulkan on Linux, and use it to create a Skia Dawn GrContext. On Windows, create a SkiaOutputDeviceDawn, which uses a native D3D12 swapchain for presentation. On Linux, use a SkiaOutputDeviceX11 for now, until the Vulkan swapchain is ready. Bug: 1021566 Change-Id: If3e1f435fe87132c9294f5613c85d675a7282b3a Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1899200 Commit-Queue: Sean Gilhuly <sgilhuly@chromium.org> Reviewed-by: Jonathan Backer <backer@chromium.org> Reviewed-by: Bo <boliu@chromium.org> Reviewed-by: Stephen White <senorblanco@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org> Cr-Commit-Position: refs/heads/master@{#713851}
- Loading branch information
Sean Gilhuly
authored and
Commit Bot
committed
Nov 8, 2019
1 parent
43812c2
commit e534232
Showing
26 changed files
with
438 additions
and
25 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
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
121 changes: 121 additions & 0 deletions
121
components/viz/service/display_embedder/skia_output_device_dawn.cc
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,121 @@ | ||
// Copyright 2019 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 "components/viz/service/display_embedder/skia_output_device_dawn.h" | ||
|
||
#include "base/logging.h" | ||
#include "build/build_config.h" | ||
#include "components/viz/common/gpu/dawn_context_provider.h" | ||
|
||
#if defined(OS_WIN) | ||
#include "third_party/dawn/src/include/dawn_native/D3D12Backend.h" | ||
#elif defined(OS_LINUX) | ||
#include "third_party/dawn/src/include/dawn_native/VulkanBackend.h" | ||
#endif | ||
|
||
namespace viz { | ||
|
||
namespace { | ||
|
||
// Some Vulkan drivers do not support kRGB_888x_SkColorType. Always use | ||
// kRGBA_8888_SkColorType instead and initialize surface to opaque as necessary. | ||
constexpr SkColorType kSurfaceColorType = kRGBA_8888_SkColorType; | ||
constexpr dawn::TextureFormat kSwapChainFormat = | ||
dawn::TextureFormat::RGBA8Unorm; | ||
|
||
constexpr dawn::TextureUsage kUsage = | ||
dawn::TextureUsage::OutputAttachment | dawn::TextureUsage::CopySrc; | ||
|
||
} // namespace | ||
|
||
SkiaOutputDeviceDawn::SkiaOutputDeviceDawn( | ||
DawnContextProvider* context_provider, | ||
gfx::AcceleratedWidget widget, | ||
DidSwapBufferCompleteCallback did_swap_buffer_complete_callback) | ||
: SkiaOutputDevice(/*need_swap_semaphore=*/false, | ||
did_swap_buffer_complete_callback), | ||
context_provider_(context_provider), | ||
widget_(widget) { | ||
capabilities_.supports_post_sub_buffer = false; | ||
} | ||
|
||
SkiaOutputDeviceDawn::~SkiaOutputDeviceDawn() = default; | ||
|
||
bool SkiaOutputDeviceDawn::Reshape(const gfx::Size& size, | ||
float device_scale_factor, | ||
const gfx::ColorSpace& color_space, | ||
bool has_alpha, | ||
gfx::OverlayTransform transform) { | ||
DCHECK_EQ(transform, gfx::OVERLAY_TRANSFORM_NONE); | ||
|
||
DiscardBackbuffer(); | ||
size_ = size; | ||
sk_color_space_ = color_space.ToSkColorSpace(); | ||
|
||
CreateSwapChainImplementation(); | ||
dawn::SwapChainDescriptor desc; | ||
desc.implementation = reinterpret_cast<int64_t>(&swap_chain_implementation_); | ||
swap_chain_ = context_provider_->GetDevice().CreateSwapChain(&desc); | ||
if (!swap_chain_) | ||
return false; | ||
swap_chain_.Configure(kSwapChainFormat, kUsage, size_.width(), | ||
size_.height()); | ||
|
||
EnsureBackbuffer(); | ||
return true; | ||
} | ||
|
||
void SkiaOutputDeviceDawn::SwapBuffers( | ||
BufferPresentedCallback feedback, | ||
std::vector<ui::LatencyInfo> latency_info) { | ||
StartSwapBuffers(std::move(feedback)); | ||
swap_chain_.Present(texture_); | ||
texture_ = swap_chain_.GetNextTexture(); | ||
FinishSwapBuffers(gfx::SwapResult::SWAP_ACK, | ||
gfx::Size(size_.width(), size_.height()), | ||
std::move(latency_info)); | ||
} | ||
|
||
SkSurface* SkiaOutputDeviceDawn::BeginPaint() { | ||
GrDawnImageInfo info; | ||
info.fTexture = texture_; | ||
info.fFormat = kSwapChainFormat; | ||
info.fLevelCount = 1; | ||
GrBackendTexture backend_texture(size_.width(), size_.height(), info); | ||
DCHECK(backend_texture.isValid()); | ||
sk_surface_ = SkSurface::MakeFromBackendTextureAsRenderTarget( | ||
context_provider_->GetGrContext(), backend_texture, | ||
!capabilities_.flipped_output_surface ? kTopLeft_GrSurfaceOrigin | ||
: kBottomLeft_GrSurfaceOrigin, | ||
/*sampleCount=*/0, kSurfaceColorType, sk_color_space_, | ||
/*surfaceProps=*/nullptr); | ||
return sk_surface_.get(); | ||
} | ||
|
||
void SkiaOutputDeviceDawn::EndPaint(const GrBackendSemaphore& semaphore) { | ||
GrFlushInfo flush_info; | ||
sk_surface_->flush(SkSurface::BackendSurfaceAccess::kPresent, flush_info); | ||
sk_surface_.reset(); | ||
} | ||
|
||
void SkiaOutputDeviceDawn::EnsureBackbuffer() { | ||
if (swap_chain_) | ||
texture_ = swap_chain_.GetNextTexture(); | ||
} | ||
|
||
void SkiaOutputDeviceDawn::DiscardBackbuffer() { | ||
texture_ = nullptr; | ||
} | ||
|
||
void SkiaOutputDeviceDawn::CreateSwapChainImplementation() { | ||
#if defined(OS_WIN) | ||
swap_chain_implementation_ = dawn_native::d3d12::CreateNativeSwapChainImpl( | ||
context_provider_->GetDevice().Get(), widget_); | ||
#else | ||
NOTREACHED(); | ||
ALLOW_UNUSED_LOCAL(widget_); | ||
#endif | ||
} | ||
|
||
} // namespace viz |
62 changes: 62 additions & 0 deletions
62
components/viz/service/display_embedder/skia_output_device_dawn.h
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,62 @@ | ||
// Copyright 2019 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 COMPONENTS_VIZ_SERVICE_DISPLAY_EMBEDDER_SKIA_OUTPUT_DEVICE_DAWN_H_ | ||
#define COMPONENTS_VIZ_SERVICE_DISPLAY_EMBEDDER_SKIA_OUTPUT_DEVICE_DAWN_H_ | ||
|
||
#include "components/viz/service/display_embedder/skia_output_device.h" | ||
#include "third_party/dawn/src/include/dawn/dawn_wsi.h" | ||
#include "third_party/dawn/src/include/dawn/dawncpp.h" | ||
#include "third_party/dawn/src/include/dawn_native/DawnNative.h" | ||
#include "third_party/skia/include/core/SkColorSpace.h" | ||
#include "third_party/skia/include/core/SkImageInfo.h" | ||
#include "third_party/skia/include/gpu/GrBackendSurface.h" | ||
#include "ui/gfx/native_widget_types.h" | ||
|
||
namespace viz { | ||
|
||
class DawnContextProvider; | ||
|
||
class SkiaOutputDeviceDawn : public SkiaOutputDevice { | ||
public: | ||
SkiaOutputDeviceDawn( | ||
DawnContextProvider* context_provider, | ||
gfx::AcceleratedWidget widget, | ||
DidSwapBufferCompleteCallback did_swap_buffer_complete_callback); | ||
~SkiaOutputDeviceDawn() override; | ||
|
||
// SkiaOutputDevice implementation: | ||
bool Reshape(const gfx::Size& size, | ||
float device_scale_factor, | ||
const gfx::ColorSpace& color_space, | ||
bool has_alpha, | ||
gfx::OverlayTransform transform) override; | ||
void SwapBuffers(BufferPresentedCallback feedback, | ||
std::vector<ui::LatencyInfo> latency_info) override; | ||
SkSurface* BeginPaint() override; | ||
void EndPaint(const GrBackendSemaphore& semaphore) override; | ||
void EnsureBackbuffer() override; | ||
void DiscardBackbuffer() override; | ||
|
||
private: | ||
// Create a platform-specific swapchain implementation. | ||
void CreateSwapChainImplementation(); | ||
|
||
DawnContextProvider* const context_provider_; | ||
gfx::AcceleratedWidget widget_; | ||
DawnSwapChainImplementation swap_chain_implementation_; | ||
dawn::SwapChain swap_chain_; | ||
dawn::Texture texture_; | ||
sk_sp<SkSurface> sk_surface_; | ||
|
||
gfx::Size size_; | ||
sk_sp<SkColorSpace> sk_color_space_; | ||
GrBackendTexture backend_texture_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(SkiaOutputDeviceDawn); | ||
}; | ||
|
||
} // namespace viz | ||
|
||
#endif // COMPONENTS_VIZ_SERVICE_DISPLAY_EMBEDDER_SKIA_OUTPUT_DEVICE_DAWN_H_ |
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
Oops, something went wrong.