2014-09-17 22:08:41 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "WebGL2Context.h"
|
2014-12-05 07:04:55 +00:00
|
|
|
|
2014-09-17 22:08:41 +00:00
|
|
|
#include "GLContext.h"
|
2014-12-05 07:04:55 +00:00
|
|
|
#include "WebGLBuffer.h"
|
2015-07-15 00:37:28 +00:00
|
|
|
#include "WebGLTransformFeedback.h"
|
2014-09-17 22:08:41 +00:00
|
|
|
|
2015-07-15 00:37:28 +00:00
|
|
|
namespace mozilla {
|
2014-09-17 22:08:41 +00:00
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
// Buffer objects
|
|
|
|
|
|
|
|
void
|
2014-12-05 07:04:55 +00:00
|
|
|
WebGL2Context::CopyBufferSubData(GLenum readTarget, GLenum writeTarget,
|
|
|
|
GLintptr readOffset, GLintptr writeOffset,
|
|
|
|
GLsizeiptr size)
|
2014-09-17 22:08:41 +00:00
|
|
|
{
|
2016-06-14 16:02:01 +00:00
|
|
|
const char funcName[] = "copyBufferSubData";
|
2014-12-05 07:04:55 +00:00
|
|
|
if (IsContextLost())
|
|
|
|
return;
|
|
|
|
|
2016-09-10 04:02:54 +00:00
|
|
|
const auto& readBuffer = ValidateBufferSelection(funcName, readTarget);
|
|
|
|
if (!readBuffer)
|
2014-12-05 07:04:55 +00:00
|
|
|
return;
|
|
|
|
|
2016-09-10 04:02:54 +00:00
|
|
|
const auto& writeBuffer = ValidateBufferSelection(funcName, writeTarget);
|
|
|
|
if (!writeBuffer)
|
2014-12-05 07:04:55 +00:00
|
|
|
return;
|
|
|
|
|
2016-09-10 04:02:54 +00:00
|
|
|
if (readBuffer->mNumActiveTFOs ||
|
|
|
|
writeBuffer->mNumActiveTFOs)
|
|
|
|
{
|
|
|
|
ErrorInvalidOperation("%s: Buffer is bound to an active transform feedback"
|
|
|
|
" object.",
|
|
|
|
funcName);
|
2016-06-14 16:02:01 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-12-05 07:04:55 +00:00
|
|
|
|
2016-09-10 04:02:54 +00:00
|
|
|
if (!ValidateNonNegative(funcName, "readOffset", readOffset) ||
|
|
|
|
!ValidateNonNegative(funcName, "writeOffset", writeOffset) ||
|
|
|
|
!ValidateNonNegative(funcName, "size", size))
|
|
|
|
{
|
2014-12-05 07:04:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-10 04:02:54 +00:00
|
|
|
const auto fnValidateOffsetSize = [&](const char* info, GLintptr offset,
|
|
|
|
const WebGLBuffer* buffer)
|
|
|
|
{
|
|
|
|
const auto neededBytes = CheckedInt<size_t>(offset) + size;
|
|
|
|
if (!neededBytes.isValid() || neededBytes.value() > buffer->ByteLength()) {
|
|
|
|
ErrorInvalidValue("%s: Invalid %s range.", funcName, info);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
2016-06-14 16:02:01 +00:00
|
|
|
|
2016-09-10 04:02:54 +00:00
|
|
|
if (!fnValidateOffsetSize("read", readOffset, readBuffer) ||
|
|
|
|
!fnValidateOffsetSize("write", writeOffset, writeBuffer))
|
|
|
|
{
|
2014-12-05 07:04:55 +00:00
|
|
|
return;
|
2016-09-10 04:02:54 +00:00
|
|
|
}
|
2014-12-05 07:04:55 +00:00
|
|
|
|
2016-09-10 04:02:54 +00:00
|
|
|
if (readBuffer == writeBuffer &&
|
2016-06-14 16:02:01 +00:00
|
|
|
!ValidateDataRanges(readOffset, writeOffset, size, funcName))
|
2014-12-05 07:04:55 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-10 04:02:54 +00:00
|
|
|
const auto& readType = readBuffer->Content();
|
|
|
|
const auto& writeType = writeBuffer->Content();
|
|
|
|
MOZ_ASSERT(readType != WebGLBuffer::Kind::Undefined);
|
|
|
|
MOZ_ASSERT(writeType != WebGLBuffer::Kind::Undefined);
|
|
|
|
if (writeType != readType) {
|
2016-06-14 16:02:01 +00:00
|
|
|
ErrorInvalidOperation("%s: Can't copy %s data to %s data.",
|
|
|
|
funcName,
|
|
|
|
(readType == WebGLBuffer::Kind::OtherData) ? "other"
|
|
|
|
: "element",
|
|
|
|
(writeType == WebGLBuffer::Kind::OtherData) ? "other"
|
|
|
|
: "element");
|
2015-05-20 23:59:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-10 04:02:54 +00:00
|
|
|
gl->MakeCurrent();
|
2016-09-26 20:38:56 +00:00
|
|
|
const ScopedLazyBind readBind(gl, readTarget, readBuffer);
|
|
|
|
const ScopedLazyBind writeBind(gl, writeTarget, writeBuffer);
|
2016-09-10 04:02:54 +00:00
|
|
|
gl->fCopyBufferSubData(readTarget, writeTarget, readOffset, writeOffset, size);
|
2014-09-17 22:08:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-10-12 00:38:45 +00:00
|
|
|
WebGL2Context::GetBufferSubData(GLenum target, GLintptr srcByteOffset,
|
|
|
|
const dom::ArrayBufferView& dstData, GLuint dstElemOffset,
|
|
|
|
GLuint dstElemCountOverride)
|
2014-09-17 22:08:41 +00:00
|
|
|
{
|
2016-06-14 16:02:01 +00:00
|
|
|
const char funcName[] = "getBufferSubData";
|
2015-04-17 01:20:22 +00:00
|
|
|
if (IsContextLost())
|
|
|
|
return;
|
2015-05-22 05:49:30 +00:00
|
|
|
|
2016-10-12 00:38:45 +00:00
|
|
|
if (!ValidateNonNegative(funcName, "srcByteOffset", srcByteOffset))
|
2015-04-17 01:20:22 +00:00
|
|
|
return;
|
2014-09-17 22:08:41 +00:00
|
|
|
|
2016-10-12 00:38:45 +00:00
|
|
|
uint8_t* bytes;
|
|
|
|
size_t byteLen;
|
|
|
|
if (!ValidateArrayBufferView(funcName, dstData, dstElemOffset, dstElemCountOverride,
|
|
|
|
&bytes, &byteLen))
|
|
|
|
{
|
2016-06-14 16:02:01 +00:00
|
|
|
return;
|
2016-10-12 00:38:45 +00:00
|
|
|
}
|
2015-04-17 01:20:22 +00:00
|
|
|
|
2016-09-10 04:02:54 +00:00
|
|
|
////
|
2015-05-22 05:49:30 +00:00
|
|
|
|
2016-10-12 00:38:45 +00:00
|
|
|
const auto& buffer = ValidateBufferSelection(funcName, target);
|
|
|
|
if (!buffer)
|
2015-04-17 01:20:22 +00:00
|
|
|
return;
|
|
|
|
|
2016-10-12 00:38:45 +00:00
|
|
|
if (!buffer->ValidateRange(funcName, srcByteOffset, byteLen))
|
2015-04-17 01:20:22 +00:00
|
|
|
return;
|
|
|
|
|
2016-09-10 04:02:54 +00:00
|
|
|
////
|
2015-04-17 01:20:22 +00:00
|
|
|
|
2016-09-10 04:02:54 +00:00
|
|
|
if (buffer->mNumActiveTFOs) {
|
|
|
|
ErrorInvalidOperation("%s: Buffer is bound to an active transform feedback"
|
|
|
|
" object.",
|
|
|
|
funcName);
|
|
|
|
return;
|
|
|
|
}
|
2015-04-17 01:20:22 +00:00
|
|
|
|
2016-09-10 04:02:54 +00:00
|
|
|
if (target == LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER &&
|
|
|
|
mBoundTransformFeedback->mIsActive)
|
|
|
|
{
|
|
|
|
ErrorInvalidOperation("%s: Currently bound transform feedback is active.",
|
|
|
|
funcName);
|
|
|
|
return;
|
2015-04-17 01:20:22 +00:00
|
|
|
}
|
|
|
|
|
2016-10-12 00:38:45 +00:00
|
|
|
if (!CheckedInt<GLsizeiptr>(byteLen).isValid()) {
|
|
|
|
ErrorOutOfMemory("%s: Size too large.", funcName);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const GLsizeiptr glByteLen(byteLen);
|
|
|
|
|
2016-09-10 04:02:54 +00:00
|
|
|
////
|
|
|
|
|
|
|
|
gl->MakeCurrent();
|
2016-09-26 20:38:56 +00:00
|
|
|
const ScopedLazyBind readBind(gl, target, buffer);
|
2015-04-17 01:20:22 +00:00
|
|
|
|
2016-10-12 00:38:45 +00:00
|
|
|
const auto mappedBytes = gl->fMapBufferRange(target, srcByteOffset, glByteLen,
|
|
|
|
LOCAL_GL_MAP_READ_BIT);
|
2015-11-26 11:47:53 +00:00
|
|
|
// Warning: Possibly shared memory. See bug 1225033.
|
2016-10-12 00:38:45 +00:00
|
|
|
if (byteLen) {
|
|
|
|
memcpy(bytes, mappedBytes, byteLen);
|
|
|
|
}
|
2015-04-17 01:20:22 +00:00
|
|
|
gl->fUnmapBuffer(target);
|
2014-09-17 22:08:41 +00:00
|
|
|
}
|
2015-07-15 00:37:28 +00:00
|
|
|
|
|
|
|
} // namespace mozilla
|