aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrDrawOpAtlas.cpp
diff options
context:
space:
mode:
authorGravatar Jim Van Verth <jvanverth@google.com>2018-02-20 15:38:08 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-02-20 21:06:13 +0000
commita8c55fa4fec87bf6fd601b16c2684168abddbab8 (patch)
tree223cc07a2cedff34a5f1dfa7c791f707b3e85660 /src/gpu/GrDrawOpAtlas.cpp
parent2d18f41858382fff91688a6318bc39cb22233f7e (diff)
Pad atlas uploads to 4-byte boundaries
Change-Id: I678358c176e318d89892ced5c76cd2662774a7d6 Reviewed-on: https://skia-review.googlesource.com/108566 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Jim Van Verth <jvanverth@google.com>
Diffstat (limited to 'src/gpu/GrDrawOpAtlas.cpp')
-rw-r--r--src/gpu/GrDrawOpAtlas.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/gpu/GrDrawOpAtlas.cpp b/src/gpu/GrDrawOpAtlas.cpp
index 9bf2315bf1..622aa229bd 100644
--- a/src/gpu/GrDrawOpAtlas.cpp
+++ b/src/gpu/GrDrawOpAtlas.cpp
@@ -76,6 +76,10 @@ GrDrawOpAtlas::Plot::Plot(int pageIndex, int plotIndex, uint64_t genID, int offX
, fDirty(false)
#endif
{
+ // We expect the allocated dimensions to be a multiple of 4 bytes
+ SkASSERT(((width*fBytesPerPixel) & 0x3) == 0);
+ // The padding for faster uploads only works for 1, 2 and 4 byte texels
+ SkASSERT(fBytesPerPixel != 3 && fBytesPerPixel <= 4);
fDirtyRect.setEmpty();
}
@@ -136,6 +140,13 @@ void GrDrawOpAtlas::Plot::uploadToTexture(GrDeferredTextureUploadWritePixelsFn&
TRACE_EVENT0("skia.gpu", TRACE_FUNC);
size_t rowBytes = fBytesPerPixel * fWidth;
const unsigned char* dataPtr = fData;
+ // Clamp to 4-byte aligned boundaries
+ unsigned int clearBits = 0x3 / fBytesPerPixel;
+ fDirtyRect.fLeft &= ~clearBits;
+ fDirtyRect.fRight += clearBits;
+ fDirtyRect.fRight &= ~clearBits;
+ SkASSERT(fDirtyRect.fRight <= fWidth);
+ // Set up dataPtr
dataPtr += rowBytes * fDirtyRect.fTop;
dataPtr += fBytesPerPixel * fDirtyRect.fLeft;
// TODO: Make GrDrawOpAtlas store a GrColorType rather than GrPixelConfig.