typename _Bundle> void BundleFlattener<_BaseType, _Scalar, _Vector, _VectorBit, _Bundle>::visit(_Bundle& bundle) throw (Error) { try { BundleFlattener<_BaseType, _Scalar, _Vector, _VectorBit, _Bundle> flattener; VisitorApplier<BundleFlattener<_BaseType, _Scalar, _Vector, _VectorBit, _Bundle> > applier(flattener); bundle.applyOnAllChildren(applier); } catch(Error& e) { e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__); throw; } }
bool RenderSVGShape::shapeDependentStrokeContains(const FloatPoint& point) { ASSERT(m_path); BoundingRectStrokeStyleApplier applier(this, style()); if (hasNonScalingStroke()) { AffineTransform nonScalingTransform = nonScalingStrokeTransform(); Path* usePath = nonScalingStrokePath(m_path.get(), nonScalingTransform); return usePath->strokeContains(&applier, nonScalingTransform.mapPoint(point)); } return m_path->strokeContains(&applier, point); }
typename _Bundle> void BundleFlattener<_BaseType, _Scalar, _Vector, _VectorBit, _Bundle>::visit(_Vector& vector) throw (Error) { try { typename _Vector::List children; vector.getChildren(children); BundleFlattener<_BaseType, _Scalar, _Vector, _VectorBit, _Bundle> flattener; VisitorApplier<BundleFlattener<_BaseType, _Scalar, _Vector, _VectorBit, _Bundle> > applier( flattener); for_each(children.begin(), children.end(), applier); } catch(Error& e) { e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__); throw; } }
template <typename _ReturnType> void PortRefCreator<_ReturnType>::visit(PortBundle& port) throw (Error) { try { PortBundleReferenceSharedPtr portBundleRef; mFactory->create(portBundleRef); PortRefCreator<PortReferenceSharedPtr> creator(mFactory, mInstance, portBundleRef); VisitorApplier<PortRefCreator<PortReferenceSharedPtr> > applier(creator); port.applyOnAllChildren(applier); setupCreatedPort(port.getSharedThis(), portBundleRef); mReturnValue = portBundleRef; } catch(Error& e) { e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__); throw; } }
void GUI::FilterConfigurationBox::updatePreview() { Model::FilterList filterList; filterList.appendFilter(tempFilter_->getName())->restore(tempFilter_->getSaveString()); auto avframe=Utility::VideoConverter::convertQImageToAVFrame(getDefaultImage()); Utility::FilterApplier applier(filterList,avframe->width,avframe->height,avframe->format); auto filteredFrame=applier.applyToFrame(*avframe); filteredImage_=Utility::VideoConverter::convertAVFrameToQImage(*filteredFrame); filterPreview_->setFrame(*filteredImage_); av_frame_unref(avframe); av_frame_unref(filteredFrame); av_frame_free(&avframe); av_frame_free(&filteredFrame); }
bool RenderSVGShape::shapeDependentStrokeContains(const FloatPoint& point) const { BoundingRectStrokeStyleApplier applier(this, style()); return m_path->strokeContains(&applier, point); }
void WorkQueue::concurrentApply(size_t iterations, const std::function<void (size_t index)>& function) { if (!iterations) return; if (iterations == 1) { function(0); return; } class ThreadPool { public: ThreadPool() { // We don't need a thread for the current core. unsigned threadCount = numberOfProcessorCores() - 1; m_workers.reserveInitialCapacity(threadCount); for (unsigned i = 0; i < threadCount; ++i) { m_workers.append(createThread(String::format("ThreadPool Worker %u", i).utf8().data(), [this] { threadBody(); })); } } size_t workerCount() const { return m_workers.size(); } void dispatch(const std::function<void ()>* function) { LockHolder holder(m_lock); m_queue.append(function); m_condition.notifyOne(); } private: NO_RETURN void threadBody() { while (true) { const std::function<void ()>* function; { LockHolder holder(m_lock); m_condition.wait(m_lock, [this] { return !m_queue.isEmpty(); }); function = m_queue.takeFirst(); } (*function)(); } } Lock m_lock; Condition m_condition; Deque<const std::function<void ()>*> m_queue; Vector<ThreadIdentifier> m_workers; }; static LazyNeverDestroyed<ThreadPool> threadPool; static std::once_flag onceFlag; std::call_once(onceFlag, [] { threadPool.construct(); }); // Cap the worker count to the number of iterations (excluding this thread) const size_t workerCount = std::min(iterations - 1, threadPool->workerCount()); std::atomic<size_t> currentIndex(0); std::atomic<size_t> activeThreads(workerCount + 1); Condition condition; Lock lock; std::function<void ()> applier = [&] { size_t index; // Call the function for as long as there are iterations left. while ((index = currentIndex++) < iterations) function(index); // If there are no active threads left, signal the caller. if (!--activeThreads) { LockHolder holder(lock); condition.notifyOne(); } }; for (size_t i = 0; i < workerCount; ++i) threadPool->dispatch(&applier); applier(); LockHolder holder(lock); condition.wait(lock, [&] { return !activeThreads; }); }