Add Chromium-only Blender WebEngine parity work

This commit is contained in:
mes123456
2026-08-12 04:47:48 -04:00
commit 9fd26010f6
18225 changed files with 11622124 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
/*******************************************************************************
* Copyright 2015-2016 Juan Francisco Crespo Galán
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
#include "util/Barrier.h"
AUD_NAMESPACE_BEGIN
Barrier::Barrier(unsigned int count) :
m_threshold(count), m_count(count), m_generation(0)
{
}
Barrier::~Barrier()
{
}
void Barrier::wait()
{
std::unique_lock<std::mutex> lck(m_mutex);
int gen = m_generation;
if(!--m_count)
{
m_count = m_threshold;
m_generation++;
m_condition.notify_all();
}
else
m_condition.wait(lck, [this, gen] { return gen != m_generation; });
}
AUD_NAMESPACE_END

View File

@@ -0,0 +1,77 @@
/*******************************************************************************
* Copyright 2009-2016 Jörg Müller
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
#include "util/Buffer.h"
#include <algorithm>
#include <cstring>
#include <cstdlib>
#define ALIGNMENT 32
#define ALIGN(a) (a + ALIGNMENT - ((long long)a & (ALIGNMENT-1)))
AUD_NAMESPACE_BEGIN
Buffer::Buffer(long long size)
{
m_size = size;
m_buffer = (data_t*) std::malloc(size + ALIGNMENT);
}
Buffer::~Buffer()
{
std::free(m_buffer);
}
const sample_t* Buffer::getBuffer() const
{
return (sample_t*) ALIGN(m_buffer);
}
sample_t* Buffer::getBuffer()
{
return (sample_t*) ALIGN(m_buffer);
}
long long Buffer::getSize() const
{
return m_size;
}
void Buffer::resize(long long size, bool keep)
{
if(keep)
{
data_t* buffer = (data_t*) std::malloc(size + ALIGNMENT);
std::memcpy(ALIGN(buffer), ALIGN(m_buffer), std::min(size, m_size));
std::free(m_buffer);
m_buffer = buffer;
}
else
m_buffer = (data_t*) std::realloc(m_buffer, size + ALIGNMENT);
m_size = size;
}
void Buffer::assureSize(long long size, bool keep)
{
if(m_size < size)
resize(size, keep);
}
AUD_NAMESPACE_END

View File

@@ -0,0 +1,80 @@
/*******************************************************************************
* Copyright 2009-2016 Jörg Müller
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
#include "util/BufferReader.h"
#include "util/Buffer.h"
#include <cstring>
AUD_NAMESPACE_BEGIN
BufferReader::BufferReader(std::shared_ptr<Buffer> buffer,
Specs specs) :
m_position(0), m_buffer(buffer), m_specs(specs)
{
}
bool BufferReader::isSeekable() const
{
return true;
}
void BufferReader::seek(int position)
{
m_position = position;
}
int BufferReader::getLength() const
{
return m_buffer->getSize() / AUD_SAMPLE_SIZE(m_specs);
}
int BufferReader::getPosition() const
{
return m_position;
}
Specs BufferReader::getSpecs() const
{
return m_specs;
}
void BufferReader::read(int& length, bool& eos, sample_t* buffer)
{
eos = false;
int sample_size = AUD_SAMPLE_SIZE(m_specs);
sample_t* buf = m_buffer->getBuffer() + m_position * m_specs.channels;
// in case the end of the buffer is reached
if(m_buffer->getSize() < (m_position + length) * sample_size)
{
length = m_buffer->getSize() / sample_size - m_position;
eos = true;
}
if(length < 0)
{
length = 0;
return;
}
m_position += length;
std::memcpy(buffer, buf, length * sample_size);
}
AUD_NAMESPACE_END

View File

@@ -0,0 +1,66 @@
/*******************************************************************************
* Copyright 2015-2016 Juan Francisco Crespo Galán
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
#include "util/FFTPlan.h"
AUD_NAMESPACE_BEGIN
FFTPlan::FFTPlan(double measureTime) :
FFTPlan(DEFAULT_N, measureTime)
{
}
FFTPlan::FFTPlan(int n, double measureTime) :
m_N(n), m_bufferSize(((n/2)+1)*2*sizeof(fftwf_complex))
{
fftwf_set_timelimit(measureTime);
void* buf = fftwf_malloc(m_bufferSize);
m_fftPlanR2C = fftwf_plan_dft_r2c_1d(m_N, (float*)buf, (fftwf_complex*)buf, FFTW_EXHAUSTIVE);
m_fftPlanC2R = fftwf_plan_dft_c2r_1d(m_N, (fftwf_complex*)buf, (float*)buf, FFTW_EXHAUSTIVE);
fftwf_free(buf);
}
FFTPlan::~FFTPlan()
{
fftwf_destroy_plan(m_fftPlanC2R);
fftwf_destroy_plan(m_fftPlanR2C);
}
int FFTPlan::getSize()
{
return m_N;
}
void FFTPlan::FFT(void* buffer)
{
fftwf_execute_dft_r2c(m_fftPlanR2C, (float*)buffer, (fftwf_complex*)buffer);
}
void FFTPlan::IFFT(void* buffer)
{
fftwf_execute_dft_c2r(m_fftPlanC2R, (fftwf_complex*)buffer, (float*)buffer);
}
void* FFTPlan::getBuffer()
{
return fftwf_malloc(m_bufferSize);
}
void FFTPlan::freeBuffer(void* buffer)
{
fftwf_free(buffer);
}
AUD_NAMESPACE_END

View File

@@ -0,0 +1,147 @@
/*******************************************************************************
* Copyright 2009-2021 Jörg Müller
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
#include "util/RingBuffer.h"
#include <algorithm>
#include <cstring>
#include <cstdlib>
#define ALIGNMENT 32
#define ALIGN(a) (a + ALIGNMENT - ((long long)a & (ALIGNMENT-1)))
AUD_NAMESPACE_BEGIN
RingBuffer::RingBuffer(int size) :
m_buffer(size),
m_read(0),
m_write(0)
{
}
const sample_t* RingBuffer::getBuffer() const
{
return m_buffer.getBuffer();
}
sample_t* RingBuffer::getBuffer()
{
return m_buffer.getBuffer();
}
int RingBuffer::getSize() const
{
return m_buffer.getSize();
}
size_t RingBuffer::getReadSize() const
{
size_t read = m_read;
size_t write = m_write;
if(read > write)
return write + getSize() - read;
else
return write - read;
}
size_t RingBuffer::getWriteSize() const
{
size_t read = m_read;
size_t write = m_write;
if(read > write)
return read - write - 1;
else
return read + getSize() - write - 1;
}
size_t RingBuffer::read(data_t* target, size_t size)
{
size = std::min(size, getReadSize());
data_t* buffer = reinterpret_cast<data_t*>(m_buffer.getBuffer());
if(m_read + size > m_buffer.getSize())
{
size_t read_first = m_buffer.getSize() - m_read;
size_t read_second = size - read_first;
std::memcpy(target, buffer + m_read, read_first);
std::memcpy(target + read_first, buffer, read_second);
m_read = read_second;
}
else
{
std::memcpy(target, buffer + m_read, size);
m_read += size;
}
return size;
}
size_t RingBuffer::write(data_t* source, size_t size)
{
size = std::min(size, getWriteSize());
data_t* buffer = reinterpret_cast<data_t*>(m_buffer.getBuffer());
if(m_write + size > m_buffer.getSize())
{
size_t write_first = m_buffer.getSize() - m_write;
size_t write_second = size - write_first;
std::memcpy(buffer + m_write, source, write_first);
std::memcpy(buffer, source + write_first, write_second);
m_write = write_second;
}
else
{
std::memcpy(buffer + m_write, source, size);
m_write += size;
}
return size;
}
void RingBuffer::clear()
{
m_read = m_write;
}
void RingBuffer::reset()
{
m_read = 0;
m_write = 0;
}
void RingBuffer::resize(int size)
{
m_buffer.resize(size);
reset();
}
void RingBuffer::assureSize(int size)
{
m_buffer.assureSize(size);
reset();
}
AUD_NAMESPACE_END

View File

@@ -0,0 +1,91 @@
/*******************************************************************************
* Copyright 2009-2016 Jörg Müller
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
#include "util/StreamBuffer.h"
#include "util/BufferReader.h"
#include "util/Buffer.h"
#include <algorithm>
// 5 sec * 48000 samples/sec * 4 bytes/sample * 6 channels
#define BUFFER_RESIZE_BYTES 5760000
// 90 min * 60 sec/min * 48000 samples/sec * 4 bytes/sample * 2 channels
#define MAXIMUM_INITIAL_BUFFER_SIZE_BYTES 2073600000
AUD_NAMESPACE_BEGIN
StreamBuffer::StreamBuffer(std::shared_ptr<ISound> sound) :
m_buffer(new Buffer())
{
std::shared_ptr<IReader> reader = sound->createReader();
m_specs = reader->getSpecs();
int sample_size = AUD_SAMPLE_SIZE(m_specs);
int length;
long long index = 0;
bool eos = false;
// get an approximated size if possible
long long size = std::min(reader->getLength(), MAXIMUM_INITIAL_BUFFER_SIZE_BYTES / sample_size);
long long size_increase = BUFFER_RESIZE_BYTES / sample_size;
if(size <= 0)
size = size_increase;
else
size += m_specs.rate;
// as long as the end of the stream is not reached
while(!eos)
{
// increase
m_buffer->resize(static_cast<long long>(size) * sample_size, true);
// read more
length = size-index;
reader->read(length, eos, m_buffer->getBuffer() + index * m_specs.channels);
if(index == m_buffer->getSize() / sample_size)
{
size += size_increase;
size_increase <<= 1;
}
index += length;
}
m_buffer->resize(index * sample_size, true);
}
StreamBuffer::StreamBuffer(std::shared_ptr<Buffer> buffer, Specs specs) :
m_buffer(buffer), m_specs(specs)
{
}
std::shared_ptr<Buffer> StreamBuffer::getBuffer()
{
return m_buffer;
}
Specs StreamBuffer::getSpecs()
{
return m_specs;
}
std::shared_ptr<IReader> StreamBuffer::createReader()
{
return std::shared_ptr<IReader>(new BufferReader(m_buffer, m_specs));
}
AUD_NAMESPACE_END

View File

@@ -0,0 +1,60 @@
/*******************************************************************************
* Copyright 2015-2016 Juan Francisco Crespo Galán
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
#include "util/ThreadPool.h"
AUD_NAMESPACE_BEGIN
ThreadPool::ThreadPool(unsigned int count) :
m_stopFlag(false), m_numThreads(count)
{
for(unsigned int i = 0; i < count; i++)
m_threads.emplace_back(&ThreadPool::threadFunction, this);
}
ThreadPool::~ThreadPool()
{
m_mutex.lock();
m_stopFlag = true;
m_mutex.unlock();
m_condition.notify_all();
for(unsigned int i = 0; i < m_threads.size(); i++)
m_threads[i].join();
}
unsigned int ThreadPool::getNumOfThreads()
{
return m_numThreads;
}
void ThreadPool::threadFunction()
{
while(true)
{
std::function<void()> task;
{
std::unique_lock<std::mutex> lock(m_mutex);
m_condition.wait(lock, [this] { return m_stopFlag || !m_queue.empty(); });
if(m_stopFlag && m_queue.empty())
return;
task = std::move(m_queue.front());
this->m_queue.pop();
}
task();
}
}
AUD_NAMESPACE_END