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/SkGrPixelRef.cpp

Issue 323283002: switch to colortype for deepcopy (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 6 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
« include/core/SkPixelRef.h ('K') | « src/core/SkBitmap.cpp ('k') | no next file » | 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 /* 2 /*
3 * Copyright 2010 Google Inc. 3 * Copyright 2010 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 10
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 void SkROLockPixelsPixelRef::onUnlockPixels() { 44 void SkROLockPixelsPixelRef::onUnlockPixels() {
45 fBitmap.unlockPixels(); 45 fBitmap.unlockPixels();
46 } 46 }
47 47
48 bool SkROLockPixelsPixelRef::onLockPixelsAreWritable() const { 48 bool SkROLockPixelsPixelRef::onLockPixelsAreWritable() const {
49 return false; 49 return false;
50 } 50 }
51 51
52 /////////////////////////////////////////////////////////////////////////////// 52 ///////////////////////////////////////////////////////////////////////////////
53 53
54 static SkGrPixelRef* copyToTexturePixelRef(GrTexture* texture, SkBitmap::Config dstConfig, 54 static SkGrPixelRef* copyToTexturePixelRef(GrTexture* texture, SkColorType dstCT ,
55 const SkIRect* subset) { 55 const SkIRect* subset) {
56 if (NULL == texture) { 56 if (NULL == texture || kUnknown_SkColorType == dstCT) {
57 return NULL; 57 return NULL;
58 } 58 }
59 GrContext* context = texture->getContext(); 59 GrContext* context = texture->getContext();
60 if (NULL == context) { 60 if (NULL == context) {
61 return NULL; 61 return NULL;
62 } 62 }
63 GrTextureDesc desc; 63 GrTextureDesc desc;
64 64
65 SkIPoint pointStorage; 65 SkIPoint pointStorage;
66 SkIPoint* topLeft; 66 SkIPoint* topLeft;
67 if (subset != NULL) { 67 if (subset != NULL) {
68 SkASSERT(SkIRect::MakeWH(texture->width(), texture->height()).contains(* subset)); 68 SkASSERT(SkIRect::MakeWH(texture->width(), texture->height()).contains(* subset));
69 // Create a new texture that is the size of subset. 69 // Create a new texture that is the size of subset.
70 desc.fWidth = subset->width(); 70 desc.fWidth = subset->width();
71 desc.fHeight = subset->height(); 71 desc.fHeight = subset->height();
72 pointStorage.set(subset->x(), subset->y()); 72 pointStorage.set(subset->x(), subset->y());
73 topLeft = &pointStorage; 73 topLeft = &pointStorage;
74 } else { 74 } else {
75 desc.fWidth = texture->width(); 75 desc.fWidth = texture->width();
76 desc.fHeight = texture->height(); 76 desc.fHeight = texture->height();
77 topLeft = NULL; 77 topLeft = NULL;
78 } 78 }
79 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; 79 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit;
80 desc.fConfig = SkBitmapConfig2GrPixelConfig(dstConfig); 80 desc.fConfig = SkImageInfo2GrPixelConfig(dstCT, kPremul_SkAlphaType);
81
82 SkImageInfo info;
83 if (!GrPixelConfig2ColorType(desc.fConfig, &info.fColorType)) {
84 return NULL;
85 }
86 info.fWidth = desc.fWidth;
87 info.fHeight = desc.fHeight;
88 info.fAlphaType = kPremul_SkAlphaType;
89 81
90 GrTexture* dst = context->createUncachedTexture(desc, NULL, 0); 82 GrTexture* dst = context->createUncachedTexture(desc, NULL, 0);
91 if (NULL == dst) { 83 if (NULL == dst) {
92 return NULL; 84 return NULL;
93 } 85 }
94 86
95 context->copyTexture(texture, dst->asRenderTarget(), topLeft); 87 context->copyTexture(texture, dst->asRenderTarget(), topLeft);
96 88
97 // TODO: figure out if this is responsible for Chrome canvas errors 89 // TODO: figure out if this is responsible for Chrome canvas errors
98 #if 0 90 #if 0
99 // The render texture we have created (to perform the copy) isn't fully 91 // The render texture we have created (to perform the copy) isn't fully
100 // functional (since it doesn't have a stencil buffer). Release it here 92 // functional (since it doesn't have a stencil buffer). Release it here
101 // so the caller doesn't try to render to it. 93 // so the caller doesn't try to render to it.
102 // TODO: we can undo this release when dynamic stencil buffer attach/ 94 // TODO: we can undo this release when dynamic stencil buffer attach/
103 // detach has been implemented 95 // detach has been implemented
104 dst->releaseRenderTarget(); 96 dst->releaseRenderTarget();
105 #endif 97 #endif
106 98
99 SkImageInfo info = SkImageInfo::Make(desc.fWidth, desc.fHeight, dstCT, kPrem ul_SkAlphaType);
107 SkGrPixelRef* pixelRef = SkNEW_ARGS(SkGrPixelRef, (info, dst)); 100 SkGrPixelRef* pixelRef = SkNEW_ARGS(SkGrPixelRef, (info, dst));
108 SkSafeUnref(dst); 101 SkSafeUnref(dst);
109 return pixelRef; 102 return pixelRef;
110 } 103 }
111 104
112 /////////////////////////////////////////////////////////////////////////////// 105 ///////////////////////////////////////////////////////////////////////////////
113 106
114 SkGrPixelRef::SkGrPixelRef(const SkImageInfo& info, GrSurface* surface, 107 SkGrPixelRef::SkGrPixelRef(const SkImageInfo& info, GrSurface* surface,
115 bool transferCacheLock) : INHERITED(info) { 108 bool transferCacheLock) : INHERITED(info) {
116 // TODO: figure out if this is responsible for Chrome canvas errors 109 // TODO: figure out if this is responsible for Chrome canvas errors
(...skipping 28 matching lines...) Expand all
145 SkSafeUnref(fSurface); 138 SkSafeUnref(fSurface);
146 } 139 }
147 140
148 GrTexture* SkGrPixelRef::getTexture() { 141 GrTexture* SkGrPixelRef::getTexture() {
149 if (NULL != fSurface) { 142 if (NULL != fSurface) {
150 return fSurface->asTexture(); 143 return fSurface->asTexture();
151 } 144 }
152 return NULL; 145 return NULL;
153 } 146 }
154 147
155 SkPixelRef* SkGrPixelRef::deepCopy(SkBitmap::Config dstConfig, const SkIRect* su bset) { 148 SkPixelRef* SkGrPixelRef::deepCopy(SkColorType dstCT, const SkIRect* subset) {
156 if (NULL == fSurface) { 149 if (NULL == fSurface) {
157 return NULL; 150 return NULL;
158 } 151 }
159 152
160 // Note that when copying a render-target-backed pixel ref, we 153 // Note that when copying a render-target-backed pixel ref, we
161 // return a texture-backed pixel ref instead. This is because 154 // return a texture-backed pixel ref instead. This is because
162 // render-target pixel refs are usually created in conjunction with 155 // render-target pixel refs are usually created in conjunction with
163 // a GrTexture owned elsewhere (e.g., SkGpuDevice), and cannot live 156 // a GrTexture owned elsewhere (e.g., SkGpuDevice), and cannot live
164 // independently of that texture. Texture-backed pixel refs, on the other 157 // independently of that texture. Texture-backed pixel refs, on the other
165 // hand, own their GrTextures, and are thus self-contained. 158 // hand, own their GrTextures, and are thus self-contained.
166 return copyToTexturePixelRef(fSurface->asTexture(), dstConfig, subset); 159 return copyToTexturePixelRef(fSurface->asTexture(), dstCT, subset);
167 } 160 }
168 161
169 bool SkGrPixelRef::onReadPixels(SkBitmap* dst, const SkIRect* subset) { 162 bool SkGrPixelRef::onReadPixels(SkBitmap* dst, const SkIRect* subset) {
170 if (NULL == fSurface || fSurface->wasDestroyed()) { 163 if (NULL == fSurface || fSurface->wasDestroyed()) {
171 return false; 164 return false;
172 } 165 }
173 166
174 int left, top, width, height; 167 int left, top, width, height;
175 if (NULL != subset) { 168 if (NULL != subset) {
176 left = subset->fLeft; 169 left = subset->fLeft;
177 width = subset->width(); 170 width = subset->width();
178 top = subset->fTop; 171 top = subset->fTop;
179 height = subset->height(); 172 height = subset->height();
180 } else { 173 } else {
181 left = 0; 174 left = 0;
182 width = this->info().fWidth; 175 width = this->info().fWidth;
183 top = 0; 176 top = 0;
184 height = this->info().fHeight; 177 height = this->info().fHeight;
185 } 178 }
186 if (!dst->allocPixels(SkImageInfo::MakeN32Premul(width, height))) { 179 if (!dst->allocPixels(SkImageInfo::MakeN32Premul(width, height))) {
187 SkDebugf("SkGrPixelRef::onReadPixels failed to alloc bitmap for result!\ n"); 180 SkDebugf("SkGrPixelRef::onReadPixels failed to alloc bitmap for result!\ n");
188 return false; 181 return false;
189 } 182 }
190 SkAutoLockPixels al(*dst); 183 SkAutoLockPixels al(*dst);
191 void* buffer = dst->getPixels(); 184 void* buffer = dst->getPixels();
192 return fSurface->readPixels(left, top, width, height, 185 return fSurface->readPixels(left, top, width, height,
193 kSkia8888_GrPixelConfig, 186 kSkia8888_GrPixelConfig,
194 buffer, dst->rowBytes()); 187 buffer, dst->rowBytes());
195 } 188 }
OLDNEW
« include/core/SkPixelRef.h ('K') | « src/core/SkBitmap.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698