void RenderWidget::setWidget(PassRefPtr<Widget> widget) { if (widget == m_widget) return; if (m_widget) { moveWidgetToParentSoon(m_widget.get(), 0); view().frameView().willRemoveWidgetFromRenderTree(*m_widget); widgetRendererMap().remove(m_widget.get()); m_widget = nullptr; } m_widget = widget; if (m_widget) { widgetRendererMap().add(m_widget.get(), this); view().frameView().didAddWidgetToRenderTree(*m_widget); // If we've already received a layout, apply the calculated space to the // widget immediately, but we have to have really been fully constructed. if (hasInitializedStyle()) { if (!needsLayout()) { WeakPtr<RenderWidget> weakThis = createWeakPtr(); updateWidgetGeometry(); if (!weakThis) return; } if (style().visibility() != VISIBLE) m_widget->hide(); else { m_widget->show(); repaint(); } } moveWidgetToParentSoon(m_widget.get(), &view().frameView()); } }
void WebCLEvent::setCallback(unsigned commandExecCallbackType, WebCLCallback* callback, ExceptionState& es) { if (isReleased()) { es.throwWebCLException(WebCLException::INVALID_EVENT, WebCLException::invalidEventMessage); return; } if (commandExecCallbackType != CL_COMPLETE) { es.throwWebCLException(WebCLException::INVALID_VALUE, WebCLException::invalidValueMessage); return; } ASSERT(callback); if (m_callbacks.size()) { m_callbacks.append(adoptRef(callback)); return; } m_callbacks.clear(); m_callbacks.append(adoptRef(callback)); WebCLEventHolder* holder = new WebCLEventHolder; holder->event = createWeakPtr(); holder->type = commandExecCallbackType; cl_int err = clSetEventCallback(m_clEvent, commandExecCallbackType, &callbackProxy, holder); if (err != CL_SUCCESS) WebCLException::throwException(err, es); }
bool RenderWidget::setWidgetGeometry(const LayoutRect& frame) { IntRect clipRect = roundedIntRect(enclosingLayer()->childrenClipRect()); IntRect newFrameRect = roundedIntRect(frame); IntRect oldFrameRect = m_widget->frameRect(); bool clipChanged = m_clipRect != clipRect; bool boundsChanged = oldFrameRect != newFrameRect; if (!boundsChanged && !clipChanged) return false; m_clipRect = clipRect; WeakPtr<RenderWidget> weakThis = createWeakPtr(); // These calls *may* cause this renderer to disappear from underneath... if (boundsChanged) m_widget->setFrameRect(newFrameRect); else if (clipChanged) m_widget->clipRectChanged(); // ...so we follow up with a sanity check. if (!weakThis) return true; #if USE(ACCELERATED_COMPOSITING) if (boundsChanged && hasLayer() && layer()->isComposited()) layer()->backing()->updateAfterWidgetResize(); #endif return oldFrameRect.size() != newFrameRect.size(); }
void MediaStreamPrivate::scheduleDeferredTask(std::function<void()> function) { ASSERT(function); auto weakThis = createWeakPtr(); callOnMainThread([weakThis, function] { if (!weakThis) return; function(); }); }
void RenderWidget::updateWidgetPosition() { if (!m_widget) return; WeakPtr<RenderWidget> weakThis = createWeakPtr(); bool widgetSizeChanged = updateWidgetGeometry(); if (!weakThis) return; // if the frame size got changed, or if view needs layout (possibly indicating // content size is wrong) we have to do a layout to set the right widget size. if (m_widget->isFrameView()) { FrameView* frameView = toFrameView(m_widget.get()); // Check the frame's page to make sure that the frame isn't in the process of being destroyed. if ((widgetSizeChanged || frameView->needsLayout()) && frameView->frame().page()) frameView->layout(); } }
RenderWidget::ChildWidgetState RenderWidget::updateWidgetPosition() { if (!m_widget) return ChildWidgetState::Destroyed; WeakPtr<RenderWidget> weakThis = createWeakPtr(); bool widgetSizeChanged = updateWidgetGeometry(); if (!weakThis || !m_widget) return ChildWidgetState::Destroyed; // if the frame size got changed, or if view needs layout (possibly indicating // content size is wrong) we have to do a layout to set the right widget size. if (is<FrameView>(*m_widget)) { FrameView& frameView = downcast<FrameView>(*m_widget); // Check the frame's page to make sure that the frame isn't in the process of being destroyed. if ((widgetSizeChanged || frameView.needsLayout()) && frameView.frame().page()) frameView.layout(); } return ChildWidgetState::Valid; }
void MediaPlayerPrivateAVFoundation::scheduleMainThreadNotification(Notification notification) { if (notification.type() != Notification::FunctionType) LOG(Media, "MediaPlayerPrivateAVFoundation::scheduleMainThreadNotification(%p) - notification %s", this, notificationName(notification)); m_queueMutex.lock(); // It is important to always process the properties in the order that we are notified, // so always go through the queue because notifications happen on different threads. m_queuedNotifications.append(notification); #if OS(WINDOWS) bool delayDispatch = true; #else bool delayDispatch = m_delayCallbacks || !isMainThread(); #endif if (delayDispatch && !m_mainThreadCallPending) { m_mainThreadCallPending = true; auto weakThis = createWeakPtr(); callOnMainThread([weakThis] { if (!weakThis) return; weakThis->mainThreadCallback(); }); } m_queueMutex.unlock(); if (delayDispatch) { if (notification.type() != Notification::FunctionType) LOG(Media, "MediaPlayerPrivateAVFoundation::scheduleMainThreadNotification(%p) - early return", this); return; } dispatchNotification(); }
void WebCLProgram::build(const Vector<RefPtr<WebCLDevice>>& devices, const String& buildOptions, WebCLCallback* callback, ExceptionState& es) { if (isReleased()) { es.throwWebCLException(WebCLException::INVALID_PROGRAM, WebCLException::invalidProgramMessage); return; } size_t kernel_label = m_programSource.find("__kernel ", 0); while (kernel_label != WTF::kNotFound) { size_t openBrace = m_programSource.find("{", kernel_label); size_t openBraket = m_programSource.reverseFind("(", openBrace); size_t space = m_programSource.reverseFind(" ", openBraket); String kernelName = m_programSource.substring(space + 1, openBraket - space - 1); if (kernelName.length() > 254) { // Kernel Name length isn't allowed larger than 255. es.throwWebCLException(WebCLException::BUILD_PROGRAM_FAILURE, WebCLException::buildProgramFailureMessage); return; } size_t closeBraket = m_programSource.find(")", openBraket); String arguments = m_programSource.substring(openBraket + 1, closeBraket - openBraket - 1); if (arguments.contains("struct ") || arguments.contains("image1d_array_t ") || arguments.contains("image1d_buffer_t ") || arguments.contains("image1d_t ") || arguments.contains("image2d_array_t ")) { // 1. Kernel structure parameters aren't allowed; // 2. Kernel argument "image1d_t", "image1d_array_t", "image2d_array_t" and "image1d_buffer_t" aren't allowed; es.throwWebCLException(WebCLException::BUILD_PROGRAM_FAILURE, WebCLException::buildProgramFailureMessage); return; } size_t closeBrace = m_programSource.find("}", openBrace); String codeString = m_programSource.substring(openBrace + 1, closeBrace - openBrace - 1).removeCharacters(isASCIILineBreakOrWhiteSpaceCharacter); if (codeString.isEmpty()) { // Kernel code isn't empty; es.throwWebCLException(WebCLException::BUILD_PROGRAM_FAILURE, WebCLException::buildProgramFailureMessage); return; } kernel_label = m_programSource.find("__kernel ", closeBrace); } if (buildOptions.length() > 0) { static AtomicString& buildOptionDashD = *new AtomicString("-D", AtomicString::ConstructFromLiteral); static HashSet<AtomicString>& webCLSupportedBuildOptions = *new HashSet<AtomicString>(); if (webCLSupportedBuildOptions.isEmpty()) { webCLSupportedBuildOptions.add(AtomicString("-cl-opt-disable", AtomicString::ConstructFromLiteral)); webCLSupportedBuildOptions.add(AtomicString("-cl-single-precision-constant", AtomicString::ConstructFromLiteral)); webCLSupportedBuildOptions.add(AtomicString("-cl-denorms-are-zero", AtomicString::ConstructFromLiteral)); webCLSupportedBuildOptions.add(AtomicString("-cl-mad-enable", AtomicString::ConstructFromLiteral)); webCLSupportedBuildOptions.add(AtomicString("-cl-no-signed-zeros", AtomicString::ConstructFromLiteral)); webCLSupportedBuildOptions.add(AtomicString("-cl-unsafe-math-optimizations", AtomicString::ConstructFromLiteral)); webCLSupportedBuildOptions.add(AtomicString("-cl-finite-math-only", AtomicString::ConstructFromLiteral)); webCLSupportedBuildOptions.add(AtomicString("-cl-fast-relaxed-math", AtomicString::ConstructFromLiteral)); webCLSupportedBuildOptions.add(AtomicString("-w", AtomicString::ConstructFromLiteral)); webCLSupportedBuildOptions.add(AtomicString("-Werror", AtomicString::ConstructFromLiteral)); } Vector<String> webCLBuildOptionsVector; buildOptions.split(" ", false, webCLBuildOptionsVector); for (size_t i = 0; i < webCLBuildOptionsVector.size(); i++) { // Every build option must start with a hyphen. if (!webCLBuildOptionsVector[i].startsWith("-")) { es.throwWebCLException(WebCLException::INVALID_BUILD_OPTIONS, WebCLException::invalidBuildOptionsMessage); return; } if (webCLSupportedBuildOptions.contains(AtomicString(webCLBuildOptionsVector[i]))) continue; if (webCLBuildOptionsVector[i].startsWith(buildOptionDashD)) { size_t j; for (j = i + 1; j < webCLBuildOptionsVector.size() && !webCLBuildOptionsVector[j].startsWith("-"); ++j) {} if (webCLBuildOptionsVector[i].stripWhiteSpace() == buildOptionDashD && j == i + 1) { es.throwWebCLException(WebCLException::INVALID_BUILD_OPTIONS, WebCLException::invalidBuildOptionsMessage); return; } i = --j; continue; } es.throwWebCLException(WebCLException::INVALID_BUILD_OPTIONS, WebCLException::invalidBuildOptionsMessage); return; } } pfnNotify callbackProxyPtr = nullptr; WebCLProgramHolder* holder = nullptr; if (callback) { if (m_buildCallback) { es.throwWebCLException(WebCLException::INVALID_OPERATION, WebCLException::invalidOperationMessage); return; } // Store the callback, eventList to HashTable and call callbackProxy. m_buildCallback = adoptRef(callback); callbackProxyPtr = &callbackProxy; holder = new WebCLProgramHolder; holder->program = createWeakPtr(); } cl_int err = CL_SUCCESS; Vector<cl_device_id> clDevices; Vector<RefPtr<WebCLDevice>> contextDevices = context()->getDevices(); if (devices.size()) { Vector<cl_device_id> inputDevices; for (auto device : devices) inputDevices.append(device->getDeviceId()); size_t contextDevicesLength = contextDevices.size(); for (size_t z, i = 0; i < inputDevices.size(); i++) { // Check if the inputDevices[i] is part of programs WebCLContext. for (z = 0; z < contextDevicesLength; z++) { if (contextDevices[z]->getDeviceId() == inputDevices[i]) { break; } } if (z == contextDevicesLength) { es.throwWebCLException(WebCLException::INVALID_DEVICE, WebCLException::invalidDeviceMessage); return; } clDevices.append(inputDevices[i]); } } else { for (auto contextDevice : contextDevices) clDevices.append(contextDevice->getDeviceId()); } if (!clDevices.size()) { es.throwWebCLException(WebCLException::INVALID_VALUE, WebCLException::invalidValueMessage); return; } m_isProgramBuilt = true; err = clBuildProgram(m_clProgram, clDevices.size(), clDevices.data(), buildOptions.utf8().data(), callbackProxyPtr, holder); if (err != CL_SUCCESS) es.throwWebCLException(WebCLException::BUILD_PROGRAM_FAILURE, WebCLException::buildProgramFailureMessage); }
void MediaPlayerPrivateAVFoundation::dispatchNotification() { ASSERT(isMainThread()); Notification notification = Notification(); { LockHolder lock(m_queueMutex); if (m_queuedNotifications.isEmpty()) return; if (!m_delayCallbacks) { // Only dispatch one notification callback per invocation because they can cause recursion. notification = m_queuedNotifications.first(); m_queuedNotifications.remove(0); } if (!m_queuedNotifications.isEmpty() && !m_mainThreadCallPending) { auto weakThis = createWeakPtr(); callOnMainThread([weakThis] { if (!weakThis) return; weakThis->mainThreadCallback(); }); } if (!notification.isValid()) return; } if (notification.type() != Notification::FunctionType) LOG(Media, "MediaPlayerPrivateAVFoundation::dispatchNotification(%p) - dispatching %s", this, notificationName(notification)); switch (notification.type()) { case Notification::ItemDidPlayToEndTime: didEnd(); break; case Notification::ItemTracksChanged: tracksChanged(); updateStates(); break; case Notification::ItemStatusChanged: updateStates(); break; case Notification::ItemSeekableTimeRangesChanged: seekableTimeRangesChanged(); updateStates(); break; case Notification::ItemLoadedTimeRangesChanged: loadedTimeRangesChanged(); updateStates(); break; case Notification::ItemPresentationSizeChanged: sizeChanged(); updateStates(); break; case Notification::ItemIsPlaybackLikelyToKeepUpChanged: updateStates(); break; case Notification::ItemIsPlaybackBufferEmptyChanged: updateStates(); break; case Notification::ItemIsPlaybackBufferFullChanged: updateStates(); break; case Notification::PlayerRateChanged: updateStates(); rateChanged(); break; case Notification::PlayerTimeChanged: timeChanged(notification.time()); break; case Notification::SeekCompleted: seekCompleted(notification.finished()); break; case Notification::AssetMetadataLoaded: metadataLoaded(); updateStates(); break; case Notification::AssetPlayabilityKnown: updateStates(); playabilityKnown(); break; case Notification::DurationChanged: invalidateCachedDuration(); break; case Notification::ContentsNeedsDisplay: contentsNeedsDisplay(); break; case Notification::InbandTracksNeedConfiguration: m_inbandTrackConfigurationPending = false; configureInbandTracks(); break; case Notification::FunctionType: notification.function()(); break; case Notification::TargetIsWirelessChanged: #if ENABLE(WIRELESS_PLAYBACK_TARGET) playbackTargetIsWirelessChanged(); #endif break; case Notification::None: ASSERT_NOT_REACHED(); break; } }