Fix usage enum with GL_NV_pixel_buffer_object.
This extensions adds PBOs but not new enum values for <usage>. Only the
ES2 enum values of STREAM_DRAW, STATIC_DRAW, and DYNAMIC_DRAW are valid.
Also change TransferBufferType to enum class.
Bug: skia:1040643
Change-Id: Id36808267a86548a25ac6c92f9b753c11764742e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/265577
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
diff --git a/src/gpu/gl/GrGLBuffer.cpp b/src/gpu/gl/GrGLBuffer.cpp
index 516c10e..55ea540 100644
--- a/src/gpu/gl/GrGLBuffer.cpp
+++ b/src/gpu/gl/GrGLBuffer.cpp
@@ -8,6 +8,7 @@
#include "include/core/SkTraceMemoryDump.h"
#include "src/gpu/GrGpuResourcePriv.h"
#include "src/gpu/gl/GrGLBuffer.h"
+#include "src/gpu/gl/GrGLCaps.h"
#include "src/gpu/gl/GrGLGpu.h"
#define GL_CALL(X) GR_GL_CALL(this->glGpu()->glInterface(), X)
@@ -31,7 +32,7 @@
sk_sp<GrGLBuffer> GrGLBuffer::Make(GrGLGpu* gpu, size_t size, GrGpuBufferType intendedType,
GrAccessPattern accessPattern, const void* data) {
- if (gpu->glCaps().transferBufferType() == GrGLCaps::kNone_TransferBufferType &&
+ if (gpu->glCaps().transferBufferType() == GrGLCaps::TransferBufferType::kNone &&
(GrGpuBufferType::kXferCpuToGpu == intendedType ||
GrGpuBufferType::kXferGpuToCpu == intendedType)) {
return nullptr;
@@ -49,7 +50,8 @@
#define DYNAMIC_DRAW_PARAM GR_GL_STREAM_DRAW
inline static GrGLenum gr_to_gl_access_pattern(GrGpuBufferType bufferType,
- GrAccessPattern accessPattern) {
+ GrAccessPattern accessPattern,
+ const GrGLCaps& caps) {
auto drawUsage = [](GrAccessPattern pattern) {
switch (pattern) {
case kDynamic_GrAccessPattern:
@@ -60,7 +62,7 @@
case kStream_GrAccessPattern:
return GR_GL_STREAM_DRAW;
}
- SK_ABORT("Unexpected access pattern");
+ SkUNREACHABLE;
};
auto readUsage = [](GrAccessPattern pattern) {
@@ -72,10 +74,15 @@
case kStream_GrAccessPattern:
return GR_GL_STREAM_READ;
}
- SK_ABORT("Unexpected access pattern");
+ SkUNREACHABLE;
};
- auto usageType = [&drawUsage, &readUsage](GrGpuBufferType type, GrAccessPattern pattern) {
+ auto usageType = [&drawUsage, &readUsage, &caps](GrGpuBufferType type,
+ GrAccessPattern pattern) {
+ // GL_NV_pixel_buffer_object adds transfer buffers but not the related <usage> values.
+ if (caps.transferBufferType() == GrGLCaps::TransferBufferType::kNV_PBO) {
+ return drawUsage(pattern);
+ }
switch (type) {
case GrGpuBufferType::kVertex:
case GrGpuBufferType::kIndex:
@@ -84,7 +91,7 @@
case GrGpuBufferType::kXferGpuToCpu:
return readUsage(pattern);
}
- SK_ABORT("Unexpected gpu buffer type.");
+ SkUNREACHABLE;
};
return usageType(bufferType, accessPattern);
@@ -95,7 +102,7 @@
: INHERITED(gpu, size, intendedType, accessPattern)
, fIntendedType(intendedType)
, fBufferID(0)
- , fUsage(gr_to_gl_access_pattern(intendedType, accessPattern))
+ , fUsage(gr_to_gl_access_pattern(intendedType, accessPattern, gpu->glCaps()))
, fGLSizeInBytes(0)
, fHasAttachedToTexture(false) {
GL_CALL(GenBuffers(1, &fBufferID));
diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp
index f1c0506..f79ba83 100644
--- a/src/gpu/gl/GrGLCaps.cpp
+++ b/src/gpu/gl/GrGLCaps.cpp
@@ -5,6 +5,8 @@
* found in the LICENSE file.
*/
+#include "src/gpu/gl/GrGLCaps.h"
+
#include "include/gpu/GrContextOptions.h"
#include "src/core/SkTSearch.h"
#include "src/core/SkTSort.h"
@@ -14,7 +16,6 @@
#include "src/gpu/GrSurfaceProxyPriv.h"
#include "src/gpu/GrTextureProxyPriv.h"
#include "src/gpu/SkGr.h"
-#include "src/gpu/gl/GrGLCaps.h"
#include "src/gpu/gl/GrGLContext.h"
#include "src/gpu/gl/GrGLRenderTarget.h"
#include "src/gpu/gl/GrGLTexture.h"
@@ -29,7 +30,7 @@
fMSFBOType = kNone_MSFBOType;
fInvalidateFBType = kNone_InvalidateFBType;
fMapBufferType = kNone_MapBufferType;
- fTransferBufferType = kNone_TransferBufferType;
+ fTransferBufferType = TransferBufferType::kNone;
fMaxFragmentUniformVectors = 0;
fPackFlipYSupport = false;
fTextureUsageSupport = false;
@@ -495,7 +496,7 @@
ctxInfo.hasExtension("GL_EXT_pixel_buffer_object")) {
fTransferFromBufferToTextureSupport = true;
fTransferFromSurfaceToBufferSupport = true;
- fTransferBufferType = kPBO_TransferBufferType;
+ fTransferBufferType = TransferBufferType::kARB_PBO;
}
} else if (GR_IS_GR_GL_ES(standard)) {
if (version >= GR_GL_VER(3, 0) ||
@@ -504,12 +505,16 @@
ctxInfo.hasExtension("GL_EXT_unpack_subimage"))) {
fTransferFromBufferToTextureSupport = true;
fTransferFromSurfaceToBufferSupport = true;
- fTransferBufferType = kPBO_TransferBufferType;
+ if (version < GR_GL_VER(3, 0)) {
+ fTransferBufferType = TransferBufferType::kNV_PBO;
+ } else {
+ fTransferBufferType = TransferBufferType::kARB_PBO;
+ }
// TODO: get transfer buffers working in Chrome
// } else if (ctxInfo.hasExtension("GL_CHROMIUM_pixel_transfer_buffer_object")) {
// fTransferFromBufferToTextureSupport = false;
// fTransferFromSurfaceToBufferSupport = false;
-// fTransferBufferType = kChromium_TransferBufferType;
+// fTransferBufferType = TransferBufferType::kChromium;
}
} // no WebGL support
@@ -3339,7 +3344,7 @@
fMapBufferFlags = kNone_MapFlags;
fTransferFromBufferToTextureSupport = false;
fTransferFromSurfaceToBufferSupport = false;
- fTransferBufferType = kNone_TransferBufferType;
+ fTransferBufferType = TransferBufferType::kNone;
#endif
#endif
@@ -3353,7 +3358,7 @@
fMapBufferFlags = kNone_MapFlags;
fTransferFromBufferToTextureSupport = false;
fTransferFromSurfaceToBufferSupport = false;
- fTransferBufferType = kNone_TransferBufferType;
+ fTransferBufferType = TransferBufferType::kNone;
}
// The TransferPixelsToTexture test fails on ANGLE.
diff --git a/src/gpu/gl/GrGLCaps.h b/src/gpu/gl/GrGLCaps.h
index 766c2fe..82f46b0 100644
--- a/src/gpu/gl/GrGLCaps.h
+++ b/src/gpu/gl/GrGLCaps.h
@@ -93,12 +93,11 @@
kLast_MapBufferType = kChromium_MapBufferType,
};
- enum TransferBufferType {
- kNone_TransferBufferType,
- kPBO_TransferBufferType, // ARB_pixel_buffer_object
- kChromium_TransferBufferType, // CHROMIUM_pixel_transfer_buffer_object
-
- kLast_TransferBufferType = kChromium_TransferBufferType,
+ enum class TransferBufferType {
+ kNone,
+ kNV_PBO, // NV__pixel_buffer_object
+ kARB_PBO, // ARB_pixel_buffer_object
+ kChromium, // CHROMIUM_pixel_transfer_buffer_object
};
/**
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp
index d0348f99..f8ed35b 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -392,7 +392,7 @@
this->hwBufferState(GrGpuBufferType::kVertex)->fGLTarget = GR_GL_ARRAY_BUFFER;
this->hwBufferState(GrGpuBufferType::kIndex)->fGLTarget = GR_GL_ELEMENT_ARRAY_BUFFER;
- if (GrGLCaps::kChromium_TransferBufferType == this->glCaps().transferBufferType()) {
+ if (GrGLCaps::TransferBufferType::kChromium == this->glCaps().transferBufferType()) {
this->hwBufferState(GrGpuBufferType::kXferCpuToGpu)->fGLTarget =
GR_GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM;
this->hwBufferState(GrGpuBufferType::kXferGpuToCpu)->fGLTarget =