summaryrefslogtreecommitdiffstats
path: root/src/core/compositor/display_skia_output_device.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/compositor/display_skia_output_device.cpp')
-rw-r--r--src/core/compositor/display_skia_output_device.cpp109
1 files changed, 59 insertions, 50 deletions
diff --git a/src/core/compositor/display_skia_output_device.cpp b/src/core/compositor/display_skia_output_device.cpp
index 246a846fa..0ca466fe8 100644
--- a/src/core/compositor/display_skia_output_device.cpp
+++ b/src/core/compositor/display_skia_output_device.cpp
@@ -3,10 +3,16 @@
#include "display_skia_output_device.h"
+#include "compositor_resource_fence.h"
#include "type_conversion.h"
#include "gpu/command_buffer/service/skia_utils.h"
+#include "third_party/skia/include/core/SkSurface.h"
#include "third_party/skia/include/core/SkSurfaceProps.h"
+#include "third_party/skia/include/gpu/ganesh/SkSurfaceGanesh.h"
+#include "third_party/skia/include/gpu/ganesh/gl/GrGLBackendSurface.h"
+
+#include <QSGTexture>
namespace QtWebEngineCore {
@@ -17,34 +23,25 @@ public:
: m_parent(parent)
, m_shape(m_parent->m_shape)
{
- auto formatIndex = static_cast<int>(m_shape.format);
- const auto &colorType = m_parent->capabilities_.sk_color_types[formatIndex];
- DCHECK(colorType != kUnknown_SkColorType)
- << "SkColorType is invalid for format: " << formatIndex;
+ }
+ void initialize()
+ {
+ const auto &colorType = m_shape.imageInfo.colorType();
+ DCHECK(colorType != kUnknown_SkColorType);
m_texture = m_parent->m_contextState->gr_context()->createBackendTexture(
- m_shape.sizeInPixels.width(), m_shape.sizeInPixels.height(), colorType,
+ m_shape.imageInfo.width(), m_shape.imageInfo.height(), colorType,
GrMipMapped::kNo, GrRenderable::kYes);
DCHECK(m_texture.isValid());
- if (m_texture.backend() == GrBackendApi::kVulkan) {
-#if BUILDFLAG(ENABLE_VULKAN)
- GrVkImageInfo info;
- bool result = m_texture.getVkImageInfo(&info);
- DCHECK(result);
- m_estimatedSize = info.fAlloc.fSize;
-#else
- NOTREACHED();
-#endif
- } else {
- auto info = SkImageInfo::Make(m_shape.sizeInPixels.width(), m_shape.sizeInPixels.height(),
- colorType, kUnpremul_SkAlphaType);
- m_estimatedSize = info.computeMinByteSize();
- }
+ DCHECK(m_texture.backend() == GrBackendApi::kOpenGL);
+ auto info = SkImageInfo::Make(m_shape.imageInfo.width(), m_shape.imageInfo.height(),
+ colorType, kUnpremul_SkAlphaType);
+ m_estimatedSize = info.computeMinByteSize();
m_parent->memory_type_tracker_->TrackMemAlloc(m_estimatedSize);
SkSurfaceProps surfaceProps = SkSurfaceProps{0, kUnknown_SkPixelGeometry};
- m_surface = SkSurface::MakeFromBackendTexture(
+ m_surface = SkSurfaces::WrapBackendTexture(
m_parent->m_contextState->gr_context(), m_texture,
m_parent->capabilities_.output_surface_origin == gfx::SurfaceOrigin::kTopLeft
? kTopLeft_GrSurfaceOrigin
@@ -55,8 +52,10 @@ public:
~Buffer()
{
- DeleteGrBackendTexture(m_parent->m_contextState.get(), &m_texture);
- m_parent->memory_type_tracker_->TrackMemFree(m_estimatedSize);
+ if (m_texture.isValid()) {
+ DeleteGrBackendTexture(m_parent->m_contextState.get(), &m_texture);
+ m_parent->memory_type_tracker_->TrackMemFree(m_estimatedSize);
+ }
}
void createFence()
@@ -87,17 +86,20 @@ private:
DisplaySkiaOutputDevice::DisplaySkiaOutputDevice(
scoped_refptr<gpu::SharedContextState> contextState,
+ bool requiresAlpha,
gpu::MemoryTracker *memoryTracker,
DidSwapBufferCompleteCallback didSwapBufferCompleteCallback)
- : SkiaOutputDevice(
- contextState->gr_context(),
- memoryTracker,
- didSwapBufferCompleteCallback)
+ : SkiaOutputDevice(contextState->gr_context(), contextState->graphite_context(),
+ memoryTracker, didSwapBufferCompleteCallback)
, Compositor(Compositor::Type::OpenGL)
, m_contextState(contextState)
+ , m_requiresAlpha(requiresAlpha)
{
capabilities_.uses_default_gl_framebuffer = false;
capabilities_.supports_surfaceless = true;
+ capabilities_.preserve_buffer_content = true;
+ capabilities_.only_invalidates_damage_rect = false;
+ capabilities_.number_of_buffers = 3;
capabilities_.sk_color_types[static_cast<int>(gfx::BufferFormat::RGBA_8888)] =
kRGBA_8888_SkColorType;
@@ -117,20 +119,20 @@ void DisplaySkiaOutputDevice::SetFrameSinkId(const viz::FrameSinkId &id)
{
bind(id);
}
-
-bool DisplaySkiaOutputDevice::Reshape(const gfx::Size& sizeInPixels,
- float devicePixelRatio,
- const gfx::ColorSpace& colorSpace,
- gfx::BufferFormat format,
+bool DisplaySkiaOutputDevice::Reshape(const SkImageInfo &image_info,
+ const gfx::ColorSpace &colorSpace,
+ int sample_count,
+ float device_scale_factor,
gfx::OverlayTransform transform)
{
- m_shape = Shape{sizeInPixels, devicePixelRatio, colorSpace, format};
+ m_shape = Shape{image_info, device_scale_factor, colorSpace};
DCHECK_EQ(transform, gfx::OVERLAY_TRANSFORM_NONE);
return true;
}
-void DisplaySkiaOutputDevice::SwapBuffers(BufferPresentedCallback feedback,
- viz::OutputSurfaceFrame frame)
+void DisplaySkiaOutputDevice::Present(const absl::optional<gfx::Rect> &update_rect,
+ BufferPresentedCallback feedback,
+ viz::OutputSurfaceFrame frame)
{
DCHECK(m_backBuffer);
@@ -140,8 +142,8 @@ void DisplaySkiaOutputDevice::SwapBuffers(BufferPresentedCallback feedback,
{
QMutexLocker locker(&m_mutex);
- m_taskRunner = base::ThreadTaskRunnerHandle::Get();
- m_middleBuffer = std::move(m_backBuffer);
+ m_taskRunner = base::SingleThreadTaskRunner::GetCurrentDefault();
+ std::swap(m_middleBuffer, m_backBuffer);
m_readyToUpdate = true;
}
@@ -157,12 +159,12 @@ void DisplaySkiaOutputDevice::DiscardBackbuffer()
{
}
-SkSurface *DisplaySkiaOutputDevice::BeginPaint(bool allocate_frame_buffer,
- std::vector<GrBackendSemaphore> *)
+SkSurface *DisplaySkiaOutputDevice::BeginPaint(std::vector<GrBackendSemaphore> *end_semaphores)
{
- Q_UNUSED(allocate_frame_buffer); // FIXME?
- if (!m_backBuffer || m_backBuffer->shape() != m_shape)
+ if (!m_backBuffer || m_backBuffer->shape() != m_shape) {
m_backBuffer = std::make_unique<Buffer>(this);
+ m_backBuffer->initialize();
+ }
return m_backBuffer->surface();
}
@@ -189,26 +191,33 @@ void DisplaySkiaOutputDevice::waitForTexture()
m_frontBuffer->consumeFence();
}
-int DisplaySkiaOutputDevice::textureId()
+QSGTexture *DisplaySkiaOutputDevice::texture(QQuickWindow *win, uint32_t textureOptions)
{
if (!m_frontBuffer)
- return 0;
+ return nullptr;
+
+ QQuickWindow::CreateTextureOptions texOpts(textureOptions);
+ QSGTexture *texture = nullptr;
GrGLTextureInfo info;
- if (!m_frontBuffer->texture().getGLTextureInfo(&info))
- return 0;
+ if (GrBackendTextures::GetGLTextureInfo(m_frontBuffer->texture(), &info))
+ texture = QNativeInterface::QSGOpenGLTexture::fromNative(info.fID, win, size(), texOpts);
+ return texture;
+}
- return info.fID;
+bool DisplaySkiaOutputDevice::textureIsFlipped()
+{
+ return true;
}
QSize DisplaySkiaOutputDevice::size()
{
- return m_frontBuffer ? toQt(m_frontBuffer->shape().sizeInPixels) : QSize();
+ return m_frontBuffer ? toQt(m_frontBuffer->shape().imageInfo.dimensions()) : QSize();
}
-bool DisplaySkiaOutputDevice::hasAlphaChannel()
+bool DisplaySkiaOutputDevice::requiresAlphaChannel()
{
- return true;
+ return m_requiresAlpha;
}
float DisplaySkiaOutputDevice::devicePixelRatio()
@@ -220,11 +229,11 @@ void DisplaySkiaOutputDevice::SwapBuffersFinished()
{
{
QMutexLocker locker(&m_mutex);
- m_backBuffer = std::move(m_middleBuffer);
+ std::swap(m_backBuffer, m_middleBuffer);
}
FinishSwapBuffers(gfx::SwapCompletionResult(gfx::SwapResult::SWAP_ACK),
- gfx::Size(m_shape.sizeInPixels.width(), m_shape.sizeInPixels.height()),
+ gfx::Size(m_shape.imageInfo.width(), m_shape.imageInfo.height()),
std::move(m_frame));
}