Skip to content
Permalink
Browse files
REGRESSION(r294215): : r294317 was reverted, it fixed an edge-case fo…
…r 294217

https://bugs.webkit.org/show_bug.cgi?id=240645

Patch by Kimmo Kinnunen <kkinnunen@apple.com> on 2022-05-25
Unreviewed.

Revert r294215, its dependency r294317 was reverted.

Reverted changeset:
        "WebCore::IOSurface has WebCore::GraphicsContext as its
        property, it should be the other way around"
        https://bugs.webkit.org/show_bug.cgi?id=240417
        https://commits.webkit.org/r294215

* Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp:
(WebCore::GraphicsContextCG::drawNativeImage):
* Source/WebCore/platform/graphics/cg/GraphicsContextCG.h:
* Source/WebCore/platform/graphics/cg/IOSurfacePool.cpp:
(WebCore::IOSurfacePool::willAddSurface):
* Source/WebCore/platform/graphics/cg/ImageBufferIOSurfaceBackend.cpp:
(WebCore::ImageBufferIOSurfaceBackend::~ImageBufferIOSurfaceBackend):
(WebCore::ImageBufferIOSurfaceBackend::context const):
(WebCore::ImageBufferIOSurfaceBackend::releaseGraphicsContext):
* Source/WebCore/platform/graphics/cg/ImageBufferIOSurfaceBackend.h:
* Source/WebCore/platform/graphics/cocoa/GraphicsContextCocoa.mm:
(WebCore::GraphicsContextCG::GraphicsContextCG): Deleted.
* Source/WebCore/platform/graphics/cocoa/IOSurface.h:
* Source/WebCore/platform/graphics/cocoa/IOSurface.mm:
(WebCore::IOSurface::create):
(WebCore::IOSurface::ensureGraphicsContext):
(WebCore::IOSurface::releaseGraphicsContext):
(WebCore::IOSurface::releasePlatformGraphicsContext): Deleted.

Canonical link: https://commits.webkit.org/250969@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@294816 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
kkinnunen-apple authored and webkit-commit-queue committed May 25, 2022
1 parent 555e4e3 commit 61e05e09838b2da199e3bf1afe7a6120eee9cb4d
Showing 8 changed files with 32 additions and 32 deletions.
@@ -267,8 +267,8 @@ void GraphicsContextCG::drawNativeImage(NativeImage& nativeImage, const FloatSiz
// image. We need to convert subimageRect to physical image coordinates.
if (auto transform = options.orientation().transformFromDefault(imageSize).inverse())
physicalSubimageRect = transform.value().mapRect(physicalSubimageRect);

}

#if CACHE_SUBIMAGES
return SubimageCacheWithTimer::getSubimage(image, physicalSubimageRect);
#else
@@ -32,16 +32,10 @@

namespace WebCore {

#if HAVE(IOSURFACE)
class IOSurface;
#endif

class WEBCORE_EXPORT GraphicsContextCG : public GraphicsContext {
public:
GraphicsContextCG(CGContextRef);
#if HAVE(IOSURFACE)
explicit GraphicsContextCG(IOSurface&);
#endif

#if PLATFORM(WIN)
GraphicsContextCG(HDC, bool hasAlpha = false); // FIXME: To be removed.
#endif
@@ -82,7 +82,7 @@ void IOSurfacePool::willAddSurface(IOSurface& surface, bool inUse)
CachedSurfaceDetails& details = m_surfaceDetails.add(&surface, CachedSurfaceDetails()).iterator->value;
details.resetLastUseTime();

surface.releasePlatformGraphicsContext();
surface.releaseGraphicsContext();

size_t surfaceBytes = surface.totalBytes();

@@ -125,17 +125,17 @@ ImageBufferIOSurfaceBackend::ImageBufferIOSurfaceBackend(const Parameters& param

ImageBufferIOSurfaceBackend::~ImageBufferIOSurfaceBackend()
{
m_context = std::nullopt; // Make sure the context does not interfere with moving to pool.
IOSurface::moveToPool(WTFMove(m_surface), m_ioSurfacePool.get());
}

GraphicsContext& ImageBufferIOSurfaceBackend::context() const
{
if (!m_context) {
m_context.emplace(*m_surface);
GraphicsContext& context = m_surface->ensureGraphicsContext();
if (m_needsSetupContext) {
m_needsSetupContext = false;
applyBaseTransformToContext();
}
return *m_context;
return context;
}

void ImageBufferIOSurfaceBackend::flushContext()
@@ -216,8 +216,8 @@ bool ImageBufferIOSurfaceBackend::isInUse() const

void ImageBufferIOSurfaceBackend::releaseGraphicsContext()
{
m_context = std::nullopt;
m_surface->releasePlatformGraphicsContext();
m_needsSetupContext = true;
return m_surface->releaseGraphicsContext();
}

bool ImageBufferIOSurfaceBackend::setVolatile()
@@ -27,17 +27,13 @@

#if HAVE(IOSURFACE)

#include "GraphicsContextCG.h"
#include "ImageBufferCGBackend.h"
#include "IOSurface.h"
#include "IOSurfacePool.h"
#include <optional>
#include <wtf/IsoMalloc.h>

namespace WebCore {

class GraphicsContextCG;

class WEBCORE_EXPORT ImageBufferIOSurfaceBackend : public ImageBufferCGBackend {
WTF_MAKE_ISO_ALLOCATED(ImageBufferIOSurfaceBackend);
WTF_MAKE_NONCOPYABLE(ImageBufferIOSurfaceBackend);
@@ -91,7 +87,7 @@ class WEBCORE_EXPORT ImageBufferIOSurfaceBackend : public ImageBufferCGBackend {
std::unique_ptr<IOSurface> m_surface;
mutable bool m_requiresDrawAfterPutPixelBuffer { false };

mutable std::optional<GraphicsContextCG> m_context;
mutable bool m_needsSetupContext { false };
VolatilityState m_volatilityState { VolatilityState::NonVolatile };

RefPtr<IOSurfacePool> m_ioSurfacePool;
@@ -29,7 +29,6 @@
#import "DisplayListRecorder.h"
#import "GraphicsContextCG.h"
#import "GraphicsContextPlatformPrivateCG.h"
#import "IOSurface.h"
#import "IntRect.h"
#import <pal/spi/cg/CoreGraphicsSPI.h>
#import <pal/spi/mac/NSGraphicsSPI.h>
@@ -116,12 +115,6 @@ static void drawFocusRingToContext(CGContextRef context, CGPathRef focusRingPath
drawFocusRing(context, color);
}

GraphicsContextCG::GraphicsContextCG(IOSurface& iosurface)
: GraphicsContextCG(iosurface.ensurePlatformContext())
{
setIsAcceleratedContext(true);
}

void GraphicsContextCG::drawFocusRing(const Path& path, float, float, const Color& color)
{
if (path.isNull())
@@ -43,6 +43,7 @@ class TextStream;

namespace WebCore {

class GraphicsContext;
class HostWindow;
class IOSurfacePool;
class ProcessIdentity;
@@ -126,10 +127,8 @@ class IOSurface final {
id asLayerContents() const { return (__bridge id)m_surface.get(); }
#endif
IOSurfaceRef surface() const { return m_surface.get(); }
WEBCORE_EXPORT GraphicsContext& ensureGraphicsContext();
WEBCORE_EXPORT CGContextRef ensurePlatformContext(const HostWindow* = nullptr);
// The graphics context cached on the surface counts as a "user", so to get
// an accurate result from isInUse(), it needs to be released.
WEBCORE_EXPORT void releasePlatformGraphicsContext();

// Querying volatility can be expensive, so in cases where the surface is
// going to be used immediately, use the return value of setVolatile to
@@ -151,6 +150,10 @@ class IOSurface final {

WEBCORE_EXPORT bool isInUse() const;

// The graphics context cached on the surface counts as a "user", so to get
// an accurate result from isInUse(), it needs to be released.
WEBCORE_EXPORT void releaseGraphicsContext();

#if HAVE(IOSURFACE_ACCELERATOR)
WEBCORE_EXPORT static bool allowConversionFromFormatToFormat(Format, Format);
WEBCORE_EXPORT static void convertToFormat(IOSurfacePool*, std::unique_ptr<WebCore::IOSurface>&& inSurface, Format, Function<void(std::unique_ptr<WebCore::IOSurface>)>&&);
@@ -169,6 +172,7 @@ class IOSurface final {
IntSize m_size;
size_t m_totalBytes;

std::unique_ptr<GraphicsContext> m_graphicsContext;
RetainPtr<CGContextRef> m_cgContext;

RetainPtr<IOSurfaceRef> m_surface;
@@ -27,6 +27,7 @@
#import "IOSurface.h"

#import "DestinationColorSpace.h"
#import "GraphicsContextCG.h"
#import "HostWindow.h"
#import "IOSurfacePool.h"
#import "Logging.h"
@@ -46,7 +47,7 @@
{
if (pool) {
if (auto cachedSurface = pool->takeSurface(size, colorSpace, pixelFormat)) {
cachedSurface->releasePlatformGraphicsContext();
cachedSurface->releaseGraphicsContext();
LOG_WITH_STREAM(IOSurface, stream << "IOSurface::create took from pool: " << *cachedSurface);
return cachedSurface;
}
@@ -351,6 +352,17 @@ static IntSize computeMaximumSurfaceSize()
return m_cgContext.get();
}

GraphicsContext& IOSurface::ensureGraphicsContext()
{
if (m_graphicsContext)
return *m_graphicsContext;

m_graphicsContext = makeUnique<GraphicsContextCG>(ensurePlatformContext());
m_graphicsContext->setIsAcceleratedContext(true);

return *m_graphicsContext;
}

SetNonVolatileResult IOSurface::state() const
{
uint32_t previousState = 0;
@@ -426,8 +438,9 @@ static IntSize computeMaximumSurfaceSize()
return IOSurfaceIsInUse(m_surface.get());
}

void IOSurface::releasePlatformGraphicsContext()
void IOSurface::releaseGraphicsContext()
{
m_graphicsContext = nullptr;
m_cgContext = nullptr;
}

0 comments on commit 61e05e0

Please sign in to comment.