
You are a strict cpp→Zig transpiler. You will receive a com...
Prompt
You are a strict cpp→Zig transpiler. You will receive a complete cpp file as input. A Zig fájlnak önmagában külső fájlok nélkül is működnie kell You must return the equivalent Zig code. soha semmi egyszerusitett mock placeholder dummy szimulalt fake szart nem engedelyezek csak a teljes fajl teljes roviditetlen production ready kód CRITICAL RULES (DO NOT BREAK THEM): 1. Output ONLY Zig code. 2. NO comments at all. Do not keep original comments, do not add new ones. 3. NO explanations, NO summaries, NO notes. 4. NO placeholders, NO “...rest of code”, NO “to be implemented”. 5. Do not skip or shorten ANY part. Translate EVERY line. 6. The output must be complete, runnable Zig code with nothing missing. a teljes kódot küldöd. minden egyes karaktert leírsz, nem rövidítesz. minden hibát kijavítasz. egy fájl marad. ne írj semmi mást csak a teljes kódot es kommentek nem lehetnek benne! soha semmi egyszerusitett mock placeholder dummy szimulalt fake szart nem engedelyezek es teljes fájl roviditetlen production ready kód #include "config.h" #include "DrawingAreaProxyCoordinatedGraphics.h" #include "DrawingAreaMessages.h" #include "DrawingAreaProxyMessages.h" #include "LayerTreeContext.h" #include "MessageSenderInlines.h" #include "UpdateInfo.h" #include "WebPageProxy.h" #include "WebPreferences.h" #include "WebProcessPool.h" #include "WebProcessProxy.h" #include <WebCore/Region.h> #include <optional> #include <wtf/TZoneMallocInlines.h> #if USE(GLIB_EVENT_LOOP) #include <wtf/glib/RunLoopSourcePriority.h> #endif namespace WebKit { using namespace WebCore; WTF_MAKE_TZONE_ALLOCATED_IMPL(DrawingAreaProxyCoordinatedGraphics); Ref<DrawingAreaProxyCoordinatedGraphics> DrawingAreaProxyCoordinatedGraphics::create(WebPageProxy& page, WebProcessProxy& webProcessProxy) { return adoptRef(*new DrawingAreaProxyCoordinatedGraphics(page, webProcessProxy)); } DrawingAreaProxyCoordinatedGraphics::DrawingAreaProxyCoordinatedGraphics(WebPageProxy& webPageProxy, WebProcessProxy& webProcessProxy) : DrawingAreaProxy(webPageProxy, webProcessProxy) #if !PLATFORM(WPE) && !PLATFORM(GTK) , m_discardBackingStoreTimer(RunLoop::currentSingleton(), "DrawingAreaProxyCoordinatedGraphics::DiscardBackingStoreTimer"_s, this, &DrawingAreaProxyCoordinatedGraphics::discardBackingStore) #endif { } DrawingAreaProxyCoordinatedGraphics::~DrawingAreaProxyCoordinatedGraphics() { if (isInAcceleratedCompositingMode()) exitAcceleratedCompositingMode(); } #if !PLATFORM(WPE) && !PLATFORM(GTK) void DrawingAreaProxyCoordinatedGraphics::paint(PlatformPaintContextPtr cr, const IntRect& rect, Region& unpaintedRegion) { unpaintedRegion = rect; if (isInAcceleratedCompositingMode()) return; if (!m_backingStore && !forceUpdateIfNeeded()) return; m_backingStore->paint(cr, rect); unpaintedRegion.subtract(IntRect(IntPoint(), m_backingStore->size())); discardBackingStoreSoon(); } bool DrawingAreaProxyCoordinatedGraphics::forceUpdateIfNeeded() { ASSERT(!isInAcceleratedCompositingMode()); if (!webProcessProxy().hasConnection()) return false; if (webProcessProxy().state() == WebProcessProxy::State::Launching) return false; if (m_isWaitingForDidUpdateGeometry) return false; RefPtr page = this->page(); if (!page) return false; if (!page->isViewVisible()) return false; SetForScope inForceUpdate(m_inForceUpdate, true); send(Messages::DrawingArea::ForceUpdate()); webProcessProxy().connection().waitForAndDispatchImmediately<Messages::DrawingAreaProxy::Update>(identifier(), 500_ms); return !!m_backingStore; } void DrawingAreaProxyCoordinatedGraphics::incorporateUpdate(UpdateInfo&& updateInfo) { ASSERT(!isInAcceleratedCompositingMode()); if (updateInfo.updateRectBounds.isEmpty()) return; if (!m_backingStore || m_backingStore->size() != updateInfo.viewSize || m_backingStore->deviceScaleFactor() != updateInfo.deviceScaleFactor) m_backingStore = makeUnique<BackingStore>(updateInfo.viewSize, updateInfo.deviceScaleFactor); if (m_inForceUpdate) { m_backingStore->incorporateUpdate(WTF::move(updateInfo)); return; } RefPtr page = this->page(); if (!page) return; Region damageRegion; if (updateInfo.scrollRect.isEmpty()) { for (const auto& rect : updateInfo.updateRects) damageRegion.unite(rect); } else damageRegion = IntRect(IntPoint(), page->viewSize()); m_backingStore->incorporateUpdate(WTF::move(updateInfo)); page->setViewNeedsDisplay(damageRegion); } #endif #if HAVE(DISPLAY_LINK) std::optional<WebCore::FramesPerSecond> DrawingAreaProxyCoordinatedGraphics::displayNominalFramesPerSecond() { if (RefPtr page = this->page()) { if (auto displayID = page->displayID()) return page->legacyMainFrameProcess().nominalFramesPerSecondForDisplay(displayID.value()); } return std::nullopt; } #endif void DrawingAreaProxyCoordinatedGraphics::sizeDidChange() { if (!page() || !page()->hasRunningProcess()) return; if (m_isWaitingForDidUpdateGeometry) return; sendUpdateGeometry(); } void DrawingAreaProxyCoordinatedGraphics::deviceScaleFactorDidChange(CompletionHandler<void()>&& completionHandler) { if (!page()) { completionHandler(); return; } sendWithAsyncReply(Messages::DrawingArea::SetDeviceScaleFactor(page()->deviceScaleFactor()), WTF::move(completionHandler)); } void DrawingAreaProxyCoordinatedGraphics::setBackingStoreIsDiscardable(bool isBackingStoreDiscardable) { #if !PLATFORM(WPE) && !PLATFORM(GTK) if (m_isBackingStoreDiscardable == isBackingStoreDiscardable) return; m_isBackingStoreDiscardable = isBackingStoreDiscardable; if (m_isBackingStoreDiscardable) discardBackingStoreSoon(); else m_discardBackingStoreTimer.stop(); #endif } #if PLATFORM(GTK) void DrawingAreaProxyCoordinatedGraphics::adjustTransientZoom(double scale, FloatPoint originInLayerForPageScale, FloatPoint) { send(Messages::DrawingArea::AdjustTransientZoom(scale, originInLayerForPageScale)); } void DrawingAreaProxyCoordinatedGraphics::commitTransientZoom(double scale, FloatPoint origin) { sendWithAsyncReply(Messages::DrawingArea::CommitTransientZoom(scale, origin), [] { }); } #endif void DrawingAreaProxyCoordinatedGraphics::enterAcceleratedCompositingMode(uint64_t, const LayerTreeContext& layerTreeContext) { enterAcceleratedCompositingMode(layerTreeContext); } #if !PLATFORM(WPE) && !PLATFORM(GTK) void DrawingAreaProxyCoordinatedGraphics::update(uint64_t, UpdateInfo&& updateInfo) { if (m_isWaitingForDidUpdateGeometry && updateInfo.viewSize != m_lastSentSize) { send(Messages::DrawingArea::DisplayDidRefresh(MonotonicTime::now())); return; } incorporateUpdate(WTF::move(updateInfo)); if (!m_isWaitingForDidUpdateGeometry) send(Messages::DrawingArea::DisplayDidRefresh(MonotonicTime::now())); } void DrawingAreaProxyCoordinatedGraphics::exitAcceleratedCompositingMode(uint64_t, UpdateInfo&& updateInfo) { exitAcceleratedCompositingMode(); incorporateUpdate(WTF::move(updateInfo)); } #endif void DrawingAreaProxyCoordinatedGraphics::updateAcceleratedCompositingMode(uint64_t, const LayerTreeContext& layerTreeContext) { updateAcceleratedCompositingMode(layerTreeContext); } bool DrawingAreaProxyCoordinatedGraphics::alwaysUseCompositing() const { if (!page()) return false; return page()->preferences().acceleratedCompositingEnabled() && page()->preferences().forceCompositingMode(); } void DrawingAreaProxyCoordinatedGraphics::enterAcceleratedCompositingMode(const LayerTreeContext& layerTreeContext) { if (isInAcceleratedCompositingMode()) { updateAcceleratedCompositingMode(layerTreeContext); return; } #if !PLATFORM(WPE) && !PLATFORM(GTK) m_backingStore = nullptr; #endif m_layerTreeContext = layerTreeContext; if (RefPtr page = this->page()) page->enterAcceleratedCompositingMode(layerTreeContext); } void DrawingAreaProxyCoordinatedGraphics::exitAcceleratedCompositingMode() { ASSERT(isInAcceleratedCompositingMode()); m_layerTreeContext = { }; if (RefPtr page = this->page()) page->exitAcceleratedCompositingMode(); } void DrawingAreaProxyCoordinatedGraphics::updateAcceleratedCompositingMode(const LayerTreeContext& layerTreeContext) { ASSERT(isInAcceleratedCompositingMode()); m_layerTreeContext = layerTreeContext; if (RefPtr page = this->page()) page->updateAcceleratedCompositingMode(layerTreeContext); } void DrawingAreaProxyCoordinatedGraphics::dispatchPresentationCallbacksAfterFlushingLayers(IPC::Connection& connection, Vector<IPC::AsyncReplyID>&& callbackIDs) { for (auto& callbackID : callbackIDs) { if (auto callback = connection.takeAsyncReplyHandler(callbackID)) callback(nullptr, nullptr); } } void DrawingAreaProxyCoordinatedGraphics::sendUpdateGeometry() { ASSERT(!m_isWaitingForDidUpdateGeometry); m_lastSentSize = size(); m_isWaitingForDidUpdateGeometry = true; sendWithAsyncReply(Messages::DrawingArea::UpdateGeometry(size()), [weakThis = WeakPtr { *this }] { if (RefPtr protectedThis = weakThis) protectedThis->didUpdateGeometry(); }); } void DrawingAreaProxyCoordinatedGraphics::didUpdateGeometry() { ASSERT(m_isWaitingForDidUpdateGeometry); m_isWaitingForDidUpdateGeometry = false; if (m_lastSentSize != size()) sendUpdateGeometry(); } #if !PLATFORM(WPE) && !PLATFORM(GTK) void DrawingAreaProxyCoordinatedGraphics::discardBackingStoreSoon() { if (!m_backingStore || !m_isBackingStoreDiscardable || m_discardBackingStoreTimer.isActive()) return; static const Seconds discardBackingStoreDelay = 10_s; m_discardBackingStoreTimer.startOneShot(discardBackingStoreDelay); } void DrawingAreaProxyCoordinatedGraphics::discardBackingStore() { if (!m_backingStore) return; m_backingStore = nullptr; send(Messages::DrawingArea::DidDiscardBackingStore()); } #endif WTF_MAKE_TZONE_ALLOCATED_IMPL(DrawingAreaProxyCoordinatedGraphics::DrawingMonitor); DrawingAreaProxyCoordinatedGraphics::DrawingMonitor::DrawingMonitor(WebPageProxy& webPage) : m_timer(RunLoop::mainSingleton(), "DrawingAreaProxyCoordinatedGraphics::DrawingMonitor::Timer"_s, this, &DrawingMonitor::stop) { #if USE(GLIB_EVENT_LOOP) m_timer.setPriority(RunLoopSourcePriority::RunLoopDispatcher); #endif } DrawingAreaProxyCoordinatedGraphics::DrawingMonitor::~DrawingMonitor() { if (m_callback) m_callback(); stop(); } void DrawingAreaProxyCoordinatedGraphics::DrawingMonitor::start(CompletionHandler<void()>&& callback) { m_callback = WTF::move(callback); m_timer.startOneShot(0_s); } void DrawingAreaProxyCoordinatedGraphics::DrawingMonitor::stop() { m_timer.stop(); if (m_callback) m_callback(); } void DrawingAreaProxyCoordinatedGraphics::dispatchAfterEnsuringDrawing(CompletionHandler<void()>&& callbackFunction) { RefPtr page = this->page(); if (!page || !page->hasRunningProcess()) { callbackFunction(); return; } if (!m_drawingMonitor) m_drawingMonitor = makeUnique<DrawingAreaProxyCoordinatedGraphics::DrawingMonitor>(*page); m_drawingMonitor->start(WTF::move(callbackFunction)); } }