void Buffer::BlockCopy(T src[], int srcOffset, T dst[], int dstOffset, int count) { if (src == null) throw ArgumentNullException("src"); if (dst == null) throw ArgumentNullException("dst"); if (srcOffset < 0) throw ArgumentOutOfRangeException("srcOffset", "Non-negative number required."); if (dstOffset < 0) throw ArgumentOutOfRangeException("dstOffset", "Non-negative number required."); if (count < 0) throw ArgumentOutOfRangeException("count", "Non-negative number required."); if ((srcOffset > ByteLength(src) - count) || (dstOffset > ByteLength(dst) - count)) throw ArgumentException("Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection."); for(int i = srcOffset, j = dstOffset; i < (srcOffset + count); i++, j++) { dst[j] = src[i]; } }
void Buffer::SetByte(T array[], int index, byte value) { if (index < 0 || index >= ByteLength(array)) throw ArgumentOutOfRangeException ("index", "Value must be non-negative and less than the size of the collection."); SetByteInternal(array, index, value); }
byte Buffer::GetByte(T array[], int index) { if (index < 0 || index >= ByteLength(array)) throw ArgumentOutOfRangeException("index", "Value must be non-negative and less than the size of the collection."); return ((byte *) &array[index]); }
void WebGLBuffer::BufferData(GLenum target, size_t size, const void* data, GLenum usage) { const char funcName[] = "bufferData"; if (!ValidateBufferUsageEnum(mContext, funcName, usage)) return; if (mNumActiveTFOs) { mContext->ErrorInvalidOperation("%s: Buffer is bound to an active transform" " feedback object.", funcName); return; } const auto& gl = mContext->gl; gl->MakeCurrent(); const ScopedLazyBind lazyBind(gl, target, this); mContext->InvalidateBufferFetching(); #ifdef XP_MACOSX // bug 790879 if (gl->WorkAroundDriverBugs() && size > INT32_MAX) { mContext->ErrorOutOfMemory("%s: Allocation size too large.", funcName); return; } #endif const bool sizeChanges = (size != ByteLength()); if (sizeChanges) { gl::GLContext::LocalErrorScope errorScope(*gl); gl->fBufferData(target, size, data, usage); const auto error = errorScope.GetError(); if (error) { MOZ_ASSERT(error == LOCAL_GL_OUT_OF_MEMORY); mContext->ErrorOutOfMemory("%s: Error from driver: 0x%04x", funcName, error); return; } } else { gl->fBufferData(target, size, data, usage); } mUsage = usage; mByteLength = size; // Warning: Possibly shared memory. See bug 1225033. if (!ElementArrayCacheBufferData(data, size)) { mByteLength = 0; mContext->ErrorOutOfMemory("%s: Failed update index buffer cache.", funcName); } }
// equals operator bool Bitstream::operator==( const Bitstream& stream ) const { if( ByteLength() != stream.ByteLength() ) return false; if( mFront != stream.mFront ) return false; std::vector<uint8_t>::const_iterator my_itr = mStream.begin(); std::vector<uint8_t>::const_iterator my_end = mStream.end(); std::vector<uint8_t>::const_iterator stream_itr = stream.mStream.begin(); for( ; my_itr != my_end; ++my_itr, ++stream_itr ) { if( *my_itr != *stream_itr ) return false; } return true; }
void BitVector::SetAllTrue() { memset(array_, ~0, ByteLength()); }
void BitVector::SetAllFalse() { memset(array_, 0, ByteLength()); }
BitVector& BitVector::operator=(const BitVector& src) { Alloc(src.bit_size_); memcpy(array_, src.array_, ByteLength()); return *this; }
BitVector::BitVector(const BitVector& src) : bit_size_(src.bit_size_) { array_ = new uinT32[WordLength()]; memcpy(array_, src.array_, ByteLength()); }
void WebGLBuffer::BufferData(GLenum target, size_t size, const void* data, GLenum usage) { // Careful: data.Length() could conceivably be any uint32_t, but GLsizeiptr // is like intptr_t. if (!CheckedInt<GLsizeiptr>(size).isValid()) return mContext->ErrorOutOfMemory("bad size"); if (!ValidateBufferUsageEnum(mContext, usage)) return; #ifdef XP_MACOSX // bug 790879 if (mContext->gl->WorkAroundDriverBugs() && size > INT32_MAX) { mContext->ErrorOutOfMemory("Allocation size too large."); return; } #endif const void* uploadData = data; UniqueBuffer newIndexCache; if (target == LOCAL_GL_ELEMENT_ARRAY_BUFFER && mContext->mNeedsIndexValidation) { newIndexCache = malloc(size); if (!newIndexCache) { mContext->ErrorOutOfMemory("Failed to alloc index cache."); return; } memcpy(newIndexCache.get(), data, size); uploadData = newIndexCache.get(); } const auto& gl = mContext->gl; const ScopedLazyBind lazyBind(gl, target, this); const bool sizeChanges = (size != ByteLength()); if (sizeChanges) { gl::GLContext::LocalErrorScope errorScope(*gl); gl->fBufferData(target, size, uploadData, usage); const auto error = errorScope.GetError(); if (error) { MOZ_ASSERT(error == LOCAL_GL_OUT_OF_MEMORY); mContext->ErrorOutOfMemory("Error from driver: 0x%04x", error); return; } } else { gl->fBufferData(target, size, uploadData, usage); } mContext->OnDataAllocCall(); mUsage = usage; mByteLength = size; mFetchInvalidator.InvalidateCaches(); mIndexCache = std::move(newIndexCache); if (mIndexCache) { if (!mIndexRanges.empty()) { mContext->GeneratePerfWarning("[%p] Invalidating %u ranges.", this, uint32_t(mIndexRanges.size())); mIndexRanges.clear(); } } ResetLastUpdateFenceId(); }