Support GL_SAMPLES queries in null contexts
BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2085043002 Review-Url: https://codereview.chromium.org/2085043002
This commit is contained in:
parent
e6939c15dc
commit
64b92a5929
@ -6,19 +6,97 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "GrNonAtomicRef.h"
|
||||||
#include "gl/GrGLInterface.h"
|
#include "gl/GrGLInterface.h"
|
||||||
#include "GrGLTestInterface.h"
|
#include "GrGLTestInterface.h"
|
||||||
#include "SkMutex.h"
|
#include "SkMutex.h"
|
||||||
#include "SkTDArray.h"
|
#include "SkTDArray.h"
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
// added to suppress 'no previous prototype' warning and because this code is duplicated in
|
// added to suppress 'no previous prototype' warning and because this code is duplicated in
|
||||||
// SkNullGLContext.cpp
|
// SkNullGLContext.cpp
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
class BufferObj {
|
class GLObject : public GrNonAtomicRef<GLObject> {
|
||||||
public:
|
public:
|
||||||
BufferObj(GrGLuint id) : fID(id), fDataPtr(nullptr), fSize(0), fMapped(false) {}
|
GLObject(GrGLuint id) : fID(id) {}
|
||||||
~BufferObj() { delete[] fDataPtr; }
|
GrGLuint id() const { return fID; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
GrGLuint fID;
|
||||||
|
};
|
||||||
|
|
||||||
|
// This class maintains a sparsely populated array of object pointers.
|
||||||
|
template<typename T> class TGLObjectManager {
|
||||||
|
static_assert(std::is_convertible<T*, GLObject*>::value, "T must be a subclass of GLObject");
|
||||||
|
|
||||||
|
public:
|
||||||
|
TGLObjectManager() : fFreeListHead(kFreeListEnd) {
|
||||||
|
*fGLObjects.append() = nullptr; // 0 is not a valid GL object id.
|
||||||
|
}
|
||||||
|
|
||||||
|
~TGLObjectManager() {
|
||||||
|
// nullptr out the entries that are really free list links rather than ptrs before deleting.
|
||||||
|
intptr_t curr = fFreeListHead;
|
||||||
|
while (kFreeListEnd != curr) {
|
||||||
|
intptr_t next = reinterpret_cast<intptr_t>(fGLObjects[SkToS32(curr)]);
|
||||||
|
fGLObjects[SkToS32(curr)] = nullptr;
|
||||||
|
curr = next;
|
||||||
|
}
|
||||||
|
|
||||||
|
fGLObjects.safeUnrefAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
T* lookUp(GrGLuint id) {
|
||||||
|
T* object = fGLObjects[id];
|
||||||
|
SkASSERT(object && object->id() == id);
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
|
||||||
|
T* create() {
|
||||||
|
GrGLuint id;
|
||||||
|
T* object;
|
||||||
|
|
||||||
|
if (kFreeListEnd == fFreeListHead) {
|
||||||
|
// no free slots - create a new one
|
||||||
|
id = fGLObjects.count();
|
||||||
|
object = new T(id);
|
||||||
|
*fGLObjects.append() = object;
|
||||||
|
} else {
|
||||||
|
// grab the head of the free list and advance the head to the next free slot.
|
||||||
|
id = static_cast<GrGLuint>(fFreeListHead);
|
||||||
|
fFreeListHead = reinterpret_cast<intptr_t>(fGLObjects[id]);
|
||||||
|
|
||||||
|
object = new T(id);
|
||||||
|
fGLObjects[id] = object;
|
||||||
|
}
|
||||||
|
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
|
||||||
|
void free(T* object) {
|
||||||
|
SkASSERT(object);
|
||||||
|
SkASSERT(fGLObjects.count() > 0);
|
||||||
|
|
||||||
|
GrGLuint id = object->id();
|
||||||
|
object->unref();
|
||||||
|
|
||||||
|
fGLObjects[id] = reinterpret_cast<T*>(fFreeListHead);
|
||||||
|
fFreeListHead = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
static const intptr_t kFreeListEnd = -1;
|
||||||
|
// Index of the first entry of fGLObjects in the free list. Free slots in fGLObjects are indices
|
||||||
|
// to the next free slot. The last free slot has a value of kFreeListEnd.
|
||||||
|
intptr_t fFreeListHead;
|
||||||
|
SkTDArray<T*> fGLObjects;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Buffer : public GLObject {
|
||||||
|
public:
|
||||||
|
Buffer(GrGLuint id) : INHERITED(id), fDataPtr(nullptr), fSize(0), fMapped(false) {}
|
||||||
|
~Buffer() { delete[] fDataPtr; }
|
||||||
|
|
||||||
void allocate(GrGLsizeiptr size, const GrGLchar* dataPtr) {
|
void allocate(GrGLsizeiptr size, const GrGLchar* dataPtr) {
|
||||||
if (fDataPtr) {
|
if (fDataPtr) {
|
||||||
@ -30,7 +108,6 @@ public:
|
|||||||
fDataPtr = new char[size];
|
fDataPtr = new char[size];
|
||||||
}
|
}
|
||||||
|
|
||||||
GrGLuint id() const { return fID; }
|
|
||||||
GrGLchar* dataPtr() { return fDataPtr; }
|
GrGLchar* dataPtr() { return fDataPtr; }
|
||||||
GrGLsizeiptr size() const { return fSize; }
|
GrGLsizeiptr size() const { return fSize; }
|
||||||
|
|
||||||
@ -38,82 +115,107 @@ public:
|
|||||||
bool mapped() const { return fMapped; }
|
bool mapped() const { return fMapped; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GrGLuint fID;
|
|
||||||
GrGLchar* fDataPtr;
|
GrGLchar* fDataPtr;
|
||||||
GrGLsizeiptr fSize; // size in bytes
|
GrGLsizeiptr fSize; // size in bytes
|
||||||
bool fMapped;
|
bool fMapped;
|
||||||
|
|
||||||
|
typedef GLObject INHERITED;
|
||||||
};
|
};
|
||||||
|
|
||||||
// This class maintains a sparsely populated array of buffer pointers.
|
class FramebufferAttachment : public GLObject {
|
||||||
class BufferManager {
|
|
||||||
public:
|
public:
|
||||||
BufferManager() : fFreeListHead(kFreeListEnd) {
|
FramebufferAttachment(int id) : INHERITED(id), fNumSamples(1) {}
|
||||||
*fBuffers.append() = nullptr; // 0 is not a valid GL buffer id.
|
int numSamples() const { return fNumSamples; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
int fNumSamples;
|
||||||
|
|
||||||
|
typedef GLObject INHERITED;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Renderbuffer : public FramebufferAttachment {
|
||||||
|
public:
|
||||||
|
Renderbuffer(int id) : INHERITED(id) {}
|
||||||
|
void setNumSamples(int numSamples) { fNumSamples = numSamples; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
typedef FramebufferAttachment INHERITED;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Texture : public FramebufferAttachment {
|
||||||
|
public:
|
||||||
|
Texture(int id) : INHERITED(id) {}
|
||||||
|
|
||||||
|
private:
|
||||||
|
typedef FramebufferAttachment INHERITED;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Framebuffer : public GLObject {
|
||||||
|
public:
|
||||||
|
Framebuffer(int id) : INHERITED(id) {}
|
||||||
|
|
||||||
|
void setAttachment(GrGLenum attachmentPoint, const FramebufferAttachment* attachment) {
|
||||||
|
switch (attachmentPoint) {
|
||||||
|
default:
|
||||||
|
SK_ABORT("Invalid framebuffer attachment.");
|
||||||
|
break;
|
||||||
|
case GR_GL_STENCIL_ATTACHMENT:
|
||||||
|
fAttachments[(int)AttachmentPoint::kStencil].reset(SkRef(attachment));
|
||||||
|
break;
|
||||||
|
case GR_GL_DEPTH_ATTACHMENT:
|
||||||
|
fAttachments[(int)AttachmentPoint::kDepth].reset(SkRef(attachment));
|
||||||
|
break;
|
||||||
|
case GR_GL_COLOR_ATTACHMENT0:
|
||||||
|
fAttachments[(int)AttachmentPoint::kColor].reset(SkRef(attachment));
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
~BufferManager() {
|
void notifyAttachmentDeleteWhileBound(const FramebufferAttachment* deleted) {
|
||||||
// nullptr out the entries that are really free list links rather than ptrs before deleting.
|
for (auto& attachment : fAttachments) {
|
||||||
intptr_t curr = fFreeListHead;
|
if (attachment == deleted) {
|
||||||
while (kFreeListEnd != curr) {
|
attachment.reset(nullptr);
|
||||||
intptr_t next = reinterpret_cast<intptr_t>(fBuffers[SkToS32(curr)]);
|
}
|
||||||
fBuffers[SkToS32(curr)] = nullptr;
|
}
|
||||||
curr = next;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fBuffers.deleteAll();
|
int numSamples() const {
|
||||||
|
int numSamples = 0;
|
||||||
|
for (auto& attachment : fAttachments) {
|
||||||
|
if (!attachment) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
if (numSamples) {
|
||||||
BufferObj* lookUp(GrGLuint id) {
|
GrAlwaysAssert(attachment->numSamples() == numSamples);
|
||||||
BufferObj* buffer = fBuffers[id];
|
continue;
|
||||||
SkASSERT(buffer && buffer->id() == id);
|
|
||||||
return buffer;
|
|
||||||
}
|
}
|
||||||
|
numSamples = attachment->numSamples();
|
||||||
BufferObj* create() {
|
|
||||||
GrGLuint id;
|
|
||||||
BufferObj* buffer;
|
|
||||||
|
|
||||||
if (kFreeListEnd == fFreeListHead) {
|
|
||||||
// no free slots - create a new one
|
|
||||||
id = fBuffers.count();
|
|
||||||
buffer = new BufferObj(id);
|
|
||||||
*fBuffers.append() = buffer;
|
|
||||||
} else {
|
|
||||||
// grab the head of the free list and advance the head to the next free slot.
|
|
||||||
id = static_cast<GrGLuint>(fFreeListHead);
|
|
||||||
fFreeListHead = reinterpret_cast<intptr_t>(fBuffers[id]);
|
|
||||||
|
|
||||||
buffer = new BufferObj(id);
|
|
||||||
fBuffers[id] = buffer;
|
|
||||||
}
|
}
|
||||||
|
GrAlwaysAssert(numSamples);
|
||||||
return buffer;
|
return numSamples;
|
||||||
}
|
|
||||||
|
|
||||||
void free(BufferObj* buffer) {
|
|
||||||
SkASSERT(buffer);
|
|
||||||
SkASSERT(fBuffers.count() > 0);
|
|
||||||
|
|
||||||
GrGLuint id = buffer->id();
|
|
||||||
delete buffer;
|
|
||||||
|
|
||||||
fBuffers[id] = reinterpret_cast<BufferObj*>(fFreeListHead);
|
|
||||||
fFreeListHead = id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const intptr_t kFreeListEnd = -1;
|
enum AttachmentPoint {
|
||||||
// Index of the first entry of fBuffers in the free list. Free slots in fBuffers are indices to
|
kStencil,
|
||||||
// the next free slot. The last free slot has a value of kFreeListEnd.
|
kDepth,
|
||||||
intptr_t fFreeListHead;
|
kColor
|
||||||
SkTDArray<BufferObj*> fBuffers;
|
};
|
||||||
|
constexpr int static kNumAttachmentPoints = 1 + (int)AttachmentPoint::kColor;
|
||||||
|
|
||||||
|
SkAutoTUnref<const FramebufferAttachment> fAttachments[kNumAttachmentPoints];
|
||||||
|
|
||||||
|
typedef GLObject INHERITED;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Null interface implementation */
|
/** Null interface implementation */
|
||||||
class NullInterface : public GrGLTestInterface {
|
class NullInterface : public GrGLTestInterface {
|
||||||
public:
|
public:
|
||||||
NullInterface(bool enableNVPR)
|
NullInterface(bool enableNVPR)
|
||||||
: fCurrProgramID(0)
|
: fCurrDrawFramebuffer(0)
|
||||||
|
, fCurrReadFramebuffer(0)
|
||||||
|
, fCurrRenderbuffer(0)
|
||||||
|
, fCurrProgramID(0)
|
||||||
, fCurrShaderID(0)
|
, fCurrShaderID(0)
|
||||||
, fCurrGenericID(0)
|
, fCurrGenericID(0)
|
||||||
, fCurrUniformLocation(0)
|
, fCurrUniformLocation(0)
|
||||||
@ -140,7 +242,7 @@ public:
|
|||||||
|
|
||||||
GrGLvoid genBuffers(GrGLsizei n, GrGLuint* ids) override {
|
GrGLvoid genBuffers(GrGLsizei n, GrGLuint* ids) override {
|
||||||
for (int i = 0; i < n; ++i) {
|
for (int i = 0; i < n; ++i) {
|
||||||
BufferObj* buffer = fBufferManager.create();
|
Buffer* buffer = fBufferManager.create();
|
||||||
ids[i] = buffer->id();
|
ids[i] = buffer->id();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -149,7 +251,7 @@ public:
|
|||||||
GrGLenum usage) override {
|
GrGLenum usage) override {
|
||||||
GrGLuint id = fBoundBuffers[GetBufferIndex(target)];
|
GrGLuint id = fBoundBuffers[GetBufferIndex(target)];
|
||||||
if (id > 0) {
|
if (id > 0) {
|
||||||
BufferObj* buffer = fBufferManager.lookUp(id);
|
Buffer* buffer = fBufferManager.lookUp(id);
|
||||||
buffer->allocate(size, (const GrGLchar*) data);
|
buffer->allocate(size, (const GrGLchar*) data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -184,24 +286,193 @@ public:
|
|||||||
// Then actually "delete" the buffers.
|
// Then actually "delete" the buffers.
|
||||||
for (int i = 0; i < n; ++i) {
|
for (int i = 0; i < n; ++i) {
|
||||||
if (ids[i] > 0) {
|
if (ids[i] > 0) {
|
||||||
BufferObj* buffer = fBufferManager.lookUp(ids[i]);
|
Buffer* buffer = fBufferManager.lookUp(ids[i]);
|
||||||
fBufferManager.free(buffer);
|
fBufferManager.free(buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GrGLvoid genFramebuffers(GrGLsizei n, GrGLuint *framebuffers) override {
|
GrGLvoid genFramebuffers(GrGLsizei n, GrGLuint *framebuffers) override {
|
||||||
this->genGenericIds(n, framebuffers);
|
for (int i = 0; i < n; ++i) {
|
||||||
|
Framebuffer* framebuffer = fFramebufferManager.create();
|
||||||
|
framebuffers[i] = framebuffer->id();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GrGLvoid bindFramebuffer(GrGLenum target, GrGLuint framebuffer) override {
|
||||||
|
SkASSERT(GR_GL_FRAMEBUFFER == target || GR_GL_DRAW_FRAMEBUFFER == target ||
|
||||||
|
GR_GL_READ_FRAMEBUFFER == target);
|
||||||
|
if (GR_GL_READ_FRAMEBUFFER != target) {
|
||||||
|
fCurrDrawFramebuffer = framebuffer;
|
||||||
|
}
|
||||||
|
if (GR_GL_DRAW_FRAMEBUFFER != target) {
|
||||||
|
fCurrReadFramebuffer = framebuffer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GrGLvoid deleteFramebuffers(GrGLsizei n, const GrGLuint* ids) override {
|
||||||
|
for (int i = 0; i < n; ++i) {
|
||||||
|
if (ids[i] == fCurrDrawFramebuffer) {
|
||||||
|
fCurrDrawFramebuffer = 0;
|
||||||
|
}
|
||||||
|
if (ids[i] == fCurrReadFramebuffer) {
|
||||||
|
fCurrReadFramebuffer = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ids[i] > 0) {
|
||||||
|
Framebuffer* framebuffer = fFramebufferManager.lookUp(ids[i]);
|
||||||
|
fFramebufferManager.free(framebuffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GrGLvoid genQueries(GrGLsizei n, GrGLuint *ids) override { this->genGenericIds(n, ids); }
|
GrGLvoid genQueries(GrGLsizei n, GrGLuint *ids) override { this->genGenericIds(n, ids); }
|
||||||
|
|
||||||
GrGLvoid genRenderbuffers(GrGLsizei n, GrGLuint *renderbuffers) override {
|
GrGLvoid genRenderbuffers(GrGLsizei n, GrGLuint *renderbuffers) override {
|
||||||
this->genGenericIds(n, renderbuffers);
|
for (int i = 0; i < n; ++i) {
|
||||||
|
Renderbuffer* renderbuffer = fRenderbufferManager.create();
|
||||||
|
renderbuffers[i] = renderbuffer->id();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GrGLvoid bindRenderbuffer(GrGLenum target, GrGLuint renderbuffer) override {
|
||||||
|
SkASSERT(GR_GL_RENDERBUFFER == target);
|
||||||
|
fCurrRenderbuffer = renderbuffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
GrGLvoid deleteRenderbuffers(GrGLsizei n, const GrGLuint* ids) override {
|
||||||
|
for (int i = 0; i < n; ++i) {
|
||||||
|
if (ids[i] <= 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (ids[i] == fCurrRenderbuffer) {
|
||||||
|
fCurrRenderbuffer = 0;
|
||||||
|
}
|
||||||
|
Renderbuffer* renderbuffer = fRenderbufferManager.lookUp(ids[i]);
|
||||||
|
|
||||||
|
if (fCurrDrawFramebuffer) {
|
||||||
|
Framebuffer* drawFramebuffer = fFramebufferManager.lookUp(fCurrDrawFramebuffer);
|
||||||
|
drawFramebuffer->notifyAttachmentDeleteWhileBound(renderbuffer);
|
||||||
|
}
|
||||||
|
if (fCurrReadFramebuffer) {
|
||||||
|
Framebuffer* readFramebuffer = fFramebufferManager.lookUp(fCurrReadFramebuffer);
|
||||||
|
readFramebuffer->notifyAttachmentDeleteWhileBound(renderbuffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
fRenderbufferManager.free(renderbuffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GrGLvoid renderbufferStorage(GrGLenum target, GrGLenum internalformat, GrGLsizei width,
|
||||||
|
GrGLsizei height) override {
|
||||||
|
GrAlwaysAssert(GR_GL_RENDERBUFFER == target);
|
||||||
|
GrAlwaysAssert(fCurrRenderbuffer);
|
||||||
|
Renderbuffer* renderbuffer = fRenderbufferManager.lookUp(fCurrRenderbuffer);
|
||||||
|
renderbuffer->setNumSamples(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
GrGLvoid renderbufferStorageMultisample(GrGLenum target, GrGLsizei samples,
|
||||||
|
GrGLenum internalformat, GrGLsizei width,
|
||||||
|
GrGLsizei height) override {
|
||||||
|
GrAlwaysAssert(GR_GL_RENDERBUFFER == target);
|
||||||
|
GrAlwaysAssert(samples > 0);
|
||||||
|
GrAlwaysAssert(fCurrRenderbuffer);
|
||||||
|
Renderbuffer* renderbuffer = fRenderbufferManager.lookUp(fCurrRenderbuffer);
|
||||||
|
renderbuffer->setNumSamples(samples);
|
||||||
|
}
|
||||||
|
|
||||||
|
GrGLvoid namedRenderbufferStorage(GrGLuint renderbuffer, GrGLenum GrGLinternalformat,
|
||||||
|
GrGLsizei width, GrGLsizei height) override {
|
||||||
|
SK_ABORT("Not implemented");
|
||||||
|
}
|
||||||
|
|
||||||
|
GrGLvoid namedRenderbufferStorageMultisample(GrGLuint renderbuffer, GrGLsizei samples,
|
||||||
|
GrGLenum GrGLinternalformat, GrGLsizei width,
|
||||||
|
GrGLsizei height) override {
|
||||||
|
SK_ABORT("Not implemented");
|
||||||
|
}
|
||||||
|
|
||||||
|
GrGLvoid framebufferRenderbuffer(GrGLenum target, GrGLenum attachment,
|
||||||
|
GrGLenum renderbuffertarget,
|
||||||
|
GrGLuint renderBufferID) override {
|
||||||
|
GrGLuint id = this->getBoundFramebufferID(target);
|
||||||
|
GrAlwaysAssert(id);
|
||||||
|
Framebuffer* framebuffer = fFramebufferManager.lookUp(id);
|
||||||
|
|
||||||
|
GrAlwaysAssert(GR_GL_RENDERBUFFER == renderbuffertarget);
|
||||||
|
GrAlwaysAssert(fCurrRenderbuffer);
|
||||||
|
Renderbuffer* renderbuffer = fRenderbufferManager.lookUp(fCurrRenderbuffer);
|
||||||
|
|
||||||
|
framebuffer->setAttachment(attachment, renderbuffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
GrGLvoid namedFramebufferRenderbuffer(GrGLuint framebuffer, GrGLenum attachment,
|
||||||
|
GrGLenum renderbuffertarget,
|
||||||
|
GrGLuint renderbuffer) override {
|
||||||
|
SK_ABORT("Not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
GrGLvoid genTextures(GrGLsizei n, GrGLuint *textures) override {
|
GrGLvoid genTextures(GrGLsizei n, GrGLuint *textures) override {
|
||||||
this->genGenericIds(n, textures);
|
for (int i = 0; i < n; ++i) {
|
||||||
|
Texture* texture = fTextureManager.create();
|
||||||
|
textures[i] = texture->id();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GrGLvoid deleteTextures(GrGLsizei n, const GrGLuint* ids) override {
|
||||||
|
for (int i = 0; i < n; ++i) {
|
||||||
|
if (ids[i] <= 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Texture* texture = fTextureManager.lookUp(ids[i]);
|
||||||
|
|
||||||
|
if (fCurrDrawFramebuffer) {
|
||||||
|
Framebuffer* drawFramebuffer = fFramebufferManager.lookUp(fCurrDrawFramebuffer);
|
||||||
|
drawFramebuffer->notifyAttachmentDeleteWhileBound(texture);
|
||||||
|
}
|
||||||
|
if (fCurrReadFramebuffer) {
|
||||||
|
Framebuffer* readFramebuffer = fFramebufferManager.lookUp(fCurrReadFramebuffer);
|
||||||
|
readFramebuffer->notifyAttachmentDeleteWhileBound(texture);
|
||||||
|
}
|
||||||
|
|
||||||
|
fTextureManager.free(texture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GrGLvoid framebufferTexture2D(GrGLenum target, GrGLenum attachment, GrGLenum textarget,
|
||||||
|
GrGLuint textureID, GrGLint level) override {
|
||||||
|
GrGLuint id = this->getBoundFramebufferID(target);
|
||||||
|
GrAlwaysAssert(id);
|
||||||
|
Framebuffer* framebuffer = fFramebufferManager.lookUp(id);
|
||||||
|
|
||||||
|
GrAlwaysAssert(GR_GL_TEXTURE_2D == textarget);
|
||||||
|
Texture* texture = fTextureManager.lookUp(textureID);
|
||||||
|
|
||||||
|
framebuffer->setAttachment(attachment, texture);
|
||||||
|
}
|
||||||
|
|
||||||
|
GrGLvoid framebufferTexture2DMultisample(GrGLenum target, GrGLenum attachment,
|
||||||
|
GrGLenum textarget, GrGLuint texture, GrGLint level,
|
||||||
|
GrGLsizei samples) override {
|
||||||
|
SK_ABORT("Not implemented");
|
||||||
|
}
|
||||||
|
|
||||||
|
GrGLvoid namedFramebufferTexture1D(GrGLuint framebuffer, GrGLenum attachment,
|
||||||
|
GrGLenum textarget, GrGLuint texture,
|
||||||
|
GrGLint level) override {
|
||||||
|
SK_ABORT("Not implemented");
|
||||||
|
}
|
||||||
|
|
||||||
|
GrGLvoid namedFramebufferTexture2D(GrGLuint framebuffer, GrGLenum attachment,
|
||||||
|
GrGLenum textarget, GrGLuint texture,
|
||||||
|
GrGLint level) override {
|
||||||
|
SK_ABORT("Not implemented");
|
||||||
|
}
|
||||||
|
|
||||||
|
GrGLvoid namedFramebufferTexture3D(GrGLuint framebuffer, GrGLenum attachment,
|
||||||
|
GrGLenum textarget, GrGLuint texture, GrGLint level,
|
||||||
|
GrGLint zoffset) override {
|
||||||
|
SK_ABORT("Not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
GrGLvoid genVertexArrays(GrGLsizei n, GrGLuint *arrays) override {
|
GrGLvoid genVertexArrays(GrGLsizei n, GrGLuint *arrays) override {
|
||||||
@ -220,9 +491,12 @@ public:
|
|||||||
case GR_GL_STENCIL_BITS:
|
case GR_GL_STENCIL_BITS:
|
||||||
*params = 8;
|
*params = 8;
|
||||||
break;
|
break;
|
||||||
case GR_GL_SAMPLES:
|
case GR_GL_SAMPLES: {
|
||||||
*params = 1;
|
GrAlwaysAssert(fCurrDrawFramebuffer);
|
||||||
|
Framebuffer* framebuffer = fFramebufferManager.lookUp(fCurrDrawFramebuffer);
|
||||||
|
*params = framebuffer->numSamples();
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case GR_GL_FRAMEBUFFER_BINDING:
|
case GR_GL_FRAMEBUFFER_BINDING:
|
||||||
*params = 0;
|
*params = 0;
|
||||||
break;
|
break;
|
||||||
@ -376,7 +650,7 @@ public:
|
|||||||
GrGLuint id = fBoundBuffers[GetBufferIndex(target)];
|
GrGLuint id = fBoundBuffers[GetBufferIndex(target)];
|
||||||
if (id > 0) {
|
if (id > 0) {
|
||||||
// We just ignore the offset and length here.
|
// We just ignore the offset and length here.
|
||||||
BufferObj* buffer = fBufferManager.lookUp(id);
|
Buffer* buffer = fBufferManager.lookUp(id);
|
||||||
SkASSERT(!buffer->mapped());
|
SkASSERT(!buffer->mapped());
|
||||||
buffer->setMapped(true);
|
buffer->setMapped(true);
|
||||||
return buffer->dataPtr();
|
return buffer->dataPtr();
|
||||||
@ -387,7 +661,7 @@ public:
|
|||||||
GrGLvoid* mapBuffer(GrGLenum target, GrGLenum access) override {
|
GrGLvoid* mapBuffer(GrGLenum target, GrGLenum access) override {
|
||||||
GrGLuint id = fBoundBuffers[GetBufferIndex(target)];
|
GrGLuint id = fBoundBuffers[GetBufferIndex(target)];
|
||||||
if (id > 0) {
|
if (id > 0) {
|
||||||
BufferObj* buffer = fBufferManager.lookUp(id);
|
Buffer* buffer = fBufferManager.lookUp(id);
|
||||||
SkASSERT(!buffer->mapped());
|
SkASSERT(!buffer->mapped());
|
||||||
buffer->setMapped(true);
|
buffer->setMapped(true);
|
||||||
return buffer->dataPtr();
|
return buffer->dataPtr();
|
||||||
@ -400,7 +674,7 @@ public:
|
|||||||
GrGLboolean unmapBuffer(GrGLenum target) override {
|
GrGLboolean unmapBuffer(GrGLenum target) override {
|
||||||
GrGLuint id = fBoundBuffers[GetBufferIndex(target)];
|
GrGLuint id = fBoundBuffers[GetBufferIndex(target)];
|
||||||
if (id > 0) {
|
if (id > 0) {
|
||||||
BufferObj* buffer = fBufferManager.lookUp(id);
|
Buffer* buffer = fBufferManager.lookUp(id);
|
||||||
SkASSERT(buffer->mapped());
|
SkASSERT(buffer->mapped());
|
||||||
buffer->setMapped(false);
|
buffer->setMapped(false);
|
||||||
return GR_GL_TRUE;
|
return GR_GL_TRUE;
|
||||||
@ -416,7 +690,7 @@ public:
|
|||||||
*params = GR_GL_FALSE;
|
*params = GR_GL_FALSE;
|
||||||
GrGLuint id = fBoundBuffers[GetBufferIndex(target)];
|
GrGLuint id = fBoundBuffers[GetBufferIndex(target)];
|
||||||
if (id > 0) {
|
if (id > 0) {
|
||||||
BufferObj* buffer = fBufferManager.lookUp(id);
|
Buffer* buffer = fBufferManager.lookUp(id);
|
||||||
if (buffer->mapped()) {
|
if (buffer->mapped()) {
|
||||||
*params = GR_GL_TRUE;
|
*params = GR_GL_TRUE;
|
||||||
}
|
}
|
||||||
@ -448,8 +722,14 @@ private:
|
|||||||
}
|
}
|
||||||
constexpr int static kNumBufferTargets = 6;
|
constexpr int static kNumBufferTargets = 6;
|
||||||
|
|
||||||
BufferManager fBufferManager;
|
TGLObjectManager<Buffer> fBufferManager;
|
||||||
GrGLuint fBoundBuffers[kNumBufferTargets];
|
GrGLuint fBoundBuffers[kNumBufferTargets];
|
||||||
|
TGLObjectManager<Framebuffer> fFramebufferManager;
|
||||||
|
GrGLuint fCurrDrawFramebuffer;
|
||||||
|
GrGLuint fCurrReadFramebuffer;
|
||||||
|
TGLObjectManager<Renderbuffer> fRenderbufferManager;
|
||||||
|
GrGLuint fCurrRenderbuffer;
|
||||||
|
TGLObjectManager<Texture> fTextureManager;
|
||||||
GrGLuint fCurrProgramID;
|
GrGLuint fCurrProgramID;
|
||||||
GrGLuint fCurrShaderID;
|
GrGLuint fCurrShaderID;
|
||||||
GrGLuint fCurrGenericID;
|
GrGLuint fCurrGenericID;
|
||||||
@ -469,6 +749,19 @@ private:
|
|||||||
// the OpenGLES 2.0 spec says this must be >= 8
|
// the OpenGLES 2.0 spec says this must be >= 8
|
||||||
static const GrGLint kDefaultMaxVaryingVectors = 8;
|
static const GrGLint kDefaultMaxVaryingVectors = 8;
|
||||||
|
|
||||||
|
GrGLuint getBoundFramebufferID(GrGLenum target) {
|
||||||
|
switch (target) {
|
||||||
|
case GR_GL_FRAMEBUFFER:
|
||||||
|
case GR_GL_DRAW_FRAMEBUFFER:
|
||||||
|
return fCurrDrawFramebuffer;
|
||||||
|
case GR_GL_READ_FRAMEBUFFER:
|
||||||
|
return fCurrReadFramebuffer;
|
||||||
|
default:
|
||||||
|
SK_ABORT("Invalid framebuffer target.");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const GrGLubyte* CombinedExtensionString() {
|
const GrGLubyte* CombinedExtensionString() {
|
||||||
static SkString gExtString;
|
static SkString gExtString;
|
||||||
static SkMutex gMutex;
|
static SkMutex gMutex;
|
||||||
|
@ -373,6 +373,34 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GrGLvoid renderbufferStorage(GrGLenum target, GrGLenum internalformat, GrGLsizei width,
|
||||||
|
GrGLsizei height) override {
|
||||||
|
GrAlwaysAssert(GR_GL_RENDERBUFFER == target);
|
||||||
|
GrRenderBufferObj* renderBuffer = this->getRenderBuffer();
|
||||||
|
GrAlwaysAssert(renderBuffer);
|
||||||
|
renderBuffer->setNumSamples(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
GrGLvoid renderbufferStorageMultisample(GrGLenum target, GrGLsizei samples,
|
||||||
|
GrGLenum internalformat, GrGLsizei width,
|
||||||
|
GrGLsizei height) override {
|
||||||
|
GrAlwaysAssert(GR_GL_RENDERBUFFER == target);
|
||||||
|
GrRenderBufferObj* renderBuffer = this->getRenderBuffer();
|
||||||
|
GrAlwaysAssert(renderBuffer);
|
||||||
|
renderBuffer->setNumSamples(samples);
|
||||||
|
}
|
||||||
|
|
||||||
|
GrGLvoid namedRenderbufferStorage(GrGLuint renderbuffer, GrGLenum GrGLinternalformat,
|
||||||
|
GrGLsizei width, GrGLsizei height) override {
|
||||||
|
SK_ABORT("Not implemented");
|
||||||
|
}
|
||||||
|
|
||||||
|
GrGLvoid namedRenderbufferStorageMultisample(GrGLuint renderbuffer, GrGLsizei samples,
|
||||||
|
GrGLenum GrGLinternalformat, GrGLsizei width,
|
||||||
|
GrGLsizei height) override {
|
||||||
|
SK_ABORT("Not implemented");
|
||||||
|
}
|
||||||
|
|
||||||
GrGLvoid framebufferRenderbuffer(GrGLenum target,
|
GrGLvoid framebufferRenderbuffer(GrGLenum target,
|
||||||
GrGLenum attachment,
|
GrGLenum attachment,
|
||||||
GrGLenum renderbuffertarget,
|
GrGLenum renderbuffertarget,
|
||||||
@ -410,6 +438,12 @@ public:
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GrGLvoid namedFramebufferRenderbuffer(GrGLuint framebuffer, GrGLenum attachment,
|
||||||
|
GrGLenum renderbuffertarget,
|
||||||
|
GrGLuint renderbuffer) override {
|
||||||
|
SK_ABORT("Not implemented");
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
GrGLvoid framebufferTexture2D(GrGLenum target, GrGLenum attachment, GrGLenum textarget,
|
GrGLvoid framebufferTexture2D(GrGLenum target, GrGLenum attachment, GrGLenum textarget,
|
||||||
GrGLuint textureID, GrGLint level) override {
|
GrGLuint textureID, GrGLint level) override {
|
||||||
@ -450,6 +484,30 @@ public:
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GrGLvoid framebufferTexture2DMultisample(GrGLenum target, GrGLenum attachment,
|
||||||
|
GrGLenum textarget, GrGLuint texture, GrGLint level,
|
||||||
|
GrGLsizei samples) override {
|
||||||
|
SK_ABORT("Not implemented");
|
||||||
|
}
|
||||||
|
|
||||||
|
GrGLvoid namedFramebufferTexture1D(GrGLuint framebuffer, GrGLenum attachment,
|
||||||
|
GrGLenum textarget, GrGLuint texture,
|
||||||
|
GrGLint level) override {
|
||||||
|
SK_ABORT("Not implemented");
|
||||||
|
}
|
||||||
|
|
||||||
|
GrGLvoid namedFramebufferTexture2D(GrGLuint framebuffer, GrGLenum attachment,
|
||||||
|
GrGLenum textarget, GrGLuint texture,
|
||||||
|
GrGLint level) override {
|
||||||
|
SK_ABORT("Not implemented");
|
||||||
|
}
|
||||||
|
|
||||||
|
GrGLvoid namedFramebufferTexture3D(GrGLuint framebuffer, GrGLenum attachment,
|
||||||
|
GrGLenum textarget, GrGLuint texture, GrGLint level,
|
||||||
|
GrGLint zoffset) override {
|
||||||
|
SK_ABORT("Not implemented");
|
||||||
|
}
|
||||||
|
|
||||||
GrGLuint createProgram() override {
|
GrGLuint createProgram() override {
|
||||||
|
|
||||||
GrProgramObj *program = CREATE(GrProgramObj, kProgram_ObjTypes);
|
GrProgramObj *program = CREATE(GrProgramObj, kProgram_ObjTypes);
|
||||||
@ -530,9 +588,26 @@ public:
|
|||||||
case GR_GL_STENCIL_BITS:
|
case GR_GL_STENCIL_BITS:
|
||||||
*params = 8;
|
*params = 8;
|
||||||
break;
|
break;
|
||||||
case GR_GL_SAMPLES:
|
case GR_GL_SAMPLES: {
|
||||||
*params = 1;
|
GrFrameBufferObj* framebuffer = this->getFrameBuffer();
|
||||||
|
GrAlwaysAssert(framebuffer);
|
||||||
|
int numSamples = 0;
|
||||||
|
|
||||||
|
if (GrFBBindableObj* stencil = framebuffer->getStencil()) {
|
||||||
|
numSamples = stencil->numSamples();
|
||||||
|
}
|
||||||
|
if (GrFBBindableObj* depth = framebuffer->getDepth()) {
|
||||||
|
GrAlwaysAssert(!numSamples || numSamples == depth->numSamples());
|
||||||
|
numSamples = depth->numSamples();
|
||||||
|
}
|
||||||
|
if (GrFBBindableObj* color = framebuffer->getColor()) {
|
||||||
|
GrAlwaysAssert(!numSamples || numSamples == color->numSamples());
|
||||||
|
numSamples = color->numSamples();
|
||||||
|
}
|
||||||
|
GrAlwaysAssert(numSamples);
|
||||||
|
*params = numSamples;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case GR_GL_FRAMEBUFFER_BINDING:
|
case GR_GL_FRAMEBUFFER_BINDING:
|
||||||
*params = 0;
|
*params = 0;
|
||||||
break;
|
break;
|
||||||
|
@ -18,7 +18,8 @@ class GrFBBindableObj : public GrFakeRefObj {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
GrFBBindableObj()
|
GrFBBindableObj()
|
||||||
: GrFakeRefObj() {
|
: GrFakeRefObj()
|
||||||
|
, fNumSamples(1) {
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~GrFBBindableObj() {
|
virtual ~GrFBBindableObj() {
|
||||||
@ -75,8 +76,11 @@ public:
|
|||||||
return 0 != fStencilReferees.count();
|
return 0 != fStencilReferees.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int numSamples() { return fNumSamples; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
int fNumSamples;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SkTDArray<GrFakeRefObj *> fColorReferees; // frame buffers that use this as a color buffer (via "glFramebufferRenderbuffer" or "glFramebufferTexture2D")
|
SkTDArray<GrFakeRefObj *> fColorReferees; // frame buffers that use this as a color buffer (via "glFramebufferRenderbuffer" or "glFramebufferTexture2D")
|
||||||
SkTDArray<GrFakeRefObj *> fDepthReferees; // frame buffers that use this as a depth buffer (via "glFramebufferRenderbuffer" or "glFramebufferTexture2D")
|
SkTDArray<GrFakeRefObj *> fDepthReferees; // frame buffers that use this as a depth buffer (via "glFramebufferRenderbuffer" or "glFramebufferTexture2D")
|
||||||
|
@ -30,6 +30,11 @@ public:
|
|||||||
this->INHERITED::deleteAction();
|
this->INHERITED::deleteAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setNumSamples(int numSamples) {
|
||||||
|
GrAlwaysAssert(numSamples > 0);
|
||||||
|
fNumSamples = numSamples;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
private:
|
private:
|
||||||
bool fBound; // is this render buffer currently bound via "glBindRenderbuffer"?
|
bool fBound; // is this render buffer currently bound via "glBindRenderbuffer"?
|
||||||
|
Loading…
Reference in New Issue
Block a user