Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(257)

Unified Diff: src/gpu/GrSurface.cpp

Issue 1234313002: Make readpixels work on GrTextures (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix and more kRT removal Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/GrContext.cpp ('k') | src/gpu/GrSurfacePriv.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrSurface.cpp
diff --git a/src/gpu/GrSurface.cpp b/src/gpu/GrSurface.cpp
index 9685c5627567589acf91685f706b2cb73b0efd3f..9bd9e8b5ef51b24290d80969e19dba961382d8da 100644
--- a/src/gpu/GrSurface.cpp
+++ b/src/gpu/GrSurface.cpp
@@ -13,6 +13,55 @@
#include "SkImageEncoder.h"
#include <stdio.h>
+template<typename T> static bool adjust_params(int surfaceWidth,
+ int surfaceHeight,
+ size_t bpp,
+ int* left, int* top, int* width, int* height,
+ T** data,
+ size_t* rowBytes) {
+ if (!*rowBytes) {
+ *rowBytes = *width * bpp;
+ }
+
+ SkIRect subRect = SkIRect::MakeXYWH(*left, *top, *width, *height);
+ SkIRect bounds = SkIRect::MakeWH(surfaceWidth, surfaceHeight);
+
+ if (!subRect.intersect(bounds)) {
+ return false;
+ }
+ *data = reinterpret_cast<void*>(reinterpret_cast<intptr_t>(*data) +
+ (subRect.fTop - *top) * *rowBytes + (subRect.fLeft - *left) * bpp);
+
+ *left = subRect.fLeft;
+ *top = subRect.fTop;
+ *width = subRect.width();
+ *height = subRect.height();
+ return true;
+}
+
+bool GrSurfacePriv::AdjustReadPixelParams(int surfaceWidth,
+ int surfaceHeight,
+ size_t bpp,
+ int* left, int* top, int* width, int* height,
+ void** data,
+ size_t* rowBytes) {
+ return adjust_params<void>(surfaceWidth, surfaceHeight, bpp, left, top, width, height, data,
+ rowBytes);
+}
+
+bool GrSurfacePriv::AdjustWritePixelParams(int surfaceWidth,
+ int surfaceHeight,
+ size_t bpp,
+ int* left, int* top, int* width, int* height,
+ const void** data,
+ size_t* rowBytes) {
+ return adjust_params<const void>(surfaceWidth, surfaceHeight, bpp, left, top, width, height,
+ data, rowBytes);
+}
+
+
+//////////////////////////////////////////////////////////////////////////////
+
bool GrSurface::writePixels(int left, int top, int width, int height,
GrPixelConfig config, const void* buffer, size_t rowBytes,
uint32_t pixelOpsFlags) {
@@ -33,12 +82,8 @@ bool GrSurface::readPixels(int left, int top, int width, int height,
if (NULL == context) {
return false;
}
- GrRenderTarget* target = this->asRenderTarget();
- if (target) {
- return context->readRenderTargetPixels(target, left, top, width, height, config, buffer,
- rowBytes, pixelOpsFlags);
- }
- return false;
+ return context->readSurfacePixels(this, left, top, width, height, config, buffer,
+ rowBytes, pixelOpsFlags);
}
SkImageInfo GrSurface::info(SkAlphaType alphaType) const {
« no previous file with comments | « src/gpu/GrContext.cpp ('k') | src/gpu/GrSurfacePriv.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698