void AudioBufferSourceHandler::setBuffer(AudioBuffer* buffer, ExceptionState& exceptionState) { ASSERT(isMainThread()); if (m_buffer) { exceptionState.throwDOMException( InvalidStateError, "Cannot set buffer after it has been already been set"); return; } // The context must be locked since changing the buffer can re-configure the number of channels that are output. AbstractAudioContext::AutoLocker contextLocker(context()); // This synchronizes with process(). MutexLocker processLocker(m_processLock); if (buffer) { // Do any necesssary re-configuration to the buffer's number of channels. unsigned numberOfChannels = buffer->numberOfChannels(); // This should not be possible since AudioBuffers can't be created with too many channels // either. if (numberOfChannels > AbstractAudioContext::maxNumberOfChannels()) { exceptionState.throwDOMException( NotSupportedError, ExceptionMessages::indexOutsideRange( "number of input channels", numberOfChannels, 1u, ExceptionMessages::InclusiveBound, AbstractAudioContext::maxNumberOfChannels(), ExceptionMessages::InclusiveBound)); return; } output(0).setNumberOfChannels(numberOfChannels); m_sourceChannels = wrapArrayUnique(new const float* [numberOfChannels]); m_destinationChannels = wrapArrayUnique(new float* [numberOfChannels]); for (unsigned i = 0; i < numberOfChannels; ++i) m_sourceChannels[i] = buffer->getChannelData(i)->data(); // If this is a grain (as set by a previous call to start()), validate the grain parameters // now since it wasn't validated when start was called (because there was no buffer then). if (m_isGrain) clampGrainParameters(buffer); } m_virtualReadIndex = 0; m_buffer = buffer; }
sk_sp<SkImageFilter> FEConvolveMatrix::createImageFilter() { if (!parametersValid()) return createTransparentBlack(); sk_sp<SkImageFilter> input( SkiaImageFilterBuilder::build(inputEffect(0), operatingColorSpace())); SkISize kernelSize( SkISize::Make(m_kernelSize.width(), m_kernelSize.height())); // parametersValid() above checks that the kernel area fits in int. int numElements = safeCast<int>(m_kernelSize.area()); SkScalar gain = SkFloatToScalar(1.0f / m_divisor); SkScalar bias = SkFloatToScalar(m_bias * 255); SkIPoint target = SkIPoint::Make(m_targetOffset.x(), m_targetOffset.y()); SkMatrixConvolutionImageFilter::TileMode tileMode = toSkiaTileMode(m_edgeMode); bool convolveAlpha = !m_preserveAlpha; std::unique_ptr<SkScalar[]> kernel = wrapArrayUnique(new SkScalar[numElements]); for (int i = 0; i < numElements; ++i) kernel[i] = SkFloatToScalar(m_kernelMatrix[numElements - 1 - i]); SkImageFilter::CropRect cropRect = getCropRect(); return SkMatrixConvolutionImageFilter::Make( kernelSize, kernel.get(), gain, bias, target, tileMode, convolveAlpha, std::move(input), &cropRect); }
TEST(SharedBufferTest, getAsBytesLargeSegments) { Vector<char> vector0(0x4000); for (size_t i = 0; i < vector0.size(); ++i) vector0[i] = 'a'; Vector<char> vector1(0x4000); for (size_t i = 0; i < vector1.size(); ++i) vector1[i] = 'b'; Vector<char> vector2(0x4000); for (size_t i = 0; i < vector2.size(); ++i) vector2[i] = 'c'; RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::adoptVector(vector0); sharedBuffer->append(vector1); sharedBuffer->append(vector2); const size_t size = sharedBuffer->size(); std::unique_ptr<char[]> data = wrapArrayUnique(new char[size]); sharedBuffer->getAsBytes(data.get(), size); ASSERT_EQ(0x4000U + 0x4000U + 0x4000U, size); int position = 0; for (int i = 0; i < 0x4000; ++i) { EXPECT_EQ('a', data[position]); ++position; } for (int i = 0; i < 0x4000; ++i) { EXPECT_EQ('b', data[position]); ++position; } for (int i = 0; i < 0x4000; ++i) { EXPECT_EQ('c', data[position]); ++position; } }
HarfBuzzShaper::HarfBuzzShaper(const Font* font, const TextRun& run) : Shaper(font, run), m_normalizedBufferLength(0) { m_normalizedBuffer = wrapArrayUnique(new UChar[m_textRun.length() + 1]); normalizeCharacters(m_textRun, m_textRun.length(), m_normalizedBuffer.get(), &m_normalizedBufferLength); setFontFeatures(); }
sk_sp<SkImageFilter> FEMerge::createImageFilter() { unsigned size = numberOfEffectInputs(); std::unique_ptr<sk_sp<SkImageFilter>[]> inputRefs = wrapArrayUnique(new sk_sp<SkImageFilter>[size]); for (unsigned i = 0; i < size; ++i) inputRefs[i] = SkiaImageFilterBuilder::build(inputEffect(i), operatingColorSpace()); SkImageFilter::CropRect rect = getCropRect(); return SkMergeImageFilter::Make(inputRefs.get(), size, 0, &rect); }
static void vprintf_stderr_with_trailing_newline(const char* format, va_list args) { size_t formatLength = strlen(format); if (formatLength && format[formatLength - 1] == '\n') { vprintf_stderr_common(format, args); return; } std::unique_ptr<char[]> formatWithNewline = wrapArrayUnique(new char[formatLength + 2]); memcpy(formatWithNewline.get(), format, formatLength); formatWithNewline[formatLength] = '\n'; formatWithNewline[formatLength + 1] = 0; vprintf_stderr_common(formatWithNewline.get(), args); }
void V8Document::openMethodCustom( const v8::FunctionCallbackInfo<v8::Value>& info) { Document* document = V8Document::toImpl(info.Holder()); if (info.Length() > 2) { LocalFrame* frame = document->frame(); if (!frame) return; // Fetch the global object for the frame. v8::Local<v8::Context> context = toV8Context(frame, DOMWrapperWorld::current(info.GetIsolate())); // Bail out if we cannot get the context. if (context.IsEmpty()) return; v8::Local<v8::Object> global = context->Global(); // Get the open property of the global object. v8::Local<v8::Value> function = global->Get(v8AtomicString(info.GetIsolate(), "open")); // Failed; return without throwing (new) exception. if (function.IsEmpty()) return; // If the open property is not a function throw a type error. if (!function->IsFunction()) { V8ThrowException::throwTypeError(info.GetIsolate(), "open is not a function"); return; } // Wrap up the arguments and call the function. std::unique_ptr<v8::Local<v8::Value>[]> params = wrapArrayUnique(new v8::Local<v8::Value>[ info.Length() ]); for (int i = 0; i < info.Length(); i++) params[i] = info[i]; v8SetReturnValue( info, V8ScriptRunner::callFunction( v8::Local<v8::Function>::Cast(function), frame->document(), global, info.Length(), params.get(), info.GetIsolate())); return; } ExceptionState exceptionState(ExceptionState::ExecutionContext, "open", "Document", info.Holder(), info.GetIsolate()); document->open(enteredDOMWindow(info.GetIsolate())->document(), exceptionState); v8SetReturnValue(info, info.Holder()); }
TEST(SharedBufferTest, getAsBytes) { char testData0[] = "Hello"; char testData1[] = "World"; char testData2[] = "Goodbye"; RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create(testData0, strlen(testData0)); sharedBuffer->append(testData1, strlen(testData1)); sharedBuffer->append(testData2, strlen(testData2)); const size_t size = sharedBuffer->size(); std::unique_ptr<char[]> data = wrapArrayUnique(new char[size]); sharedBuffer->getAsBytes(data.get(), size); char expectedConcatenation[] = "HelloWorldGoodbye"; ASSERT_EQ(strlen(expectedConcatenation), size); EXPECT_EQ(0, memcmp(expectedConcatenation, data.get(), strlen(expectedConcatenation))); }
TEST(SharedBufferTest, getPartAsBytes) { char testData0[] = "Hello"; char testData1[] = "World"; char testData2[] = "Goodbye"; RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create(testData0, strlen(testData0)); sharedBuffer->append(testData1, strlen(testData1)); sharedBuffer->append(testData2, strlen(testData2)); struct TestData { size_t position; size_t size; const char* expected; } testData[] = { {0, 17, "HelloWorldGoodbye"}, {0, 7, "HelloWo"}, {4, 7, "oWorldG"}, }; for (TestData& test : testData) { std::unique_ptr<char[]> data = wrapArrayUnique(new char[test.size]); ASSERT_TRUE( sharedBuffer->getPartAsBytes(data.get(), test.position, test.size)); EXPECT_EQ(0, memcmp(test.expected, data.get(), test.size)); } }