Diff
Modified: trunk/Source/WebKitLegacy/CMakeLists.txt (224628 => 224629)
--- trunk/Source/WebKitLegacy/CMakeLists.txt 2017-11-09 16:18:32 UTC (rev 224628)
+++ trunk/Source/WebKitLegacy/CMakeLists.txt 2017-11-09 17:11:24 UTC (rev 224629)
@@ -61,4 +61,8 @@
POST_BUILD
COMMAND ${PERL_EXECUTABLE} ${WEBKIT_LIBRARIES_DIR}/tools/scripts/version-stamp.pl ${DERIVED_SOURCES_WEBKITLEGACY_DIR} $<TARGET_FILE:WebKitLegacy>
VERBATIM)
+
+ if (NOT WTF_PLATFORM_WIN_CAIRO)
+ add_subdirectory(win/WebKitQuartzCoreAdditions)
+ endif ()
endif ()
Modified: trunk/Source/WebKitLegacy/ChangeLog (224628 => 224629)
--- trunk/Source/WebKitLegacy/ChangeLog 2017-11-09 16:18:32 UTC (rev 224628)
+++ trunk/Source/WebKitLegacy/ChangeLog 2017-11-09 17:11:24 UTC (rev 224629)
@@ -1,3 +1,14 @@
+2017-11-06 Per Arne Vollan <pvol...@apple.com>
+
+ [Win] Add WebKitQuartzCoreAdditions library.
+ https://bugs.webkit.org/show_bug.cgi?id=179331
+
+ Reviewed by Alex Christensen.
+
+ This library should be added to the OpenSource repository.
+
+ * CMakeLists.txt:
+
2017-11-06 Alex Christensen <achristen...@webkit.org>
Make ResourceLoader::willSendRequestInternal asynchronous
Modified: trunk/Source/WebKitLegacy/win/ChangeLog (224628 => 224629)
--- trunk/Source/WebKitLegacy/win/ChangeLog 2017-11-09 16:18:32 UTC (rev 224628)
+++ trunk/Source/WebKitLegacy/win/ChangeLog 2017-11-09 17:11:24 UTC (rev 224629)
@@ -1,3 +1,149 @@
+2017-11-06 Per Arne Vollan <pvol...@apple.com>
+
+ [Win] Add WebKitQuartzCoreAdditions library.
+ https://bugs.webkit.org/show_bug.cgi?id=179331
+
+ Reviewed by Alex Christensen.
+
+ * WebKitQuartzCoreAdditions: Added.
+ * WebKitQuartzCoreAdditions/API: Added.
+ * WebKitQuartzCoreAdditions/API/WKCACFImage.cpp: Added.
+ (toImage):
+ (WKCACFImageGetWidth):
+ (WKCACFImageGetHeight):
+ (WKCACFImageCopyFileMapping):
+ (WKCACFImageCreateWithImage):
+ (WKCACFImageFinalize):
+ (WKCACFImageCopyFormattingDescription):
+ (WKCACFImageCopyDebugDescription):
+ (WKCACFImageGetTypeID):
+ * WebKitQuartzCoreAdditions/API/WKCACFImage.h: Added.
+ * WebKitQuartzCoreAdditions/API/WKCACFImageInternal.h: Added.
+ * WebKitQuartzCoreAdditions/API/WKCACFView.cpp: Added.
+ (toView):
+ (toImpl):
+ (WKCACFViewCreate):
+ (WKCACFViewSetLayer):
+ (WKCACFViewUpdate):
+ (WKCACFViewFlushContext):
+ (WKCACFViewInvalidateRects):
+ (WKCACFViewCanDraw):
+ (WKCACFViewDraw):
+ (WKCACFViewCopyDrawnImage):
+ (WKCACFViewDrawIntoDC):
+ (contextDidChangeCallback):
+ (WKCACFViewSetContextDidChangeCallback):
+ (WKCACFViewGetLastCommitTime):
+ (WKCACFViewSetContextUserData):
+ (WKCACFViewGetContext):
+ (WKCACFViewFinalize):
+ (WKCACFViewCopyFormattingDescription):
+ (WKCACFViewCopyDebugDescription):
+ (WKCACFViewGetTypeID):
+ (WKCACFViewSetShouldInvertColors):
+ (WKCACFViewGetD3DDevice9):
+ * WebKitQuartzCoreAdditions/API/WKCACFView.h: Added.
+ * WebKitQuartzCoreAdditions/API/WKCACFViewPrivate.h: Added.
+ * WebKitQuartzCoreAdditions/API/WebKitQuartzCoreAdditions.cpp: Added.
+ (WKQCA::dllInstance):
+ (DllMain):
+ (WKCACFShutDown):
+ * WebKitQuartzCoreAdditions/API/WebKitQuartzCoreAdditionsBase.h: Added.
+ * WebKitQuartzCoreAdditions/CAD3DRenderer.cpp: Added.
+ (WKQCA::D3DPostProcessingContext::D3DPostProcessingContext):
+ (WKQCA::d3d):
+ (WKQCA::initialPresentationParameters):
+ (WKQCA::CAD3DRenderer::shared):
+ (WKQCA::CAD3DRenderer::CAD3DRenderer):
+ (WKQCA::CAD3DRenderer::swapChain):
+ (WKQCA::CAD3DRenderer::createD3DPostProcessingContext):
+ (WKQCA::hardwareCapabilitiesIndicateCoreAnimationSupport):
+ (WKQCA::CAD3DRenderer::initialize):
+ (WKQCA::D3DMatrixOrthoOffCenterRH):
+ (WKQCA::prepareDevice):
+ (WKQCA::updateBounds):
+ (WKQCA::CAD3DRenderer::renderAndPresent):
+ (WKQCA::CAD3DRenderer::renderToImage):
+ (WKQCA::CAD3DRenderer::setDeviceIsLost):
+ (WKQCA::CAD3DRenderer::renderInternal):
+ (WKQCA::CAD3DRenderer::postProcess):
+ (WKQCA::CAD3DRenderer::resetD3DDevice):
+ (WKQCA::CAD3DRenderer::createShaderIfNeeded):
+ (WKQCA::CAD3DRenderer::release):
+ * WebKitQuartzCoreAdditions/CAD3DRenderer.h: Added.
+ (WKQCA::D3DPostProcessingContext::sceneTexture const):
+ (WKQCA::D3DPostProcessingContext::overlayQuad const):
+ (WKQCA::CAD3DRenderer::d3dDevice9 const):
+ * WebKitQuartzCoreAdditions/CAView.cpp: Added.
+ (WKQCA::CAView::Handle::create):
+ (WKQCA::CAView::Handle::~Handle):
+ (WKQCA::CAView::Handle::mutex):
+ (WKQCA::CAView::Handle::view const):
+ (WKQCA::CAView::Handle::clear):
+ (WKQCA::CAView::Handle::Handle):
+ (WKQCA::globalStateMutex):
+ (WKQCA::registerMessageWindowClass):
+ (WKQCA::createMessageWindow):
+ (WKQCA::CAView::releaseAllD3DResources):
+ (WKQCA::CAView::CAView):
+ (WKQCA::CAView::~CAView):
+ (WKQCA::CAView::create):
+ (WKQCA::CAView::setContextDidChangeCallback):
+ (WKQCA::CAView::setLayer):
+ (WKQCA::CAView::update):
+ (WKQCA::CAView::invalidateRects):
+ (WKQCA::CAView::drawToWindow):
+ (WKQCA::CAView::drawToWindowInternal):
+ (WKQCA::CAView::drawToImage):
+ (WKQCA::CAView::willDraw):
+ (WKQCA::CAView::didDraw):
+ (WKQCA::CAView::drawIntoDC):
+ (WKQCA::CAView::setShouldInvertColors):
+ (WKQCA::CAView::scheduleNextDraw):
+ (WKQCA::CAView::displayLinkReachedCAMediaTime):
+ (WKQCA::CAView::contextDidChangeCallback):
+ (WKQCA::CAView::contextDidChange):
+ (WKQCA::CAView::updateSoon):
+ (WKQCA::CAView::updateViewsNow):
+ (WKQCA::CAView::d3dDevice9):
+ * WebKitQuartzCoreAdditions/CAView.h: Added.
+ (WKQCA::CAView::context const):
+ (WKQCA::CAView::canDraw const):
+ (WKQCA::CAView::ContextDidChangeCallback::ContextDidChangeCallback):
+ * WebKitQuartzCoreAdditions/CMakeLists.txt: Added.
+ * WebKitQuartzCoreAdditions/CVDisplayLink.cpp: Added.
+ (WKQCA::CVDisplayLink::CVDisplayLink):
+ (WKQCA::CVDisplayLink::~CVDisplayLink):
+ (WKQCA::CVDisplayLink::create):
+ (WKQCA::CVDisplayLink::start):
+ (WKQCA::CVDisplayLink::stop):
+ (WKQCA::CVDisplayLink::setPaused):
+ (WKQCA::CVDisplayLink::runIOThread):
+ * WebKitQuartzCoreAdditions/CVDisplayLink.h: Added.
+ * WebKitQuartzCoreAdditions/CVDisplayLinkClient.h: Added.
+ (WKQCA::CVDisplayLinkClient::~CVDisplayLinkClient):
+ * WebKitQuartzCoreAdditions/Image.cpp: Added.
+ (WKQCA::numBytesForSize):
+ (WKQCA::Image::create):
+ (WKQCA::Image::Image):
+ (WKQCA::Image::~Image):
+ (WKQCA::bitmapInfo):
+ (WKQCA::Image::createDIB const):
+ (WKQCA::Image::copyFileMapping):
+ * WebKitQuartzCoreAdditions/Image.h: Added.
+ (WKQCA::Image::size const):
+ * WebKitQuartzCoreAdditions/ImageConversion.cpp: Added.
+ (WKQCA::getBackBufferRectAsRenderTarget):
+ (WKQCA::getSystemMemoryCopy):
+ (WKQCA::copyRectToBitmap):
+ (WKQCA::getImageCopy):
+ (WKQCA::getBackBufferRectAsImage):
+ * WebKitQuartzCoreAdditions/ImageConversion.h: Added.
+ * WebKitQuartzCoreAdditions/InvertColorPS.hlsl: Added.
+ * WebKitQuartzCoreAdditions/WebKitQuartzCoreAdditionsInternal.h: Added.
+ * WebKitQuartzCoreAdditions/WebKitQuartzCoreAdditionsPrefix.cpp: Added.
+ * WebKitQuartzCoreAdditions/WebKitQuartzCoreAdditionsPrefix.h: Added.
+
2017-11-06 Christopher Reid <chris.r...@sony.com>
Use enum classes within FileSystem
Added: trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/API/WKCACFImage.cpp (0 => 224629)
--- trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/API/WKCACFImage.cpp (rev 0)
+++ trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/API/WKCACFImage.cpp 2017-11-09 17:11:24 UTC (rev 224629)
@@ -0,0 +1,98 @@
+/*
+* Copyright (C) 2017 Apple Inc. All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+* 1. Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in the
+* documentation and/or other materials provided with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+* THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include "WKCACFImage.h"
+
+#include "Image.h"
+#include "WKCACFImageInternal.h"
+#include <CoreFoundation/CFRuntime.h>
+#include <wtf/RefPtr.h>
+
+using namespace WKQCA;
+
+struct _WKCACFImage : public CFRuntimeBase {
+ RefPtr<Image> image;
+};
+
+static WKCACFImageRef toImage(CFTypeRef image)
+{
+ return static_cast<WKCACFImageRef>(const_cast<void*>(image));
+}
+
+size_t WKCACFImageGetWidth(WKCACFImageRef image)
+{
+ return image->image->size().cx;
+}
+
+size_t WKCACFImageGetHeight(WKCACFImageRef image)
+{
+ return image->image->size().cy;
+}
+
+HANDLE WKCACFImageCopyFileMapping(WKCACFImageRef image, size_t* fileMappingSize)
+{
+ return image->image->copyFileMapping(*fileMappingSize);
+}
+
+WKCACFImageRef WKCACFImageCreateWithImage(RefPtr<Image>&& image)
+{
+ WKCACFImageRef wrapper = toImage(_CFRuntimeCreateInstance(0, WKCACFImageGetTypeID(), sizeof(_WKCACFImage) - sizeof(CFRuntimeBase), 0));
+ wrapper->image = WTFMove(image);
+ return wrapper;
+}
+
+static void WKCACFImageFinalize(CFTypeRef image)
+{
+ toImage(image)->image = nullptr;
+}
+
+static CFStringRef WKCACFImageCopyFormattingDescription(CFTypeRef image, CFDictionaryRef options)
+{
+ return CFStringCreateWithFormat(CFGetAllocator(image), options, CFSTR("<WKCACFImage 0x%x>"), image);
+}
+
+static CFStringRef WKCACFImageCopyDebugDescription(CFTypeRef image)
+{
+ return WKCACFImageCopyFormattingDescription(image, 0);
+}
+
+CFTypeID WKCACFImageGetTypeID()
+{
+ static const CFRuntimeClass runtimeClass = {
+ 0,
+ "WKCACFImage",
+ 0,
+ 0,
+ WKCACFImageFinalize,
+ 0,
+ 0,
+ WKCACFImageCopyFormattingDescription,
+ WKCACFImageCopyDebugDescription,
+ 0
+ };
+
+ static CFTypeID id = _CFRuntimeRegisterClass(&runtimeClass);
+ return id;
+}
Added: trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/API/WKCACFImage.h (0 => 224629)
--- trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/API/WKCACFImage.h (rev 0)
+++ trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/API/WKCACFImage.h 2017-11-09 17:11:24 UTC (rev 224629)
@@ -0,0 +1,49 @@
+/*
+* Copyright (C) 2017 Apple Inc. All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+* 1. Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in the
+* documentation and/or other materials provided with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+* THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#pragma once
+
+#include <WebKitQuartzCoreAdditions/WebKitQuartzCoreAdditionsBase.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Returns the type identifier of all WKCACFImage instances. */
+WKQCA_EXPORT CFTypeID WKCACFImageGetTypeID(void);
+
+/* Return the dimensions of the image. */
+WKQCA_EXPORT size_t WKCACFImageGetWidth(WKCACFImageRef);
+WKQCA_EXPORT size_t WKCACFImageGetHeight(WKCACFImageRef);
+
+/* Returns a file mapping object which contains the bits of the image. (Note that this does not
+ * copy the bits; the returned file mapping object points to the same underlying bits that the
+ * image itself uses.) The bits are in the format of a top-down, 32-bit DIB. It is the caller's
+ * responsibility to destroy the file mapping via ::CloseHandle. */
+WKQCA_EXPORT HANDLE WKCACFImageCopyFileMapping(WKCACFImageRef, size_t* fileMappingSize);
+
+#ifdef __cplusplus
+}
+#endif
Added: trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/API/WKCACFImageInternal.h (0 => 224629)
--- trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/API/WKCACFImageInternal.h (rev 0)
+++ trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/API/WKCACFImageInternal.h 2017-11-09 17:11:24 UTC (rev 224629)
@@ -0,0 +1,34 @@
+/*
+* Copyright (C) 2017 Apple Inc. All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+* 1. Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in the
+* documentation and/or other materials provided with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+* THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#pragma once
+
+#include "WKCACFImage.h"
+
+namespace WKQCA {
+class Image;
+}
+
+WKCACFImageRef WKCACFImageCreateWithImage(RefPtr<WKQCA::Image>&&);
Added: trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/API/WKCACFView.cpp (0 => 224629)
--- trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/API/WKCACFView.cpp (rev 0)
+++ trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/API/WKCACFView.cpp 2017-11-09 17:11:24 UTC (rev 224629)
@@ -0,0 +1,181 @@
+/*
+* Copyright (C) 2017 Apple Inc. All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+* 1. Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in the
+* documentation and/or other materials provided with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+* THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include "WKCACFView.h"
+
+#include "CAView.h"
+#include "Image.h"
+#include "WKCACFImageInternal.h"
+#include <CoreFoundation/CFRuntime.h>
+
+using namespace WKQCA;
+
+struct _WKCACFView : public CFRuntimeBase {
+ RefPtr<CAView> view;
+ WKCACFViewContextDidChangeCallback callback;
+ void* info;
+};
+
+static WKCACFViewRef toView(CFTypeRef view)
+{
+ return static_cast<WKCACFViewRef>(const_cast<void*>(view));
+}
+
+static CAView::DrawingDestination toImpl(WKCACFViewDrawingDestination destination)
+{
+ switch (destination) {
+ case kWKCACFViewDrawingDestinationWindow:
+ return CAView::DrawingDestinationWindow;
+ case kWKCACFViewDrawingDestinationImage:
+ return CAView::DrawingDestinationImage;
+ };
+ ASSERT_NOT_REACHED();
+ return CAView::DrawingDestinationWindow;
+}
+
+WKCACFViewRef WKCACFViewCreate(WKCACFViewDrawingDestination destination)
+{
+ WKCACFViewRef view = toView(_CFRuntimeCreateInstance(0, WKCACFViewGetTypeID(), sizeof(_WKCACFView) - sizeof(CFRuntimeBase), 0));
+ view->view = CAView::create(toImpl(destination));
+ return view;
+}
+
+void WKCACFViewSetLayer(WKCACFViewRef view, CACFLayerRef layer)
+{
+ view->view->setLayer(layer);
+}
+
+void WKCACFViewUpdate(WKCACFViewRef view, HWND window, const CGRect* bounds)
+{
+ view->view->update(window, bounds ? *bounds : CGRectNull);
+}
+
+void WKCACFViewFlushContext(WKCACFViewRef view)
+{
+ CACFContextFlush(view->view->context());
+}
+
+void WKCACFViewInvalidateRects(WKCACFViewRef view, const CGRect rects[], size_t count)
+{
+ view->view->invalidateRects(rects, count);
+}
+
+bool WKCACFViewCanDraw(WKCACFViewRef view)
+{
+ return view->view->canDraw();
+}
+
+void WKCACFViewDraw(WKCACFViewRef view)
+{
+ view->view->drawToWindow();
+}
+
+WKCACFImageRef WKCACFViewCopyDrawnImage(WKCACFViewRef view, CGPoint* imageOrigin, CFTimeInterval* nextDrawTime)
+{
+ RefPtr<Image> image = view->view->drawToImage(*imageOrigin, *nextDrawTime);
+ if (!image)
+ return nullptr;
+ return WKCACFImageCreateWithImage(WTFMove(image));
+}
+
+void WKCACFViewDrawIntoDC(WKCACFViewRef view, HDC dc)
+{
+ view->view->drawIntoDC(dc);
+}
+
+static void contextDidChangeCallback(CAView* view, void* info)
+{
+ WKCACFViewRef wrapper = static_cast<WKCACFViewRef>(info);
+ ASSERT_ARG(view, view == wrapper->view);
+ ASSERT(wrapper->callback);
+ wrapper->callback(wrapper, wrapper->info);
+}
+
+void WKCACFViewSetContextDidChangeCallback(WKCACFViewRef view, WKCACFViewContextDidChangeCallback callback, void* info)
+{
+ view->callback = callback;
+ view->info = info;
+ view->view->setContextDidChangeCallback(callback ? contextDidChangeCallback : 0, view);
+}
+
+CFTimeInterval WKCACFViewGetLastCommitTime(WKCACFViewRef view)
+{
+ return CACFContextGetLastCommitTime(view->view->context());
+}
+
+void WKCACFViewSetContextUserData(WKCACFViewRef view, void* userData)
+{
+ CACFContextSetUserData(view->view->context(), userData);
+}
+
+CACFContextRef WKCACFViewGetContext(WKCACFViewRef view)
+{
+ return view->view->context();
+}
+
+static void WKCACFViewFinalize(CFTypeRef view)
+{
+ toView(view)->view = nullptr;
+}
+
+static CFStringRef WKCACFViewCopyFormattingDescription(CFTypeRef view, CFDictionaryRef options)
+{
+ return CFStringCreateWithFormat(CFGetAllocator(view), options, CFSTR("<WKCACFView 0x%x>"), view);
+}
+
+static CFStringRef WKCACFViewCopyDebugDescription(CFTypeRef view)
+{
+ return WKCACFViewCopyFormattingDescription(view, 0);
+}
+
+CFTypeID WKCACFViewGetTypeID()
+{
+ static const CFRuntimeClass runtimeClass = {
+ 0,
+ "WKCACFView",
+ 0,
+ 0,
+ WKCACFViewFinalize,
+ 0,
+ 0,
+ WKCACFViewCopyFormattingDescription,
+ WKCACFViewCopyDebugDescription,
+ 0
+ };
+
+ static CFTypeID id = _CFRuntimeRegisterClass(&runtimeClass);
+ return id;
+}
+
+void WKCACFViewSetShouldInvertColors(WKCACFViewRef view, bool shouldInvertColors)
+{
+ view->view->setShouldInvertColors(shouldInvertColors);
+}
+
+IDirect3DDevice9* WKCACFViewGetD3DDevice9(WKCACFViewRef view)
+{
+ return view->view->d3dDevice9();
+}
+
Added: trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/API/WKCACFView.h (0 => 224629)
--- trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/API/WKCACFView.h (rev 0)
+++ trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/API/WKCACFView.h 2017-11-09 17:11:24 UTC (rev 224629)
@@ -0,0 +1,120 @@
+/*
+* Copyright (C) 2017 Apple Inc. All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+* 1. Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in the
+* documentation and/or other materials provided with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+* THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#pragma once
+
+#include <QuartzCore/CoreAnimationCF.h>
+#include <WebKitQuartzCoreAdditions/WebKitQuartzCoreAdditionsBase.h>
+
+#ifndef WIN32_LEAN_AND_MEAN
+#define WKQCA_DEFINED_WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN
+#endif
+
+#include <d3d9.h>
+#include <windows.h>
+
+#ifdef WKQCA_DEFINED_WIN32_LEAN_AND_MEAN
+#undef WIN32_LEAN_AND_MEAN
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Returns the type identifier of all WKCACFView instances. */
+WKQCA_EXPORT CFTypeID WKCACFViewGetTypeID(void);
+
+enum WKCACFViewDrawingDestination {
+ /* Drawing is done directly into the window passed to WKCACFViewUpdate. Drawing occurs
+ * automatically and asynchronously after WKCACFViewFlushContext is called. Synchronous drawing
+ * can be achieved by calling WKCACFViewDraw. */
+ kWKCACFViewDrawingDestinationWindow = 0,
+
+ /* Drawing is done to an image in system memory. Drawing is manually driven by the caller via
+ * the WKCACFViewCopyDrawnImage API. The window passed to WKCACFViewUpdate is still used by
+ * Direct3D for message processing, but is not drawn into. */
+ kWKCACFViewDrawingDestinationImage,
+};
+typedef enum WKCACFViewDrawingDestination WKCACFViewDrawingDestination;
+
+/* Creates a new view object. */
+WKQCA_EXPORT WKCACFViewRef WKCACFViewCreate(WKCACFViewDrawingDestination);
+
+/* Sets the root layer being displayed by the view. */
+WKQCA_EXPORT void WKCACFViewSetLayer(WKCACFViewRef, CACFLayerRef);
+
+/* Sets the window associated with the view. The passed-in bounds
+ * should match the window's client rect. */
+WKQCA_EXPORT void WKCACFViewUpdate(WKCACFViewRef, HWND window, const CGRect* bounds);
+
+/* Commit all changes made to view and the layer tree it references to
+ * the render tree (i.e. to the screen). This function must be called
+ * after modifying any layer properties or adding any animations to
+ * have their effect be seen. */
+WKQCA_EXPORT void WKCACFViewFlushContext(WKCACFViewRef);
+
+/* Invalidates a region of the view, i.e. causes it to be redrawn the next
+ * time the view redraws anything. */
+WKQCA_EXPORT void WKCACFViewInvalidateRects(WKCACFViewRef, const CGRect rects[], size_t count);
+
+/* Returns true if it is possible for this view to draw into the window
+ * at this time. This can return false if, e.g., the system does not
+ * meet CoreAnimation's hardware requirements. */
+WKQCA_EXPORT bool WKCACFViewCanDraw(WKCACFViewRef);
+
+/* Renders the current region needing updating into the view's window. May only be called when the
+ * view was created with kWKCACFViewDrawingDestinationWindow. */
+WKQCA_EXPORT void WKCACFViewDraw(WKCACFViewRef);
+
+/* Renders the current region needing updating and returns it as an image. imageOrigin specifies
+ * the location within the view to which the image corresponds, relative to the bottom-left. May
+ * only be called when the view was created with kWKCACFViewDrawingDestinationImage. */
+WKQCA_EXPORT WKCACFImageRef WKCACFViewCopyDrawnImage(WKCACFViewRef, CGPoint* imageOrigin, CFTimeInterval* nextDrawTime);
+
+/* Renders the entire view into the device context. */
+WKQCA_EXPORT void WKCACFViewDrawIntoDC(WKCACFViewRef, HDC);
+
+/* Sets a function to be called whenever the view's root layer has changed and needs to be redrawn. */
+typedef void (*WKCACFViewContextDidChangeCallback)(WKCACFViewRef view, void* info);
+WKQCA_EXPORT void WKCACFViewSetContextDidChangeCallback(WKCACFViewRef, WKCACFViewContextDidChangeCallback, void* info);
+
+/* Returns the default beginTime of animations added as part of the
+ * previous transaction (i.e. the previous call to WKCACFViewFlushContext). */
+WKQCA_EXPORT CFTimeInterval WKCACFViewGetLastCommitTime(WKCACFViewRef);
+
+/* Allows for an arbitrary pointer to be associated with the view's context. */
+WKQCA_EXPORT void WKCACFViewSetContextUserData(WKCACFViewRef, void* userData);
+
+/* Set whether the view should invert colors when rendering */
+WKQCA_EXPORT void WKCACFViewSetShouldInvertColors(WKCACFViewRef, bool shouldInvertColors);
+
+/* Returns a pointer to the D3D device. The caller is responsible for retaining the object if
+ * it will be used after the function returns. */
+WKQCA_EXPORT IDirect3DDevice9* WKCACFViewGetD3DDevice9(WKCACFViewRef);
+
+#ifdef __cplusplus
+}
+#endif
Added: trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/API/WKCACFViewPrivate.h (0 => 224629)
--- trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/API/WKCACFViewPrivate.h (rev 0)
+++ trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/API/WKCACFViewPrivate.h 2017-11-09 17:11:24 UTC (rev 224629)
@@ -0,0 +1,38 @@
+/*
+* Copyright (C) 2017 Apple Inc. All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+* 1. Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in the
+* documentation and/or other materials provided with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+* THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#pragma once
+
+#include <WebKitQuartzCoreAdditions/WKCACFView.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+WKQCA_EXPORT CACFContextRef WKCACFViewGetContext(WKCACFViewRef);
+
+#ifdef __cplusplus
+}
+#endif
Added: trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/API/WebKitQuartzCoreAdditions.cpp (0 => 224629)
--- trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/API/WebKitQuartzCoreAdditions.cpp (rev 0)
+++ trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/API/WebKitQuartzCoreAdditions.cpp 2017-11-09 17:11:24 UTC (rev 224629)
@@ -0,0 +1,70 @@
+/*
+* Copyright (C) 2017 Apple Inc. All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+* 1. Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in the
+* documentation and/or other materials provided with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+* THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include "CAD3DRenderer.h"
+#include "WebKitQuartzCoreAdditionsBase.h"
+
+using namespace WKQCA;
+
+namespace WKQCA {
+
+static HINSTANCE instance;
+
+HINSTANCE dllInstance()
+{
+ return instance;
+}
+
+} // namespace WKQCA
+
+BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
+{
+ switch (fdwReason) {
+ case DLL_PROCESS_ATTACH:
+#if defined(_M_X64) || defined(__x86_64__)
+ // The VS2013 runtime has a bug where it mis-detects AVX-capable processors
+ // if the feature has been disabled in firmware. This causes us to crash
+ // in some of the math functions. For now, we disable those optimizations
+ // because Microsoft is not going to fix the problem in VS2013.
+ // FIXME: http://webkit.org/b/141449: Remove this workaround when we switch to VS2015+.
+ _set_FMA3_enable(0);
+#endif
+ instance = hinstDLL;
+ break;
+
+ case DLL_PROCESS_DETACH:
+ case DLL_THREAD_ATTACH:
+ case DLL_THREAD_DETACH:
+ ASSERT_ARG(hinstDLL, hinstDLL == instance);
+ break;
+ }
+
+ return TRUE;
+}
+
+void WKCACFShutDown()
+{
+ CAD3DRenderer::shared().release();
+}
Added: trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/API/WebKitQuartzCoreAdditionsBase.h (0 => 224629)
--- trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/API/WebKitQuartzCoreAdditionsBase.h (rev 0)
+++ trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/API/WebKitQuartzCoreAdditionsBase.h 2017-11-09 17:11:24 UTC (rev 224629)
@@ -0,0 +1,49 @@
+/*
+* Copyright (C) 2017 Apple Inc. All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+* 1. Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in the
+* documentation and/or other materials provided with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+* THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#pragma once
+
+#ifndef WKQCA_EXPORT
+#ifdef BUILDING_WKQCA
+#define WKQCA_EXPORT __declspec(dllexport)
+#else
+#define WKQCA_EXPORT __declspec(dllimport)
+#endif
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct _WKCACFImage* WKCACFImageRef;
+typedef struct _WKCACFView* WKCACFViewRef;
+
+/* Releases internal resources. Useful in combination with the debug Direct3D runtime's "Break on
+ Memory Leaks" feature. Must only be called after all WKCACFViews have been destroyed. */
+WKQCA_EXPORT void WKCACFShutDown(void);
+
+#ifdef __cplusplus
+}
+#endif
Added: trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/CAD3DRenderer.cpp (0 => 224629)
--- trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/CAD3DRenderer.cpp (rev 0)
+++ trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/CAD3DRenderer.cpp 2017-11-09 17:11:24 UTC (rev 224629)
@@ -0,0 +1,629 @@
+/*
+* Copyright (C) 2017 Apple Inc. All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+* 1. Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in the
+* documentation and/or other materials provided with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+* THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include "CAD3DRenderer.h"
+
+#include "Image.h"
+#include "ImageConversion.h"
+#include "InvertColorPS.h"
+#include <CoreGraphics/CGSRegion.h>
+#include <QuartzCore/CACFContext.h>
+#include <QuartzCore/CARenderOGL.h>
+#include <limits>
+#include <string>
+#include <wtf/RefPtr.h>
+
+// Define strings from the HLSL effect that are referenced later
+#define HLSL_TECHNIQUE "InvertColor"
+#define SCENE_TEXTURE "sceneTexture"
+
+typedef HRESULT (CALLBACK *LPFNDLL_Direct3DCreate9Ex)(UINT, void **);
+
+using namespace std;
+
+namespace WKQCA {
+
+static const DWORD customVertexFormat = D3DFVF_XYZRHW | D3DFVF_TEX1;
+
+D3DPostProcessingContext::D3DPostProcessingContext(const CComPtr<IDirect3DTexture9>& sceneTexture, const CComPtr<IDirect3DVertexBuffer9>& overlayQuad)
+ : m_sceneTexture(sceneTexture)
+ , m_overlayQuad(overlayQuad)
+{
+}
+
+static IDirect3D9* s_d3d;
+static IDirect3D9* d3d()
+{
+ static bool initialized;
+
+ if (initialized)
+ return s_d3d;
+ initialized = true;
+
+ HMODULE d3dLibHandle = LoadLibrary(TEXT("d3d9.dll"));
+ if (!d3dLibHandle)
+ return nullptr;
+
+ // AVFoundationCF requires us to create an IDirect3DDevice9Ex instead of an IDirect3DDevice9 for HW
+ // video decoding to work, because IDirect3DDevice9Ex::ResetEx() allows the HW decoder to persist
+ // during a reset, while IDirect3DDevice9::Reset() requires that the HW decoder be destroyed.
+ LPFNDLL_Direct3DCreate9Ex d3dCreate9Ex = (LPFNDLL_Direct3DCreate9Ex)GetProcAddress(d3dLibHandle, "Direct3DCreate9Ex");
+ if (d3dCreate9Ex) {
+ d3dCreate9Ex(D3D_SDK_VERSION, (void **)&s_d3d);
+
+ if (s_d3d) {
+ D3DCAPS9 caps;
+ HRESULT hr = s_d3d->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps);
+
+ // HW video decoding requires D3DCAPS2_DYNAMICTEXTURES, which not all d3d9 devices support,
+ // so fall back to plain old IDirect3DDevice9 if it isn't available.
+ if (!FAILED(hr) && (caps.Caps2 & D3DCAPS2_DYNAMICTEXTURES))
+ return s_d3d;
+
+ // Release the IDirect3DDevice9Ex, it doesn't have the features we require so we should
+ // allocate and use a plain old IDirect3D9.
+ s_d3d->Release();
+ }
+ }
+
+ s_d3d = Direct3DCreate9(D3D_SDK_VERSION);
+
+ return s_d3d;
+}
+
+static D3DPRESENT_PARAMETERS initialPresentationParameters(const CGSize& size)
+{
+ D3DPRESENT_PARAMETERS parameters = {0};
+ parameters.Windowed = TRUE;
+ parameters.SwapEffect = D3DSWAPEFFECT_COPY;
+ parameters.BackBufferCount = 1;
+ parameters.BackBufferFormat = D3DFMT_UNKNOWN;
+ parameters.BackBufferHeight = size.height;
+ parameters.BackBufferWidth = size.width;
+ parameters.MultiSampleType = D3DMULTISAMPLE_NONE;
+
+ return parameters;
+}
+
+CAD3DRenderer& CAD3DRenderer::shared()
+{
+ static CAD3DRenderer& shared = *new CAD3DRenderer;
+ return shared;
+}
+
+CAD3DRenderer::CAD3DRenderer()
+{
+}
+
+CComPtr<IDirect3DSwapChain9> CAD3DRenderer::swapChain(CWindow window, const CGSize& size)
+{
+ MutexLocker lock(m_mutex);
+
+ bool useDefaultSwapChain = false;
+
+ if (!m_d3dDevice) {
+ if (!initialize(window, size))
+ return nullptr;
+ ASSERT(m_d3dDevice);
+ // Since we used this window to initialize the device, the device's default swap chain
+ // should be associated with this window.
+ useDefaultSwapChain = true;
+ }
+
+ if (m_deviceIsLost) {
+ if (!resetD3DDevice(window, size))
+ return nullptr;
+ ASSERT(!m_deviceIsLost);
+ // Since we used this window to reset the device, the device's default swap chain should be
+ // associated with this window.
+ useDefaultSwapChain = true;
+ }
+
+ if (useDefaultSwapChain) {
+ CComPtr<IDirect3DSwapChain9> defaultSwapChain;
+ if (SUCCEEDED(m_d3dDevice->GetSwapChain(0, &defaultSwapChain))) {
+#if !ASSERT_DISABLED
+ // Since we just initialized or reset the device, its default swap chain should be
+ // associated with and sized to match this window.
+ D3DPRESENT_PARAMETERS parameters;
+ ASSERT(SUCCEEDED(defaultSwapChain->GetPresentParameters(¶meters)));
+ ASSERT(parameters.hDeviceWindow == window);
+ CRect clientRect;
+ ASSERT(window.GetClientRect(clientRect));
+ ASSERT(parameters.BackBufferHeight == clientRect.Height());
+ ASSERT(parameters.BackBufferWidth == clientRect.Width());
+#endif
+ return defaultSwapChain;
+ }
+ }
+
+ D3DPRESENT_PARAMETERS parameters = initialPresentationParameters(size);
+ parameters.hDeviceWindow = window;
+
+ CComPtr<IDirect3DSwapChain9> result;
+ if (FAILED(m_d3dDevice->CreateAdditionalSwapChain(¶meters, &result)))
+ return nullptr;
+
+ return result;
+}
+
+struct CustomVertex {
+ // position
+ float x;
+ float y;
+ float z;
+ float rhw; // indicates that the position is already transformed to screen coordinates
+
+ // texture coordinates
+ float tu;
+ float tv;
+};
+
+std::unique_ptr<D3DPostProcessingContext> CAD3DRenderer::createD3DPostProcessingContext(IDirect3DSwapChain9* swapChain, const CGSize& size)
+{
+ ASSERT_ARG(swapChain, swapChain);
+
+ // Get the back buffer format of the swap chain; we want to create the scene texture using the same format.
+ D3DPRESENT_PARAMETERS swapChainParameters;
+ if (FAILED(swapChain->GetPresentParameters(&swapChainParameters)))
+ return nullptr;
+
+ // FIXME: We should fall back to software rendering if CreateTexture() returns D3DERR_OUTOFVIDEOMEMORY.
+ CComPtr<IDirect3DTexture9> sceneTexture;
+ HRESULT hr = m_d3dDevice->CreateTexture(size.width, size.height, 1, D3DUSAGE_RENDERTARGET, swapChainParameters.BackBufferFormat, D3DPOOL_DEFAULT, &sceneTexture, 0);
+ if (FAILED(hr)) {
+ ASSERT(hr != D3DERR_OUTOFVIDEOMEMORY);
+ return nullptr;
+ }
+
+ // Create a quad in screen coordinates onto which sceneTexture will be
+ // applied. In D3D, pixels are referenced from the center of a 1x1 cell, so
+ // to properly encapsulate the cell we need to offset the quad boundaries by
+ // 0.5 pixels.
+ const float left = -0.5;
+ const float right = size.width - 0.5;
+ const float top = -0.5;
+ const float bottom = size.height - 0.5;
+ const float z = 1;
+ const float rhw = 1;
+ CustomVertex overlayQuadVertices[4] = {
+ { left, top, z, rhw, 0, 0 },
+ { right, top, z, rhw, 1, 0 },
+ { left, bottom, z, rhw, 0, 1 },
+ { right, bottom, z, rhw, 1, 1 }
+ };
+
+ CComPtr<IDirect3DVertexBuffer9> overlayQuad;
+ if (FAILED(m_d3dDevice->CreateVertexBuffer(sizeof(overlayQuadVertices), D3DUSAGE_WRITEONLY, customVertexFormat, D3DPOOL_DEFAULT, &overlayQuad, 0)))
+ return nullptr;
+
+ void* overlayQuadBuffer;
+ if (FAILED(overlayQuad->Lock(0, 0, &overlayQuadBuffer, 0)))
+ return nullptr;
+
+ memcpy(overlayQuadBuffer, overlayQuadVertices, sizeof(overlayQuadVertices));
+ overlayQuad->Unlock();
+
+ return std::make_unique<D3DPostProcessingContext>(sceneTexture, overlayQuad);
+}
+
+// FIXME: <rdar://6507851> Share this code with CoreAnimation's
+// CA::OGL::DX9Context::update function.
+static bool hardwareCapabilitiesIndicateCoreAnimationSupport(const D3DCAPS9& caps)
+{
+ // CoreAnimation needs two or more texture units.
+ if (caps.MaxTextureBlendStages < 2)
+ return false;
+
+ // CoreAnimation needs non-power-of-two textures.
+ if ((caps.TextureCaps & D3DPTEXTURECAPS_POW2) && !(caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL))
+ return false;
+
+ // CoreAnimation needs vertex shader 2.0 or greater.
+ if (D3DSHADER_VERSION_MAJOR(caps.VertexShaderVersion) < 2)
+ return false;
+
+ // CoreAnimation needs pixel shader 2.0 or greater.
+ if (D3DSHADER_VERSION_MAJOR(caps.PixelShaderVersion) < 2)
+ return false;
+
+ return true;
+}
+
+bool CAD3DRenderer::initialize(CWindow window, const CGSize& size)
+{
+#if !ASSERT_DISABLED
+ if (!m_deviceThreadID)
+ m_deviceThreadID = ::GetCurrentThreadId();
+ // MSDN says that IDirect3D9::CreateDevice must "be called from the same thread that handles
+ // window messages." <http://msdn.microsoft.com/en-us/library/bb147224(VS.85).aspx>.
+ ASSERT(::GetCurrentThreadId() == m_deviceThreadID);
+ ASSERT(::GetCurrentThreadId() == window.GetWindowThreadID());
+#endif
+
+ if (m_initialized)
+ return m_d3dDevice;
+ m_initialized = true;
+
+ if (!d3d())
+ return false;
+
+ D3DCAPS9 d3dCaps;
+ if (FAILED(d3d()->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &d3dCaps)))
+ return false;
+
+ DWORD behaviorFlags = D3DCREATE_FPU_PRESERVE | D3DCREATE_MULTITHREADED;
+ if ((d3dCaps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) && d3dCaps.VertexProcessingCaps)
+ behaviorFlags |= D3DCREATE_HARDWARE_VERTEXPROCESSING;
+ else
+ behaviorFlags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING;
+
+ D3DPRESENT_PARAMETERS parameters = initialPresentationParameters(size);
+ parameters.hDeviceWindow = window;
+
+ CComPtr<IDirect3DDevice9> device;
+ CComQIPtr<IDirect3D9Ex> d3d9Ex = d3d();
+ HRESULT hr;
+
+ if (d3d9Ex)
+ hr = d3d9Ex->CreateDeviceEx(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, 0, behaviorFlags, ¶meters, 0, (IDirect3DDevice9Ex **)&device);
+ else
+ hr = s_d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, 0, behaviorFlags, ¶meters, &device);
+ if (FAILED(hr))
+ return false;
+
+ // Now that we've created the IDirect3DDevice9 based on the capabilities we
+ // got from the IDirect3D9 global object, we requery the device for its
+ // actual capabilities. The capabilities returned by the device can
+ // sometimes be more complete, for example when using software vertex
+ // processing.
+ D3DCAPS9 deviceCaps;
+ if (FAILED(device->GetDeviceCaps(&deviceCaps)))
+ return false;
+
+ if (!hardwareCapabilitiesIndicateCoreAnimationSupport(deviceCaps))
+ return false;
+
+ m_d3dDevice.Attach(device.Detach());
+ m_usingDirect3D9Ex = d3d9Ex;
+ m_renderOGLContext = CARenderOGLNew(&kCARenderDX9Callbacks, m_d3dDevice, 0);
+
+ return true;
+}
+
+static void D3DMatrixOrthoOffCenterRH(D3DMATRIX* pOut, float l, float r, float b, float t, float zn, float zf)
+{
+ pOut->_11 = 2 / (r-l);
+ pOut->_12 = 0;
+ pOut->_13 = 0;
+ pOut->_14 = 0;
+
+ pOut->_21 = 0;
+ pOut->_22 = 2 / (t-b);
+ pOut->_23 = 0;
+ pOut->_24 = 0;
+
+ pOut->_31 = 0;
+ pOut->_32 = 0;
+ pOut->_33 = 1 / (zn-zf);
+ pOut->_34 = 0;
+
+ pOut->_41 = (l+r) / (l-r);
+ pOut->_42 = (t+b) / (b-t);
+ pOut->_43 = zn / (zn-zf);
+ pOut->_44 = 1;
+}
+
+static bool prepareDevice(IDirect3DDevice9* device, const CGRect& bounds, IDirect3DSwapChain9* swapChain, D3DPostProcessingContext* postProcessingContext)
+{
+ CComPtr<IDirect3DSurface9> backBuffer;
+
+ // If we will post-process the scene, we want to render to the scene texture rather than the back buffer.
+ if (postProcessingContext) {
+ if (FAILED(postProcessingContext->sceneTexture()->GetSurfaceLevel(0, &backBuffer)))
+ return false;
+ } else {
+ if (FAILED(swapChain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &backBuffer)))
+ return false;
+ }
+
+ CComPtr<IDirect3DSurface9> currentRenderTarget;
+ if (FAILED(device->GetRenderTarget(0, ¤tRenderTarget)))
+ return false;
+
+ if (backBuffer != currentRenderTarget && FAILED(device->SetRenderTarget(0, backBuffer)))
+ return false;
+
+ float x0 = bounds.origin.x;
+ float y0 = bounds.origin.y;
+ float x1 = x0 + bounds.size.width;
+ float y1 = y0 + bounds.size.height;
+
+ D3DMATRIX projection;
+ D3DMatrixOrthoOffCenterRH(&projection, x0, x1, y0, y1, -1.0f, 1.0f);
+
+ if (FAILED(device->SetTransform(D3DTS_PROJECTION, &projection)))
+ return false;
+
+ return true;
+}
+
+static CGRect updateBounds(CARenderUpdate* update)
+{
+ CGSRegionObj rgn = CARenderUpdateCopyRegion(update);
+ if (!rgn)
+ return CGRectZero;
+
+ CGRect result;
+ CGError error = CGSGetRegionBounds(rgn, &result);
+ CGSReleaseRegion(rgn);
+
+ return error == kCGErrorSuccess ? result : CGRectZero;
+}
+
+CAD3DRenderer::RenderResult CAD3DRenderer::renderAndPresent(const CGRect& bounds, IDirect3DSwapChain9* swapChain, D3DPostProcessingContext* postProcessingContext, CACFContextRef context, CFTimeInterval& nextRenderTime)
+{
+ ASSERT_ARG(swapChain, swapChain);
+ ASSERT_ARG(context, context);
+
+ MutexLocker lock(m_mutex);
+
+ CGRect unusedDirtyRect;
+ RenderResult result = renderInternal(bounds, swapChain, postProcessingContext, context, unusedDirtyRect, nextRenderTime);
+ switch (result) {
+ case DeviceBecameLost:
+ ASSERT_NOT_REACHED();
+ case DeviceIsLost:
+ case OtherFailure:
+ return result;
+ case NoRenderingRequired:
+ case Success:
+ break;
+ }
+
+ // Note that we only use the bounds size, not its origin, when deciding where in the
+ // window to render. As with NSViews, the bounds origin determines where content is
+ // positioned within the view, not where the view is positioned in its parent.
+ CRect destinationRect(0, 0, CGRectGetWidth(bounds), CGRectGetHeight(bounds));
+
+ // FIXME: Passing a pDirtyRegion based on the CARenderUpdate's dirty region to
+ // IDirect3DSwapChain9::Present might increase performance.
+ if (swapChain->Present(0, destinationRect, 0, 0, 0) != D3DERR_DEVICELOST)
+ return Success;
+
+ // The device was lost. Record that this happened so that we'll try to reset it before
+ // we try to create a new swap chain.
+ setDeviceIsLost(true);
+
+ // We can't render until the device is reset, which the caller will have to take care of.
+ nextRenderTime = numeric_limits<CFTimeInterval>::infinity();
+
+ return DeviceBecameLost;
+}
+
+CAD3DRenderer::RenderResult CAD3DRenderer::renderToImage(const CGRect& bounds, IDirect3DSwapChain9* swapChain, D3DPostProcessingContext* postProcessingContext, CACFContextRef context, RefPtr<Image>& outImage, CGPoint& imageOrigin, CFTimeInterval& nextRenderTime)
+{
+ ASSERT_ARG(swapChain, swapChain);
+ ASSERT_ARG(context, context);
+
+ MutexLocker lock(m_mutex);
+
+ CGRect dirtyRect;
+ RenderResult result = renderInternal(bounds, swapChain, postProcessingContext, context, dirtyRect, nextRenderTime);
+ switch (result) {
+ case DeviceBecameLost:
+ ASSERT_NOT_REACHED();
+ case DeviceIsLost:
+ case OtherFailure:
+ case NoRenderingRequired:
+ return result;
+ case Success:
+ break;
+ }
+
+ ASSERT(!CGRectIsEmpty(dirtyRect));
+
+ dirtyRect = CGRectIntersection(dirtyRect, bounds);
+ CRect dirtyWinRect(CPoint(CGRectGetMinX(dirtyRect), CGRectGetHeight(bounds) - CGRectGetMaxY(dirtyRect)), CSize(CGRectGetWidth(dirtyRect), CGRectGetHeight(dirtyRect)));
+
+ RefPtr<Image> image;
+ HRESULT hr = getBackBufferRectAsImage(m_d3dDevice, swapChain, dirtyWinRect, image);
+ if (SUCCEEDED(hr)) {
+ outImage = WTFMove(image);
+ imageOrigin = dirtyRect.origin;
+ return Success;
+ }
+
+ if (hr != D3DERR_DEVICELOST)
+ return OtherFailure;
+
+ // The device was lost. Record that this happened so that we'll try to reset it before
+ // we try to create a new swap chain.
+ setDeviceIsLost(true);
+
+ // We can't render until the device is reset, which the caller will have to take care of.
+ nextRenderTime = numeric_limits<CFTimeInterval>::infinity();
+
+ return DeviceBecameLost;
+}
+
+void CAD3DRenderer::setDeviceIsLost(bool lost)
+{
+ ASSERT_WITH_MESSAGE(!m_mutex.tryLock(), "m_mutex must be held when calling this function");
+
+ if (m_deviceIsLost == lost)
+ return;
+
+ m_deviceIsLost = lost;
+
+ if (!m_deviceIsLost)
+ return;
+
+ // We have to release any existing D3D resources before we try to reset the device.
+ // We'll reallocate them as needed. See
+ // <http://msdn.microsoft.com/en-us/library/bb174425(v=VS.85).aspx>.
+
+ // This will cause CA to release its D3D resources.
+ CARenderOGLPurge(m_renderOGLContext);
+}
+
+CAD3DRenderer::RenderResult CAD3DRenderer::renderInternal(const CGRect& bounds, IDirect3DSwapChain9* swapChain, D3DPostProcessingContext* postProcessingContext, CACFContextRef context, CGRect& dirtyRect, CFTimeInterval& nextRenderTime)
+{
+ ASSERT_ARG(swapChain, swapChain);
+ ASSERT_ARG(context, context);
+
+ ASSERT_WITH_MESSAGE(!m_mutex.tryLock(), "m_mutex must be held when calling this function");
+ ASSERT(m_d3dDevice);
+ ASSERT(m_renderOGLContext);
+
+ nextRenderTime = numeric_limits<CFTimeInterval>::infinity();
+
+ if (m_deviceIsLost)
+ return DeviceIsLost;
+
+ if (!prepareDevice(m_d3dDevice, bounds, swapChain, postProcessingContext))
+ return OtherFailure;
+
+ char space[4096];
+ CARenderUpdate* u = CARenderUpdateBegin(space, sizeof(space), CACurrentMediaTime(), 0, 0, &bounds);
+ if (!u)
+ return OtherFailure;
+
+ CARenderContext* renderContext = static_cast<CARenderContext*>(CACFContextGetRenderContext(context));
+ CARenderContextLock(renderContext);
+ CARenderUpdateAddContext(u, renderContext);
+ CARenderContextUnlock(renderContext);
+
+ nextRenderTime = CARenderUpdateGetNextTime(u);
+
+ bool didRender = false;
+
+ dirtyRect = updateBounds(u);
+ if (!CGRectIsEmpty(dirtyRect)) {
+ m_d3dDevice->BeginScene();
+ CARenderOGLRender(m_renderOGLContext, u);
+ if (postProcessingContext)
+ postProcess(bounds, swapChain, postProcessingContext);
+ m_d3dDevice->EndScene();
+ didRender = true;
+ }
+
+ CARenderUpdateFinish(u);
+
+ return didRender ? Success : NoRenderingRequired;
+}
+
+void CAD3DRenderer::postProcess(const CGRect& bounds, IDirect3DSwapChain9* swapChain, D3DPostProcessingContext* context)
+{
+ // The scene has been rendered to the scene texture, so now draw a quad to
+ // the back buffer and apply the scene texture to the quad with the
+ // InvertColor HLSL technique.
+
+ ASSERT_ARG(swapChain, swapChain);
+ ASSERT_ARG(context, context);
+
+ CComPtr<IDirect3DSurface9> backBuffer;
+ if (FAILED(swapChain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &backBuffer)))
+ return;
+
+ if (FAILED(m_d3dDevice->SetRenderTarget(0, backBuffer)))
+ return;
+
+ if (FAILED(m_d3dDevice->SetFVF(customVertexFormat)))
+ return;
+
+ if (FAILED(m_d3dDevice->SetStreamSource(0, context->overlayQuad(), 0, sizeof(CustomVertex))))
+ return;
+
+ createShaderIfNeeded();
+
+ m_d3dDevice->SetTexture(0, context->sceneTexture());
+ m_d3dDevice->SetPixelShader(m_pixelShader);
+ m_d3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
+ m_d3dDevice->SetPixelShader(nullptr);
+}
+
+bool CAD3DRenderer::resetD3DDevice(CWindow window, const CGSize& size)
+{
+ ASSERT(m_d3dDevice);
+ ASSERT(m_renderOGLContext);
+ ASSERT(m_deviceIsLost);
+
+ // MSDN says that IDirect3DDevice9::Reset must "be called from the same thread that handles
+ // window messages." <http://msdn.microsoft.com/en-us/library/bb147224(VS.85).aspx>.
+ ASSERT(::GetCurrentThreadId() == m_deviceThreadID);
+ ASSERT(::GetCurrentThreadId() == window.GetWindowThreadID());
+
+ HRESULT hr = m_d3dDevice->TestCooperativeLevel();
+
+ if (hr == D3DERR_DEVICELOST || hr == D3DERR_DRIVERINTERNALERROR) {
+ // The device cannot be reset at this time. We'll try again later.
+ return false;
+ }
+
+ setDeviceIsLost(false);
+
+ if (hr == D3D_OK) {
+ // The device wasn't lost after all.
+ return true;
+ }
+
+ // We can reset the device.
+
+ D3DPRESENT_PARAMETERS parameters = initialPresentationParameters(size);
+ parameters.hDeviceWindow = window;
+ if (m_usingDirect3D9Ex) {
+ CComQIPtr<IDirect3DDevice9Ex> d3d9Ex = m_d3dDevice;
+ ASSERT(d3d9Ex);
+ hr = d3d9Ex->ResetEx(¶meters, nullptr);
+ } else
+ hr = m_d3dDevice->Reset(¶meters);
+
+ // TestCooperativeLevel told us the device may be reset now, so we should
+ // not be told here that the device is lost.
+ ASSERT(hr != D3DERR_DEVICELOST);
+
+ return true;
+}
+
+
+void CAD3DRenderer::createShaderIfNeeded()
+{
+ if (m_pixelShader)
+ return;
+
+ m_d3dDevice->CreatePixelShader(reinterpret_cast<const DWORD*>(g_ps20_InvertColorPS), &m_pixelShader);
+}
+
+void CAD3DRenderer::release()
+{
+ if (m_renderOGLContext)
+ CARenderOGLDestroy(m_renderOGLContext);
+ m_d3dDevice = nullptr;
+ if (s_d3d)
+ s_d3d->Release();
+}
+
+} // namespace WKQCA
Added: trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/CAD3DRenderer.h (0 => 224629)
--- trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/CAD3DRenderer.h (rev 0)
+++ trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/CAD3DRenderer.h 2017-11-09 17:11:24 UTC (rev 224629)
@@ -0,0 +1,115 @@
+/*
+* Copyright (C) 2017 Apple Inc. All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+* 1. Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in the
+* documentation and/or other materials provided with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+* THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#pragma once
+
+#include <d3d9.h>
+#include <wtf/Forward.h>
+#include <wtf/Noncopyable.h>
+
+struct IDirect3DDevice9;
+struct IDirect3DPixelShader9;
+struct IDirect3DSwapChain9;
+struct IDirect3DTexture9;
+struct IDirect3DVertexBuffer9;
+typedef struct _CACFContext* CACFContextRef;
+typedef struct _CARenderOGLContext CARenderOGLContext;
+
+namespace WKQCA {
+
+class Image;
+
+class D3DPostProcessingContext {
+public:
+ D3DPostProcessingContext(const CComPtr<IDirect3DTexture9>&, const CComPtr<IDirect3DVertexBuffer9>&);
+
+ IDirect3DTexture9* sceneTexture() const { return m_sceneTexture; }
+ IDirect3DVertexBuffer9* overlayQuad() const { return m_overlayQuad; }
+
+private:
+ CComPtr<IDirect3DTexture9> m_sceneTexture;
+ CComPtr<IDirect3DVertexBuffer9> m_overlayQuad;
+};
+
+class CAD3DRenderer {
+ WTF_MAKE_NONCOPYABLE(CAD3DRenderer);
+public:
+ static CAD3DRenderer& shared();
+
+ // Returns a swap chain that can be used to render into the given window. The swap chain's
+ // buffers' dimensions match the passed-in size. If necessary, this function will create or
+ // reset the D3D device.
+ CComPtr<IDirect3DSwapChain9> swapChain(CWindow, const CGSize&);
+
+ // Creates a context used by CAD3DRenderer to post-process the rendered scene.
+ // The only post-processing effect currently supported is color inversion.
+ // This method returns nullptr if no post-processing is to be applied.
+ std::unique_ptr<D3DPostProcessingContext> createD3DPostProcessingContext(IDirect3DSwapChain9*, const CGSize&);
+
+ enum RenderResult { DeviceBecameLost, DeviceIsLost, OtherFailure, NoRenderingRequired, Success };
+
+ // Call these functions to render the given context into the given swap chain's back buffer.
+ // renderAndPresent then presents the back buffer to the screen, while renderToImage copies the
+ // updated region to a system-memory Image. nextRenderTime is set to the CAMediaTime at which
+ // the context needs to be rendered again (or infinity, if no further rendering is required or
+ // the device has entered the lost state).
+ RenderResult renderAndPresent(const CGRect& bounds, IDirect3DSwapChain9*, D3DPostProcessingContext*, CACFContextRef, CFTimeInterval& nextRenderTime);
+ RenderResult renderToImage(const CGRect& bounds, IDirect3DSwapChain9*, D3DPostProcessingContext*, CACFContextRef, RefPtr<Image>&, CGPoint& imageOrigin, CFTimeInterval& nextRenderTime);
+
+ // Call this when the process is exiting to prevent the debug Direct3D runtime from reporting
+ // memory leaks. Calling it when the release Direct3D runtime is being used is harmless (other
+ // than some unknown performance cost).
+ void release();
+
+ CComPtr<IDirect3DDevice9> d3dDevice9() const { return m_d3dDevice; }
+
+private:
+ CAD3DRenderer();
+ ~CAD3DRenderer();
+
+ bool initialize(CWindow, const CGSize&);
+
+ RenderResult renderInternal(const CGRect& bounds, IDirect3DSwapChain9*, D3DPostProcessingContext*, CACFContextRef, CGRect& dirtyRect, CFTimeInterval& nextRenderTime);
+ void postProcess(const CGRect&, IDirect3DSwapChain9*, D3DPostProcessingContext*);
+
+ void setDeviceIsLost(bool);
+ bool resetD3DDevice(CWindow, const CGSize&);
+
+ void createShaderIfNeeded();
+
+ Mutex m_mutex;
+ CComPtr<IDirect3DDevice9> m_d3dDevice;
+ CARenderOGLContext* m_renderOGLContext { nullptr };
+ CComPtr<IDirect3DPixelShader9> m_pixelShader;
+#if !ASSERT_DISABLED
+ DWORD m_deviceThreadID { 0 };
+#endif
+ bool m_initialized { false };
+ bool m_deviceIsLost { false };
+ bool m_invertsColors { false };
+ bool m_usingDirect3D9Ex { false };
+};
+
+} // namespace WKQCA
Added: trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/CAView.cpp (0 => 224629)
--- trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/CAView.cpp (rev 0)
+++ trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/CAView.cpp 2017-11-09 17:11:24 UTC (rev 224629)
@@ -0,0 +1,578 @@
+/*
+* Copyright (C) 2017 Apple Inc. All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+* 1. Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in the
+* documentation and/or other materials provided with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+* THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include "CAView.h"
+
+#include "CVDisplayLink.h"
+#include "Image.h"
+#include "WebKitQuartzCoreAdditionsInternal.h"
+#include <QuartzCore/CACFContext.h>
+#include <QuartzCore/CACFLayer.h>
+#include <QuartzCore/CARenderOGL.h>
+#include <d3d9.h>
+#include <wtf/HashSet.h>
+#include <wtf/StdLibExtras.h>
+#include <wtf/Vector.h>
+#include <wtf/win/GDIObject.h>
+
+using namespace std;
+
+namespace WKQCA {
+
+class CAView::Handle : public ThreadSafeRefCounted<Handle> {
+public:
+ static RefPtr<Handle> create(CAView* view) { return adoptRef(new Handle(view)); }
+ ~Handle() { ASSERT(!m_view); }
+
+ Mutex& mutex() { return m_mutex; }
+ CAView* view() const { ASSERT_WITH_MESSAGE(!const_cast<Mutex&>(m_mutex).tryLock(), "CAView::Handle's mutex must be held when calling this function"); return m_view; }
+ void clear() { ASSERT_WITH_MESSAGE(!m_mutex.tryLock(), "CAView::Handle's mutex must be held when calling this function"); m_view = 0; }
+
+private:
+ Handle(CAView* view)
+ : m_view(view) { }
+
+ Mutex m_mutex;
+ CAView* m_view;
+};
+
+static Mutex& globalStateMutex()
+{
+ DEPRECATED_DEFINE_STATIC_LOCAL(Mutex, mutex, ());
+ return mutex;
+}
+
+static HWND messageWindow;
+static const wchar_t messageWindowClassName[] = L"CAViewMessageWindow";
+
+static HashSet<RefPtr<CAView::Handle> >& views()
+{
+ DEPRECATED_DEFINE_STATIC_LOCAL(HashSet<RefPtr<CAView::Handle> >, views, ());
+ return views;
+}
+
+static HashSet<RefPtr<CAView::Handle> >& viewsNeedingUpdate()
+{
+ DEPRECATED_DEFINE_STATIC_LOCAL(HashSet<RefPtr<CAView::Handle> >, views, ());
+ return views;
+}
+
+static void registerMessageWindowClass()
+{
+ static bool didRegister;
+ if (didRegister)
+ return;
+ didRegister = true;
+
+ WNDCLASSW cls = {0};
+ cls.hInstance = dllInstance();
+ cls.lpfnWndProc = ::DefWindowProcW;
+ cls.lpszClassName = messageWindowClassName;
+ ::RegisterClassW(&cls);
+}
+
+static HWND createMessageWindow()
+{
+ registerMessageWindowClass();
+ return ::CreateWindowW(messageWindowClassName, 0, 0, 0, 0, 0, 0, HWND_MESSAGE, 0, 0, 0);
+}
+
+void CAView::releaseAllD3DResources()
+{
+ DEPRECATED_DEFINE_STATIC_LOCAL(Mutex, mutex, ());
+
+ if (!mutex.tryLock()) {
+ // Another thread is currently releasing 3D resources.
+ // Since it will also release resources for the view calling this method, we can just return early.
+ return;
+ }
+
+ Vector<RefPtr<Handle>> viewsToRelease;
+
+ {
+ MutexLocker lock(globalStateMutex());
+ viewsToRelease = copyToVector(views());
+ }
+
+ for (size_t i = 0; i < viewsToRelease.size(); ++i) {
+ const RefPtr<Handle>& handle = viewsToRelease[i];
+ MutexLocker lock(handle->mutex());
+ CAView* view = handle->view();
+ if (!view)
+ continue;
+ MutexLocker viewLock(view->m_mutex);
+ view->m_swapChain = nullptr;
+ view->m_d3dPostProcessingContext = nullptr;
+ }
+
+ mutex.unlock();
+}
+
+inline CAView::CAView(DrawingDestination destination)
+ : m_destination(destination)
+ , m_handle(Handle::create(this))
+ , m_context(adoptCF(CACFContextCreate(0)))
+ , m_bounds(CGRectZero)
+{
+ {
+ MutexLocker lock(globalStateMutex());
+ views().add(m_handle);
+ }
+
+ CARenderNotificationAddObserver(kCARenderContextDidChange, CACFContextGetRenderContext(m_context.get()), contextDidChangeCallback, this);
+}
+
+CAView::~CAView()
+{
+ CARenderNotificationRemoveObserver(kCARenderContextDidChange, CACFContextGetRenderContext(m_context.get()), contextDidChangeCallback, this);
+
+ m_layer = nullptr;
+
+ {
+ MutexLocker lock(m_mutex);
+ m_context = nullptr;
+ }
+
+ // Avoid stopping the display link while we hold either m_mutex or m_displayLinkMutex, as doing
+ // so will wait for displayLinkReachedCAMediaTime to return and that function can take those
+ // same mutexes.
+ RefPtr<CVDisplayLink> linkToStop;
+
+ {
+ MutexLocker lock(m_displayLinkMutex);
+ linkToStop = WTFMove(m_displayLink);
+ }
+
+ if (linkToStop)
+ linkToStop->stop();
+
+ update(nullptr, CGRectZero);
+
+ {
+ MutexLocker lock(m_handle->mutex());
+ m_handle->clear();
+ }
+
+ MutexLocker lock(globalStateMutex());
+
+ views().remove(m_handle);
+ if (!views().isEmpty())
+ return;
+
+ ::DestroyWindow(messageWindow);
+ messageWindow = nullptr;
+}
+
+RefPtr<CAView> CAView::create(DrawingDestination destination)
+{
+ return adoptRef(new CAView(destination));
+}
+
+void CAView::setContextDidChangeCallback(ContextDidChangeCallbackFunction function, void* info)
+{
+ m_contextDidChangeCallback.function = function;
+ m_contextDidChangeCallback.info = info;
+}
+
+void CAView::setLayer(CACFLayerRef layer)
+{
+ m_layer = layer;
+
+ if (!m_layer)
+ return;
+
+ CACFLayerSetFrame(m_layer.get(), m_bounds);
+
+ MutexLocker lock(m_mutex);
+ CACFContextSetLayer(m_context.get(), m_layer.get());
+}
+
+void CAView::update(CWindow window, const CGRect& bounds)
+{
+ {
+ MutexLocker lock(globalStateMutex());
+
+ // Ensure our message window is created on the thread that called CAView::update.
+ if (!messageWindow)
+ messageWindow = createMessageWindow();
+
+ // CAView::update may only be called from a single thread, and that thread must be the same as
+ // the window's thread (due to limitations of the D3D API).
+ ASSERT(::GetCurrentThreadId() == CWindow(messageWindow).GetWindowThreadID());
+ ASSERT(!window || ::GetCurrentThreadId() == window.GetWindowThreadID());
+
+ viewsNeedingUpdate().remove(m_handle);
+ }
+
+ bool boundsChanged;
+
+ {
+ MutexLocker lock(m_mutex);
+
+ boundsChanged = !CGRectEqualToRect(m_bounds, bounds);
+
+ if (m_window == window && !boundsChanged && !m_flushing && m_swapChain)
+ return;
+
+ m_window = window;
+ m_bounds = bounds;
+
+ // Invalidate the post-processing context since the window's bounds
+ // have changed. If needed, the post-processing context will be
+ // recreated with the correct bounds during the next rendering pass.
+ m_d3dPostProcessingContext = nullptr;
+
+ if (!m_window) {
+ m_swapChain = nullptr;
+ // If we don't have a window, we can't draw, so there's no point in having the display
+ // link fire.
+ scheduleNextDraw(numeric_limits<CFTimeInterval>::infinity());
+ } else {
+ // FIXME: We might be able to get better resizing performance by allocating swap chains in
+ // multiples of some size (say, 256x256) and only reallocating when our window size passes into
+ // the next size threshold.
+ m_swapChain = CAD3DRenderer::shared().swapChain(m_window, m_bounds.size);
+
+ if (boundsChanged) {
+ // Our layer's rendered appearance won't be updated until our context is next flushed.
+ // We shouldn't draw until that happens.
+ m_drawingProhibited = true;
+ // There's no point in allowing the display link to fire until drawing becomes
+ // allowed again (at which time we'll restart the display link).
+ scheduleNextDraw(numeric_limits<CFTimeInterval>::infinity());
+ } else if (m_destination == DrawingDestinationImage) {
+ // It is the caller's responsibility to ask us to draw sometime later.
+ scheduleNextDraw(numeric_limits<CFTimeInterval>::infinity());
+ } else {
+ // We should draw into the new window and/or swap chain as soon as possible.
+ scheduleNextDraw(0);
+ }
+ }
+ }
+
+ if (m_layer)
+ CACFLayerSetFrame(m_layer.get(), m_bounds);
+
+ if (m_window)
+ invalidateRects(&m_bounds, 1);
+
+ m_flushing = false;
+}
+
+void CAView::invalidateRects(const CGRect* rects, size_t count)
+{
+ CARenderContext* renderContext = static_cast<CARenderContext*>(CACFContextGetRenderContext(m_context.get()));
+ CARenderContextLock(renderContext);
+ for (size_t i = 0; i < count; ++i)
+ CARenderContextInvalidateRect(renderContext, &rects[i]);
+ CARenderContextUnlock(renderContext);
+}
+
+void CAView::drawToWindow()
+{
+ MutexLocker lock(m_mutex);
+ drawToWindowInternal();
+}
+
+void CAView::drawToWindowInternal()
+{
+ ASSERT_WITH_MESSAGE(!m_mutex.tryLock(), "m_mutex must be held when calling this function");
+ CFTimeInterval nextDrawTime;
+ bool unusedWillUpdateSoon;
+ if (willDraw(unusedWillUpdateSoon))
+ didDraw(CAD3DRenderer::shared().renderAndPresent(m_bounds, m_swapChain, m_d3dPostProcessingContext.get(), m_context.get(), nextDrawTime), unusedWillUpdateSoon);
+ else
+ nextDrawTime = numeric_limits<CFTimeInterval>::infinity();
+ scheduleNextDraw(nextDrawTime);
+}
+
+RefPtr<Image> CAView::drawToImage(CGPoint& imageOrigin, CFTimeInterval& nextDrawTime)
+{
+ ASSERT(m_destination == DrawingDestinationImage);
+
+ imageOrigin = CGPointZero;
+ nextDrawTime = numeric_limits<CFTimeInterval>::infinity();
+
+ MutexLocker lock(m_mutex);
+
+ RefPtr<Image> image;
+ bool willUpdateSoon;
+ if (willDraw(willUpdateSoon))
+ didDraw(CAD3DRenderer::shared().renderToImage(m_bounds, m_swapChain, m_d3dPostProcessingContext.get(), m_context.get(), image, imageOrigin, nextDrawTime), willUpdateSoon);
+
+ if (willUpdateSoon) {
+ // We weren't able to draw, and have scheduled an update in the near future. Our caller
+ // will have to call us again in order to get anything to be drawn. Ideally we'd set
+ // nextDrawTime to just after we update ourselves, but we don't know exactly when it will
+ // occur, so we just tell the caller to call us again as soon as they can.
+ nextDrawTime = 0;
+ }
+ return image;
+}
+
+bool CAView::willDraw(bool& willUpdateSoon)
+{
+ ASSERT_WITH_MESSAGE(!m_mutex.tryLock(), "m_mutex must be held when calling this function");
+
+ willUpdateSoon = false;
+
+ if (!m_window)
+ return false;
+
+ if (m_drawingProhibited)
+ return false;
+
+ if (!m_swapChain) {
+ // We've lost our swap chain. This probably means the Direct3D device became lost.
+ updateSoon();
+ willUpdateSoon = true;
+ // We'll schedule a new draw once we've updated. Until then, there's no point in trying to draw.
+ return false;
+ }
+
+ if (m_shouldInvertColors && !m_d3dPostProcessingContext)
+ m_d3dPostProcessingContext = CAD3DRenderer::shared().createD3DPostProcessingContext(m_swapChain, m_bounds.size);
+ else if (!m_shouldInvertColors)
+ m_d3dPostProcessingContext = nullptr;
+
+ return true;
+}
+
+void CAView::didDraw(CAD3DRenderer::RenderResult result, bool& willUpdateSoon)
+{
+ willUpdateSoon = false;
+
+ switch (result) {
+ case CAD3DRenderer::DeviceBecameLost:
+ // MSDN says we have to release any existing D3D resources before we try to recover a lost
+ // device. That includes swap chains. See
+ // <http://msdn.microsoft.com/en-us/library/bb174425(v=VS.85).aspx>.
+ releaseAllD3DResources();
+ updateSoon();
+ willUpdateSoon = true;
+ return;
+
+ case CAD3DRenderer::DeviceIsLost:
+ updateSoon();
+ willUpdateSoon = true;
+ return;
+
+ case CAD3DRenderer::OtherFailure:
+ case CAD3DRenderer::NoRenderingRequired:
+ case CAD3DRenderer::Success:
+ return;
+ }
+
+ ASSERT_NOT_REACHED();
+}
+
+void CAView::drawIntoDC(HDC dc)
+{
+ auto memoryDC = adoptGDIObject(::CreateCompatibleDC(dc));
+
+ // Create a bitmap and select it into our memoryDC.
+
+ BITMAPINFO info = {0};
+ info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
+ info.bmiHeader.biWidth = CGRectGetWidth(m_bounds);
+ info.bmiHeader.biHeight = CGRectGetHeight(m_bounds);
+ info.bmiHeader.biPlanes = 1;
+ info.bmiHeader.biBitCount = 32;
+
+ void* bits = nullptr;
+ auto bitmap = adoptGDIObject(::CreateDIBSection(memoryDC.get(), &info, DIB_RGB_COLORS, &bits, 0, 0));
+ if (!bitmap)
+ return;
+
+ HBITMAP oldBitmap = static_cast<HBITMAP>(::SelectObject(memoryDC.get(), bitmap.get()));
+
+ BITMAP bmp;
+ ::GetObject(bitmap.get(), sizeof(bmp), &bmp);
+
+ // Create a software renderer.
+ CARenderOGLContext* renderer = CARenderOGLNew(&kCARenderSoftwareCallbacks, 0, kCARenderFlippedGeometry);
+
+ // Tell it to render into our bitmap.
+ if (!CARenderSoftwareSetDestination(renderer, bmp.bmBits, bmp.bmWidthBytes, bmp.bmBitsPixel, 0, 0, 0, 0, CGRectGetWidth(m_bounds), CGRectGetHeight(m_bounds))) {
+ ::SelectObject(memoryDC.get(), oldBitmap);
+ CARenderOGLDestroy(renderer);
+ return;
+ }
+
+ // Prepare for rendering.
+ char space[4096];
+ CARenderUpdate* u = CARenderUpdateBegin(space, sizeof(space), CACurrentMediaTime(), 0, 0, &m_bounds);
+ if (!u) {
+ ::SelectObject(memoryDC.get(), oldBitmap);
+ CARenderOGLDestroy(renderer);
+ return;
+ }
+
+ {
+ MutexLocker lock(m_mutex);
+
+ CARenderContext* renderContext = static_cast<CARenderContext*>(CACFContextGetRenderContext(m_context.get()));
+ CARenderContextLock(renderContext);
+ CARenderUpdateAddContext(u, renderContext);
+ CARenderContextUnlock(renderContext);
+
+ // We always want to render our entire contents.
+ CARenderUpdateAddRect(u, &m_bounds);
+
+ CARenderOGLRender(renderer, u);
+
+ CARenderUpdateFinish(u);
+ }
+
+ // Copy the rendered image into the destination DC.
+ ::BitBlt(dc, 0, 0, CGRectGetWidth(m_bounds), CGRectGetHeight(m_bounds), memoryDC.get(), 0, 0, SRCCOPY);
+
+ // Clean up.
+ ::SelectObject(memoryDC.get(), oldBitmap);
+ CARenderOGLDestroy(renderer);
+}
+
+void CAView::setShouldInvertColors(bool shouldInvertColors)
+{
+ MutexLocker lock(m_mutex);
+ m_shouldInvertColors = shouldInvertColors;
+}
+
+void CAView::scheduleNextDraw(CFTimeInterval mediaTime)
+{
+ MutexLocker lock(m_displayLinkMutex);
+
+ if (!m_context)
+ return;
+
+ m_nextDrawTime = mediaTime;
+
+ // We use !< here to ensure that we bail out when mediaTime is NaN.
+ // (Comparisons with NaN always yield false.)
+ if (!(m_nextDrawTime < numeric_limits<CFTimeInterval>::infinity())) {
+ if (m_displayLink)
+ m_displayLink->setPaused(true);
+ return;
+ }
+
+ ASSERT(m_destination == DrawingDestinationWindow);
+
+ if (!m_displayLink) {
+ m_displayLink = CVDisplayLink::create(this);
+ m_displayLink->start();
+ } else
+ m_displayLink->setPaused(false);
+}
+
+void CAView::displayLinkReachedCAMediaTime(CVDisplayLink* displayLink, CFTimeInterval time)
+{
+ ASSERT(m_destination == DrawingDestinationWindow);
+
+ {
+ MutexLocker lock(m_displayLinkMutex);
+ if (!m_displayLink)
+ return;
+ ASSERT_UNUSED(displayLink, displayLink == m_displayLink);
+
+ if (time < m_nextDrawTime)
+ return;
+ }
+
+ MutexLocker lock(m_mutex);
+ drawToWindowInternal();
+}
+
+void CAView::contextDidChangeCallback(void* object, void* info, void*)
+{
+ ASSERT_ARG(info, info);
+ ASSERT_ARG(object, object);
+
+ CAView* view = static_cast<CAView*>(info);
+ ASSERT_UNUSED(object, CACFContextGetRenderContext(view->context()) == object);
+ view->contextDidChange();
+}
+
+void CAView::contextDidChange()
+{
+ {
+ MutexLocker lock(m_mutex);
+
+ // Our layer's rendered appearance once again matches our bounds, so it's safe to draw.
+ m_drawingProhibited = false;
+ m_flushing = true;
+
+ if (m_destination == DrawingDestinationWindow)
+ scheduleNextDraw(0);
+ }
+
+ if (m_contextDidChangeCallback.function)
+ m_contextDidChangeCallback.function(this, m_contextDidChangeCallback.info);
+}
+
+void CAView::updateSoon()
+{
+ {
+ MutexLocker lock(globalStateMutex());
+ viewsNeedingUpdate().add(m_handle);
+ }
+ // It doesn't matter what timer ID we pass here, as long as it's nonzero.
+ ASSERT(messageWindow);
+ ::SetTimer(messageWindow, 1, 0, updateViewsNow);
+}
+
+void CAView::updateViewsNow(HWND window, UINT, UINT_PTR timerID, DWORD)
+{
+ ASSERT_ARG(window, window == messageWindow);
+ ::KillTimer(window, timerID);
+
+ Vector<RefPtr<Handle>> viewsToUpdate;
+
+ {
+ MutexLocker lock(globalStateMutex());
+ viewsToUpdate = copyToVector(viewsNeedingUpdate());
+ viewsNeedingUpdate().clear();
+ }
+
+ for (size_t i = 0; i < viewsToUpdate.size(); ++i) {
+ const RefPtr<Handle>& handle = viewsToUpdate[i];
+ MutexLocker lock(handle->mutex());
+ CAView* view = handle->view();
+ if (!view)
+ continue;
+ MutexLocker viewLock(view->m_mutex);
+ view->update(view->m_window, view->m_bounds);
+ }
+}
+
+IDirect3DDevice9* CAView::d3dDevice9()
+{
+ // Hold the mutex while we return the shared d3d device. The caller is responsible for retaining
+ // the device before returning to ensure that it is not released.
+ MutexLocker lock(m_mutex);
+
+ return CAD3DRenderer::shared().d3dDevice9();
+}
+
+} // namespace WKQCA
Added: trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/CAView.h (0 => 224629)
--- trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/CAView.h (rev 0)
+++ trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/CAView.h 2017-11-09 17:11:24 UTC (rev 224629)
@@ -0,0 +1,131 @@
+/*
+* Copyright (C) 2017 Apple Inc. All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+* 1. Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in the
+* documentation and/or other materials provided with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+* THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#pragma once
+
+#include "CAD3DRenderer.h"
+#include "CVDisplayLinkClient.h"
+#include <wtf/RefCounted.h>
+#include <wtf/RetainPtr.h>
+
+typedef struct _CACFContext* CACFContextRef;
+typedef struct _CACFLayer* CACFLayerRef;
+
+namespace WKQCA {
+
+class Image;
+
+// This class is a stand-in for QuartzCore's CAViewRef until that class is usable on Windows.
+// FIXME 8727182: Replace this with CAViewRef.
+class CAView : public RefCounted<CAView>, private CVDisplayLinkClient {
+public:
+ enum DrawingDestination {
+ DrawingDestinationWindow,
+ DrawingDestinationImage,
+ };
+
+ class Handle;
+
+ static RefPtr<CAView> create(DrawingDestination);
+ ~CAView();
+
+ typedef void (*ContextDidChangeCallbackFunction)(CAView*, void* info);
+ void setContextDidChangeCallback(ContextDidChangeCallbackFunction, void* info);
+
+ // The only valid operations that may be performed on the context are CFRetain, CFRelease, and
+ // CACFContextFlush.
+ CACFContextRef context() const { return m_context.get(); }
+
+ void setLayer(CACFLayerRef);
+
+ void update(CWindow, const CGRect& bounds);
+
+ void invalidateRects(const CGRect*, size_t count);
+
+ bool canDraw() const { return m_swapChain; }
+
+ void drawToWindow();
+ RefPtr<Image> drawToImage(CGPoint& imageLocation, CFTimeInterval& nextDrawTime);
+ void drawIntoDC(HDC);
+
+ void setShouldInvertColors(bool);
+
+ IDirect3DDevice9* d3dDevice9();
+
+private:
+ struct ContextDidChangeCallback {
+ ContextDidChangeCallback()
+ : function(0), info(0) { }
+ ContextDidChangeCallbackFunction function;
+ void* info;
+ };
+
+ CAView(DrawingDestination);
+
+ void drawToWindowInternal();
+ bool willDraw(bool& willUpdateSoon);
+ void didDraw(CAD3DRenderer::RenderResult, bool& willUpdateSoon);
+ void scheduleNextDraw(CFTimeInterval mediaTime);
+
+ static void contextDidChangeCallback(void*, void* info, void*);
+ void contextDidChange();
+
+ static void releaseAllD3DResources();
+
+ void updateSoon();
+ static void CALLBACK updateViewsNow(HWND, UINT, UINT_PTR, DWORD);
+
+ virtual void displayLinkReachedCAMediaTime(CVDisplayLink*, CFTimeInterval);
+
+ // Only set in the constructor.
+ DrawingDestination m_destination;
+
+ // Only set in the constructor, then protected by its own Mutex.
+ RefPtr<Handle> m_handle;
+
+ // Only accessed in API calls, the synchronization of which is the responsibility of the caller.
+ RetainPtr<CACFLayerRef> m_layer;
+ ContextDidChangeCallback m_contextDidChangeCallback;
+
+ Mutex m_mutex;
+ // Accessed by the display link thread, protected by m_mutex. (m_context isn't directly
+ // accessed from the display link thread, but its CARenderContext is.)
+ RetainPtr<CACFContextRef> m_context;
+ CWindow m_window;
+ CGRect m_bounds;
+ CComPtr<IDirect3DSwapChain9> m_swapChain;
+ std::unique_ptr<D3DPostProcessingContext> m_d3dPostProcessingContext;
+
+ Mutex m_displayLinkMutex;
+ // Accessed by the display link thread, protected by m_displayLinkMutex.
+ RefPtr<CVDisplayLink> m_displayLink;
+ CFTimeInterval m_nextDrawTime { 0 };
+
+ bool m_drawingProhibited { false };
+ bool m_shouldInvertColors { false };
+ bool m_flushing { false };
+};
+
+} // namespace WKQCA
Added: trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/CMakeLists.txt (0 => 224629)
--- trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/CMakeLists.txt (rev 0)
+++ trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/CMakeLists.txt 2017-11-09 17:11:24 UTC (rev 224629)
@@ -0,0 +1,66 @@
+cmake_minimum_required(VERSION 2.8.12)
+include(WebKitCommon)
+
+add_definitions(
+ -DUSE_CF=1
+ -DD3D_DEBUG_INFO
+ -DBUILDING_WKQCA
+ -DDISABLE_COREIMAGE
+ -DDISABLE_FRONTEND
+ -DDISABLE_IOSURFACE
+ -DDISABLE_RENDERSERVER
+)
+
+set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /SUBSYSTEM:WINDOWS")
+set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:WINDOWS")
+
+set(WebKitQuartzCoreAdditions_SOURCES
+ API/WKCACFImage.cpp
+ API/WKCACFView.cpp
+ API/WebKitQuartzCoreAdditions.cpp
+
+ CAD3DRenderer.cpp
+ CAView.cpp
+ CVDisplayLink.cpp
+ Image.cpp
+ ImageConversion.cpp
+ ${DERIVED_SOURCES_DIR}/WebKitQuartzCoreAdditions/InvertColorPS.h
+)
+
+file(MAKE_DIRECTORY "${DERIVED_SOURCES_DIR}/WebKitQuartzCoreAdditions")
+add_custom_command(
+ OUTPUT ${DERIVED_SOURCES_DIR}/WebKitQuartzCoreAdditions/InvertColorPS.h
+ MAIN_DEPENDENCY InvertColorPS.hlsl
+ COMMAND fxc /E "InvertColorPS" /T ps_2_0 /Fh "${DERIVED_SOURCES_DIR}/WebKitQuartzCoreAdditions/InvertColorPS.h" "${CMAKE_CURRENT_SOURCE_DIR}/InvertColorPS.hlsl"
+ VERBATIM)
+
+file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/API/WebKitQuartzCoreAdditionsBase.h DESTINATION ${DERIVED_SOURCES_DIR}/WebKitQuartzCoreAdditions)
+file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/API/WKCACFImage.h DESTINATION ${DERIVED_SOURCES_DIR}/WebKitQuartzCoreAdditions)
+file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/API/WKCACFImageInternal.h DESTINATION ${DERIVED_SOURCES_DIR}/WebKitQuartzCoreAdditions)
+file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/API/WKCACFView.h DESTINATION ${DERIVED_SOURCES_DIR}/WebKitQuartzCoreAdditions)
+file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/API/WKCACFViewPrivate.h DESTINATION ${DERIVED_SOURCES_DIR}/WebKitQuartzCoreAdditions)
+
+WEBKIT_ADD_PRECOMPILED_HEADER("WebKitQuartzCoreAdditionsPrefix.h" "WebKitQuartzCoreAdditionsPrefix.cpp" WebKitQuartzCoreAdditions_SOURCES)
+
+include_directories(
+ .
+ "${DERIVED_SOURCES_DIR}/ForwardingHeaders"
+ "${DERIVED_SOURCES_DIR}/WebKitQuartzCoreAdditions"
+ "${CMAKE_BINARY_DIR}/../include/private"
+)
+
+if (${MSVC_CXX_ARCHITECTURE_ID} STREQUAL "X86")
+ link_directories($(WINDOWSSDKDIR)Lib/$(WINDOWSSDKLIBVERSION)/um/x86)
+else ()
+ link_directories($(WINDOWSSDKDIR)Lib/$(WINDOWSSDKLIBVERSION)/um/x64)
+endif ()
+
+add_library(WebKitQuartzCoreAdditions SHARED ${WebKitQuartzCoreAdditions_SOURCES})
+set_target_properties(WebKitQuartzCoreAdditions PROPERTIES OUTPUT_NAME WebKitQuartzCoreAdditions${DEBUG_SUFFIX})
+target_link_libraries(WebKitQuartzCoreAdditions
+ D3d9
+ WTF${DEBUG_SUFFIX}
+ CoreFoundation${DEBUG_SUFFIX}
+ CoreGraphics${DEBUG_SUFFIX}
+ QuartzCore${DEBUG_SUFFIX}
+)
Added: trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/CVDisplayLink.cpp (0 => 224629)
--- trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/CVDisplayLink.cpp (rev 0)
+++ trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/CVDisplayLink.cpp 2017-11-09 17:11:24 UTC (rev 224629)
@@ -0,0 +1,147 @@
+/*
+* Copyright (C) 2017 Apple Inc. All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+* 1. Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in the
+* documentation and/or other materials provided with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+* THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include "CVDisplayLink.h"
+
+#include "CVDisplayLinkClient.h"
+#include <QuartzCore/CABase.h>
+#include <wtf/RefPtr.h>
+
+namespace WKQCA {
+
+inline CVDisplayLink::CVDisplayLink(CVDisplayLinkClient* client)
+ : m_client(client)
+ , m_wakeupEvent(::CreateEventW(0, FALSE, FALSE, 0))
+{
+ ASSERT_ARG(client, client);
+}
+
+CVDisplayLink::~CVDisplayLink()
+{
+ stop();
+ ::CloseHandle(m_wakeupEvent);
+}
+
+RefPtr<CVDisplayLink> CVDisplayLink::create(CVDisplayLinkClient* client)
+{
+ return adoptRef(new CVDisplayLink(client));
+}
+
+void CVDisplayLink::start()
+{
+ if (m_isRunning) {
+ ASSERT(m_ioThread);
+ return;
+ }
+
+ ASSERT(!m_ioThread);
+
+ m_isRunning = true;
+
+ ref(); // Adopted in runIOThread.
+ m_ioThread = Thread::create("WKQCA: CVDisplayLink", [this] {
+ runIOThread();
+ });
+ ASSERT(m_ioThread);
+}
+
+void CVDisplayLink::stop()
+{
+ if (!m_isRunning) {
+ ASSERT(!m_ioThread);
+ return;
+ }
+
+ ASSERT(m_ioThread);
+
+ m_isRunning = false;
+
+ // Unpause the thread so it will exit.
+ setPaused(false);
+
+ DWORD result = m_ioThread->waitForCompletion();
+ m_ioThread = nullptr;
+
+ switch (result) {
+ case WAIT_OBJECT_0:
+ // The thread's HANDLE was signaled, so the thread has exited.
+ break;
+ case WAIT_FAILED:
+ LOG_ERROR("waitForCompletion failed with error code %u", ::GetLastError());
+ break;
+ default:
+ ASSERT_WITH_MESSAGE(false, "waitForCompletion returned unexpected result %u", result);
+ break;
+ }
+}
+
+void CVDisplayLink::setPaused(bool paused)
+{
+ if (m_isPaused == paused)
+ return;
+
+ m_isPaused = paused;
+
+ if (m_isPaused)
+ return;
+
+ // Since we were paused until right now, the IO thread, if it has been started, is currently
+ // waiting forever inside ::WaitForSingleObject. We need to wake it up so it can continue
+ // running. If it hasn't been started, signaling this event is harmless.
+ ::SetEvent(m_wakeupEvent);
+}
+
+void CVDisplayLink::runIOThread()
+{
+ RefPtr<CVDisplayLink> link = adoptRef(this);
+ ::SetThreadPriority(::GetCurrentThread(), THREAD_PRIORITY_HIGHEST);
+
+ while (m_isRunning) {
+ // When we're not paused, we want to wait for as short a time as possible. MSDN says that
+ // passing a timeout of 0 causes ::WaitForSingleObject to return immediately without
+ // entering the wait state at all, which wouldn't give other threads a chance to acquire any
+ // mutexes our client acquires beneath displayLinkReachedCAMediaTime. So we pass a timeout
+ // of 1 instead. (Passing a timeout of 0 does seem to cause this function to enter the wait
+ // state at least sometimes on Windows XP, despite what MSDN says, but not on Windows 7.)
+ DWORD result = ::WaitForSingleObject(m_wakeupEvent, m_isPaused ? INFINITE : 1);
+ switch (result) {
+ case WAIT_TIMEOUT:
+ // It must be time to render.
+ m_client->displayLinkReachedCAMediaTime(this, CACurrentMediaTime());
+ break;
+ case WAIT_OBJECT_0:
+ // Someone wanted to wake us up.
+ break;
+ case WAIT_FAILED:
+ LOG_ERROR("::WaitForSingleObject failed with error code %u", ::GetLastError());
+ break;
+ default:
+ ASSERT_WITH_MESSAGE(false, "::WaitForSingleObject returned unexpected result %u", result);
+ break;
+ }
+ }
+}
+
+} // namespace WKQCA
Added: trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/CVDisplayLink.h (0 => 224629)
--- trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/CVDisplayLink.h (rev 0)
+++ trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/CVDisplayLink.h 2017-11-09 17:11:24 UTC (rev 224629)
@@ -0,0 +1,58 @@
+/*
+* Copyright (C) 2017 Apple Inc. All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+* 1. Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in the
+* documentation and/or other materials provided with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+* THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#pragma once
+
+#include <wtf/Forward.h>
+#include <wtf/Threading.h>
+
+namespace WKQCA {
+
+class CVDisplayLinkClient;
+
+// This class is a stand-in for CoreVideo's CVDisplayLinkRef until that class is usable on Windows.
+// FIXME 8769181: Replace this with CVDisplayLinkRef
+class CVDisplayLink : public ThreadSafeRefCounted<CVDisplayLink> {
+public:
+ static RefPtr<CVDisplayLink> create(CVDisplayLinkClient*);
+ ~CVDisplayLink();
+
+ void start();
+ void stop();
+ void setPaused(bool);
+
+private:
+ CVDisplayLink(CVDisplayLinkClient*);
+
+ void runIOThread();
+
+ CVDisplayLinkClient* m_client;
+ HANDLE m_wakeupEvent;
+ RefPtr<Thread> m_ioThread;
+ volatile bool m_isRunning { false };
+ volatile bool m_isPaused { false };
+};
+
+} // namespace WKQCA
Added: trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/CVDisplayLinkClient.h (0 => 224629)
--- trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/CVDisplayLinkClient.h (rev 0)
+++ trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/CVDisplayLinkClient.h 2017-11-09 17:11:24 UTC (rev 224629)
@@ -0,0 +1,43 @@
+/*
+* Copyright (C) 2017 Apple Inc. All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+* 1. Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in the
+* documentation and/or other materials provided with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+* THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#pragma once
+
+typedef double CFTimeInterval;
+
+namespace WKQCA {
+
+class CVDisplayLink;
+
+class CVDisplayLinkClient {
+public:
+ // Called on the display link's thread.
+ virtual void displayLinkReachedCAMediaTime(CVDisplayLink*, CFTimeInterval) = 0;
+
+protected:
+ ~CVDisplayLinkClient() { }
+};
+
+} // namespace WKQCA
Added: trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/Image.cpp (0 => 224629)
--- trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/Image.cpp (rev 0)
+++ trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/Image.cpp 2017-11-09 17:11:24 UTC (rev 224629)
@@ -0,0 +1,91 @@
+/*
+* Copyright (C) 2017 Apple Inc. All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+* 1. Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in the
+* documentation and/or other materials provided with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+* THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include "Image.h"
+
+#include <wtf/RefPtr.h>
+#include <wtf/win/GDIObject.h>
+
+namespace WKQCA {
+
+static const unsigned bitCount = 32;
+
+static size_t numBytesForSize(const CSize& size)
+{
+ return size.cx * size.cy * bitCount / 8;
+}
+
+RefPtr<Image> Image::create(const CSize& size)
+{
+ HANDLE mapping = ::CreateFileMappingW(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, 0, numBytesForSize(size), 0);
+ if (!mapping)
+ return nullptr;
+
+ return adoptRef(new Image(mapping, size));
+}
+
+Image::Image(HANDLE fileMapping, const CSize& size)
+ : m_fileMapping(fileMapping)
+ , m_size(size)
+{
+ ASSERT_ARG(fileMapping, fileMapping);
+}
+
+Image::~Image()
+{
+ ::CloseHandle(m_fileMapping);
+}
+
+static BITMAPINFO bitmapInfo(const CSize& size)
+{
+ BITMAPINFO info = {0};
+ info.bmiHeader.biSize = sizeof(info.bmiHeader);
+ info.bmiHeader.biBitCount = bitCount;
+ info.bmiHeader.biPlanes = 1;
+ info.bmiHeader.biCompression = BI_RGB;
+ info.bmiHeader.biWidth = size.cx;
+ info.bmiHeader.biHeight = -size.cy;
+
+ return info;
+}
+
+GDIObject<HBITMAP> Image::createDIB() const
+{
+ BITMAPINFO info = bitmapInfo(m_size);
+
+ void* unusedBits;
+ return adoptGDIObject(::CreateDIBSection(0, &info, DIB_RGB_COLORS, &unusedBits, m_fileMapping, 0));
+}
+
+HANDLE Image::copyFileMapping(size_t& fileMappingSize)
+{
+ HANDLE result;
+ if (!::DuplicateHandle(::GetCurrentProcess(), m_fileMapping, ::GetCurrentProcess(), &result, 0, FALSE, DUPLICATE_SAME_ACCESS))
+ return 0;
+ fileMappingSize = numBytesForSize(m_size);
+ return result;
+}
+
+} // namespace WKQCA
Added: trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/Image.h (0 => 224629)
--- trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/Image.h (rev 0)
+++ trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/Image.h 2017-11-09 17:11:24 UTC (rev 224629)
@@ -0,0 +1,51 @@
+/*
+* Copyright (C) 2017 Apple Inc. All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+* 1. Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in the
+* documentation and/or other materials provided with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+* THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#pragma once
+
+#include <wtf/Forward.h>
+#include <wtf/RefCounted.h>
+#include <wtf/win/GDIObject.h>
+
+namespace WKQCA {
+
+class Image : public RefCounted<Image> {
+public:
+ static RefPtr<Image> create(const CSize&);
+ ~Image();
+
+ const CSize& size() const { return m_size; }
+
+ GDIObject<HBITMAP> createDIB() const;
+ HANDLE copyFileMapping(size_t& fileMappingSize);
+
+private:
+ Image(HANDLE fileMapping, const CSize&);
+
+ HANDLE m_fileMapping;
+ CSize m_size;
+};
+
+} // namespace WKQCA
Added: trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/ImageConversion.cpp (0 => 224629)
--- trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/ImageConversion.cpp (rev 0)
+++ trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/ImageConversion.cpp 2017-11-09 17:11:24 UTC (rev 224629)
@@ -0,0 +1,147 @@
+/*
+* Copyright (C) 2017 Apple Inc. All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+* 1. Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in the
+* documentation and/or other materials provided with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+* THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include "ImageConversion.h"
+
+#include "Image.h"
+#include <d3d9.h>
+#include <wtf/RefPtr.h>
+#include <wtf/win/GDIObject.h>
+
+namespace WKQCA {
+
+static HRESULT getBackBufferRectAsRenderTarget(IDirect3DDevice9* device, IDirect3DSwapChain9* swapChain, const CRect& rect, D3DFORMAT format, CComPtr<IDirect3DSurface9>& outRenderTarget)
+{
+ CComPtr<IDirect3DSurface9> backBuffer;
+ HRESULT hr = swapChain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &backBuffer);
+ if (FAILED(hr))
+ return hr;
+
+ CComPtr<IDirect3DSurface9> renderTarget;
+ hr = device->CreateRenderTarget(rect.Width(), rect.Height(), format, D3DMULTISAMPLE_NONE, 0, FALSE, &renderTarget, 0);
+ if (FAILED(hr))
+ return hr;
+
+ hr = device->StretchRect(backBuffer, &rect, renderTarget, 0, D3DTEXF_NONE);
+ if (FAILED(hr))
+ return hr;
+
+ outRenderTarget.Attach(renderTarget.Detach());
+ return S_OK;
+}
+
+static HRESULT getSystemMemoryCopy(IDirect3DDevice9* device, IDirect3DSurface9* renderTarget, CComPtr<IDirect3DSurface9>& outSystemMemorySurface)
+{
+ D3DSURFACE_DESC desc;
+ HRESULT hr = renderTarget->GetDesc(&desc);
+ if (FAILED(hr))
+ return hr;
+
+ CComPtr<IDirect3DSurface9> systemMemorySurface;
+ hr = device->CreateOffscreenPlainSurface(desc.Width, desc.Height, desc.Format, D3DPOOL_SYSTEMMEM, &systemMemorySurface, 0);
+ if (FAILED(hr))
+ return hr;
+
+ hr = device->GetRenderTargetData(renderTarget, systemMemorySurface);
+ if (FAILED(hr))
+ return hr;
+
+ outSystemMemorySurface.Attach(systemMemorySurface.Detach());
+ return S_OK;
+}
+
+static bool copyRectToBitmap(HDC sourceDC, const CRect& rect, HBITMAP destinationBitmap)
+{
+ auto bitmapDC = adoptGDIObject(::CreateCompatibleDC(sourceDC));
+ if (!bitmapDC)
+ return false;
+
+ HBITMAP oldBitmap = static_cast<HBITMAP>(::SelectObject(bitmapDC.get(), destinationBitmap));
+ if (!oldBitmap)
+ return false;
+
+ if (!::BitBlt(bitmapDC.get(), 0, 0, rect.Width(), rect.Height(), sourceDC, rect.left, rect.top, SRCCOPY))
+ return false;
+
+ return ::SelectObject(bitmapDC.get(), oldBitmap);
+}
+
+static HRESULT getImageCopy(IDirect3DSurface9* systemMemorySurface, RefPtr<Image>& outImage)
+{
+ D3DSURFACE_DESC desc;
+ HRESULT hr = systemMemorySurface->GetDesc(&desc);
+ if (FAILED(hr))
+ return hr;
+
+ CSize surfaceSize(desc.Width, desc.Height);
+
+ RefPtr<Image> image = Image::create(surfaceSize);
+ if (!image)
+ return E_FAIL;
+
+ auto bitmap = image->createDIB();
+
+ HDC surfaceDC;
+ hr = systemMemorySurface->GetDC(&surfaceDC);
+ if (FAILED(hr))
+ return hr;
+
+ bool success = copyRectToBitmap(surfaceDC, CRect(CPoint(0, 0), surfaceSize), bitmap.get());
+
+ hr = systemMemorySurface->ReleaseDC(surfaceDC);
+ if (FAILED(hr))
+ return hr;
+
+ if (!success)
+ return E_FAIL;
+
+ outImage = WTFMove(image);
+ return S_OK;
+}
+
+HRESULT getBackBufferRectAsImage(IDirect3DDevice9* device, IDirect3DSwapChain9* swapChain, const CRect& rect, RefPtr<Image>& outImage)
+{
+ // We have to read the back buffer's bits off the GPU and into system memory. But copying from
+ // the GPU to system memory is slow, so we want to copy as few bits as possible. Direct3D only
+ // allows an entire surface to be read into system memory, not just a subrect, so we first copy
+ // the subrect we care about to a second, smaller surface, then read that second surface into
+ // system memory.
+
+ // We explicitly specify D3DFMT_X8R8G8B8 to match the format of Image's bits. This should cause
+ // any color conversion to happen on the GPU before we read the bits back into system memory.
+ CComPtr<IDirect3DSurface9> renderTarget;
+ HRESULT hr = getBackBufferRectAsRenderTarget(device, swapChain, rect, D3DFMT_X8R8G8B8, renderTarget);
+ if (FAILED(hr))
+ return hr;
+
+ CComPtr<IDirect3DSurface9> systemMemorySurface;
+ hr = getSystemMemoryCopy(device, renderTarget, systemMemorySurface);
+ if (FAILED(hr))
+ return hr;
+
+ return getImageCopy(systemMemorySurface, outImage);
+}
+
+} // namespace WKQCA
Added: trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/ImageConversion.h (0 => 224629)
--- trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/ImageConversion.h (rev 0)
+++ trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/ImageConversion.h 2017-11-09 17:11:24 UTC (rev 224629)
@@ -0,0 +1,39 @@
+/*
+* Copyright (C) 2017 Apple Inc. All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+* 1. Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in the
+* documentation and/or other materials provided with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+* THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#pragma once
+
+#include <wtf/Forward.h>
+
+struct IDirect3DDevice9;
+struct IDirect3DSwapChain9;
+
+namespace WKQCA {
+
+class Image;
+
+HRESULT getBackBufferRectAsImage(IDirect3DDevice9*, IDirect3DSwapChain9*, const CRect&, RefPtr<Image>&);
+
+} // namespace WKQCA
Added: trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/InvertColorPS.hlsl (0 => 224629)
--- trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/InvertColorPS.hlsl (rev 0)
+++ trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/InvertColorPS.hlsl 2017-11-09 17:11:24 UTC (rev 224629)
@@ -0,0 +1,13 @@
+// Pixel shader to invert color of texture
+texture sceneTexture;
+
+sampler2D sceneTextureSampler = sampler_state {
+ Texture = <sceneTexture>;
+};
+
+float4 InvertColorPS(float2 textureCoordinate : TEXCOORD0) : COLOR0
+{
+ float4 color = tex2D(sceneTextureSampler, textureCoordinate);
+ color.rgb = 1.0f - color.rgb;
+ return color;
+};
Added: trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/WebKitQuartzCoreAdditionsInternal.h (0 => 224629)
--- trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/WebKitQuartzCoreAdditionsInternal.h (rev 0)
+++ trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/WebKitQuartzCoreAdditionsInternal.h 2017-11-09 17:11:24 UTC (rev 224629)
@@ -0,0 +1,32 @@
+/*
+* Copyright (C) 2017 Apple Inc. All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+* 1. Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in the
+* documentation and/or other materials provided with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+* THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#pragma once
+
+namespace WKQCA {
+
+HINSTANCE dllInstance();
+
+} // namespace WKQCA
Added: trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/WebKitQuartzCoreAdditionsPrefix.cpp (0 => 224629)
--- trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/WebKitQuartzCoreAdditionsPrefix.cpp (rev 0)
+++ trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/WebKitQuartzCoreAdditionsPrefix.cpp 2017-11-09 17:11:24 UTC (rev 224629)
@@ -0,0 +1,26 @@
+/*
+* Copyright (C) 2017 Apple Inc. All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+* 1. Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in the
+* documentation and/or other materials provided with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+* THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include "WebKitQuartzCoreAdditionsPrefix.h"
Added: trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/WebKitQuartzCoreAdditionsPrefix.h (0 => 224629)
--- trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/WebKitQuartzCoreAdditionsPrefix.h (rev 0)
+++ trunk/Source/WebKitLegacy/win/WebKitQuartzCoreAdditions/WebKitQuartzCoreAdditionsPrefix.h 2017-11-09 17:11:24 UTC (rev 224629)
@@ -0,0 +1,51 @@
+/*
+* Copyright (C) 2017 Apple Inc. All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+* 1. Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in the
+* documentation and/or other materials provided with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+* THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#pragma once
+
+#include <wtf/Platform.h>
+
+#define WIN32_LEAN_AND_MEAN
+#ifndef NOMINMAX
+#define NOMINMAX
+#endif
+
+#ifndef _WIN32_WINNT
+#define _WIN32_WINNT 0x601
+#endif
+
+#undef WINVER
+#define WINVER 0x0601
+
+#include <CoreGraphics/CGFloat.h>
+#include <CoreGraphics/CoreGraphics.h>
+
+#include <atlbase.h>
+#include <atltypes.h>
+#include <atlwin.h>
+#include <windows.h>
+#include <wtf/ExportMacros.h>
+#include <wtf/MathExtras.h>
+#include <wtf/ThreadingPrimitives.h>