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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « src/gpu/GrContext.cpp ('k') | src/gpu/GrSurfacePriv.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "GrSurface.h" 8 #include "GrSurface.h"
9 #include "GrSurfacePriv.h" 9 #include "GrSurfacePriv.h"
10 10
11 #include "SkBitmap.h" 11 #include "SkBitmap.h"
12 #include "SkGr.h" 12 #include "SkGr.h"
13 #include "SkImageEncoder.h" 13 #include "SkImageEncoder.h"
14 #include <stdio.h> 14 #include <stdio.h>
15 15
16 template<typename T> static bool adjust_params(int surfaceWidth,
17 int surfaceHeight,
18 size_t bpp,
19 int* left, int* top, int* width, int* height,
20 T** data,
21 size_t* rowBytes) {
22 if (!*rowBytes) {
23 *rowBytes = *width * bpp;
24 }
25
26 SkIRect subRect = SkIRect::MakeXYWH(*left, *top, *width, *height);
27 SkIRect bounds = SkIRect::MakeWH(surfaceWidth, surfaceHeight);
28
29 if (!subRect.intersect(bounds)) {
30 return false;
31 }
32 *data = reinterpret_cast<void*>(reinterpret_cast<intptr_t>(*data) +
33 (subRect.fTop - *top) * *rowBytes + (subRect.fLeft - *left) * bpp);
34
35 *left = subRect.fLeft;
36 *top = subRect.fTop;
37 *width = subRect.width();
38 *height = subRect.height();
39 return true;
40 }
41
42 bool GrSurfacePriv::AdjustReadPixelParams(int surfaceWidth,
43 int surfaceHeight,
44 size_t bpp,
45 int* left, int* top, int* width, int* height,
46 void** data,
47 size_t* rowBytes) {
48 return adjust_params<void>(surfaceWidth, surfaceHeight, bpp, left, top, widt h, height, data,
49 rowBytes);
50 }
51
52 bool GrSurfacePriv::AdjustWritePixelParams(int surfaceWidth,
53 int surfaceHeight,
54 size_t bpp,
55 int* left, int* top, int* width, int* height,
56 const void** data,
57 size_t* rowBytes) {
58 return adjust_params<const void>(surfaceWidth, surfaceHeight, bpp, left, top , width, height,
59 data, rowBytes);
60 }
61
62
63 //////////////////////////////////////////////////////////////////////////////
64
16 bool GrSurface::writePixels(int left, int top, int width, int height, 65 bool GrSurface::writePixels(int left, int top, int width, int height,
17 GrPixelConfig config, const void* buffer, size_t row Bytes, 66 GrPixelConfig config, const void* buffer, size_t row Bytes,
18 uint32_t pixelOpsFlags) { 67 uint32_t pixelOpsFlags) {
19 // go through context so that all necessary flushing occurs 68 // go through context so that all necessary flushing occurs
20 GrContext* context = this->getContext(); 69 GrContext* context = this->getContext();
21 if (NULL == context) { 70 if (NULL == context) {
22 return false; 71 return false;
23 } 72 }
24 return context->writeSurfacePixels(this, left, top, width, height, config, b uffer, rowBytes, 73 return context->writeSurfacePixels(this, left, top, width, height, config, b uffer, rowBytes,
25 pixelOpsFlags); 74 pixelOpsFlags);
26 } 75 }
27 76
28 bool GrSurface::readPixels(int left, int top, int width, int height, 77 bool GrSurface::readPixels(int left, int top, int width, int height,
29 GrPixelConfig config, void* buffer, size_t rowBytes, 78 GrPixelConfig config, void* buffer, size_t rowBytes,
30 uint32_t pixelOpsFlags) { 79 uint32_t pixelOpsFlags) {
31 // go through context so that all necessary flushing occurs 80 // go through context so that all necessary flushing occurs
32 GrContext* context = this->getContext(); 81 GrContext* context = this->getContext();
33 if (NULL == context) { 82 if (NULL == context) {
34 return false; 83 return false;
35 } 84 }
36 GrRenderTarget* target = this->asRenderTarget(); 85 return context->readSurfacePixels(this, left, top, width, height, config, bu ffer,
37 if (target) { 86 rowBytes, pixelOpsFlags);
38 return context->readRenderTargetPixels(target, left, top, width, height, config, buffer,
39 rowBytes, pixelOpsFlags);
40 }
41 return false;
42 } 87 }
43 88
44 SkImageInfo GrSurface::info(SkAlphaType alphaType) const { 89 SkImageInfo GrSurface::info(SkAlphaType alphaType) const {
45 SkColorType colorType; 90 SkColorType colorType;
46 SkColorProfileType profileType; 91 SkColorProfileType profileType;
47 if (!GrPixelConfig2ColorAndProfileType(this->config(), &colorType, &profileT ype)) { 92 if (!GrPixelConfig2ColorAndProfileType(this->config(), &colorType, &profileT ype)) {
48 sk_throw(); 93 sk_throw();
49 } 94 }
50 return SkImageInfo::Make(this->width(), this->height(), colorType, alphaType , 95 return SkImageInfo::Make(this->width(), this->height(), colorType, alphaType ,
51 profileType); 96 profileType);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 173
129 void GrSurface::onRelease() { 174 void GrSurface::onRelease() {
130 this->invokeReleaseProc(); 175 this->invokeReleaseProc();
131 this->INHERITED::onRelease(); 176 this->INHERITED::onRelease();
132 } 177 }
133 178
134 void GrSurface::onAbandon() { 179 void GrSurface::onAbandon() {
135 this->invokeReleaseProc(); 180 this->invokeReleaseProc();
136 this->INHERITED::onAbandon(); 181 this->INHERITED::onAbandon();
137 } 182 }
OLDNEW
« 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