| OLD | NEW |
| 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 Loading... |
| 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, const SkIRect* su
bset) { | 54 static SkGrPixelRef* copyToTexturePixelRef(GrTexture* texture, SkBitmap::Config
dstConfig, |
| 55 const SkIRect* subset) { |
| 55 if (NULL == texture) { | 56 if (NULL == texture) { |
| 56 return NULL; | 57 return NULL; |
| 57 } | 58 } |
| 58 GrContext* context = texture->getContext(); | 59 GrContext* context = texture->getContext(); |
| 59 if (NULL == context) { | 60 if (NULL == context) { |
| 60 return NULL; | 61 return NULL; |
| 61 } | 62 } |
| 62 GrTextureDesc desc; | 63 GrTextureDesc desc; |
| 63 | 64 |
| 64 SkIPoint pointStorage; | 65 SkIPoint pointStorage; |
| 65 SkIPoint* topLeft; | 66 SkIPoint* topLeft; |
| 66 if (subset != NULL) { | 67 if (subset != NULL) { |
| 67 SkASSERT(SkIRect::MakeWH(texture->width(), texture->height()).contains(*
subset)); | 68 SkASSERT(SkIRect::MakeWH(texture->width(), texture->height()).contains(*
subset)); |
| 68 // Create a new texture that is the size of subset. | 69 // Create a new texture that is the size of subset. |
| 69 desc.fWidth = subset->width(); | 70 desc.fWidth = subset->width(); |
| 70 desc.fHeight = subset->height(); | 71 desc.fHeight = subset->height(); |
| 71 pointStorage.set(subset->x(), subset->y()); | 72 pointStorage.set(subset->x(), subset->y()); |
| 72 topLeft = &pointStorage; | 73 topLeft = &pointStorage; |
| 73 } else { | 74 } else { |
| 74 desc.fWidth = texture->width(); | 75 desc.fWidth = texture->width(); |
| 75 desc.fHeight = texture->height(); | 76 desc.fHeight = texture->height(); |
| 76 topLeft = NULL; | 77 topLeft = NULL; |
| 77 } | 78 } |
| 78 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; | 79 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; |
| 79 desc.fConfig = texture->config(); | 80 desc.fConfig = SkBitmapConfig2GrPixelConfig(dstConfig); |
| 80 | 81 |
| 81 SkImageInfo info; | 82 SkImageInfo info; |
| 82 if (!GrPixelConfig2ColorType(desc.fConfig, &info.fColorType)) { | 83 if (!GrPixelConfig2ColorType(desc.fConfig, &info.fColorType)) { |
| 83 return NULL; | 84 return NULL; |
| 84 } | 85 } |
| 85 info.fWidth = desc.fWidth; | 86 info.fWidth = desc.fWidth; |
| 86 info.fHeight = desc.fHeight; | 87 info.fHeight = desc.fHeight; |
| 87 info.fAlphaType = kPremul_SkAlphaType; | 88 info.fAlphaType = kPremul_SkAlphaType; |
| 88 | 89 |
| 89 GrTexture* dst = context->createUncachedTexture(desc, NULL, 0); | 90 GrTexture* dst = context->createUncachedTexture(desc, NULL, 0); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 SkSafeUnref(fSurface); | 145 SkSafeUnref(fSurface); |
| 145 } | 146 } |
| 146 | 147 |
| 147 GrTexture* SkGrPixelRef::getTexture() { | 148 GrTexture* SkGrPixelRef::getTexture() { |
| 148 if (NULL != fSurface) { | 149 if (NULL != fSurface) { |
| 149 return fSurface->asTexture(); | 150 return fSurface->asTexture(); |
| 150 } | 151 } |
| 151 return NULL; | 152 return NULL; |
| 152 } | 153 } |
| 153 | 154 |
| 154 SkPixelRef* SkGrPixelRef::deepCopy(const SkIRect* subset) { | 155 SkPixelRef* SkGrPixelRef::deepCopy(SkBitmap::Config dstConfig, const SkIRect* su
bset) { |
| 155 if (NULL == fSurface) { | 156 if (NULL == fSurface) { |
| 156 return NULL; | 157 return NULL; |
| 157 } | 158 } |
| 158 | 159 |
| 159 // Note that when copying a render-target-backed pixel ref, we | 160 // Note that when copying a render-target-backed pixel ref, we |
| 160 // return a texture-backed pixel ref instead. This is because | 161 // return a texture-backed pixel ref instead. This is because |
| 161 // render-target pixel refs are usually created in conjunction with | 162 // render-target pixel refs are usually created in conjunction with |
| 162 // a GrTexture owned elsewhere (e.g., SkGpuDevice), and cannot live | 163 // a GrTexture owned elsewhere (e.g., SkGpuDevice), and cannot live |
| 163 // independently of that texture. Texture-backed pixel refs, on the other | 164 // independently of that texture. Texture-backed pixel refs, on the other |
| 164 // hand, own their GrTextures, and are thus self-contained. | 165 // hand, own their GrTextures, and are thus self-contained. |
| 165 return copyToTexturePixelRef(fSurface->asTexture(), subset); | 166 return copyToTexturePixelRef(fSurface->asTexture(), dstConfig, subset); |
| 166 } | 167 } |
| 167 | 168 |
| 168 bool SkGrPixelRef::onReadPixels(SkBitmap* dst, const SkIRect* subset) { | 169 bool SkGrPixelRef::onReadPixels(SkBitmap* dst, const SkIRect* subset) { |
| 169 if (NULL == fSurface || !fSurface->isValid()) { | 170 if (NULL == fSurface || !fSurface->isValid()) { |
| 170 return false; | 171 return false; |
| 171 } | 172 } |
| 172 | 173 |
| 173 int left, top, width, height; | 174 int left, top, width, height; |
| 174 if (NULL != subset) { | 175 if (NULL != subset) { |
| 175 left = subset->fLeft; | 176 left = subset->fLeft; |
| 176 width = subset->width(); | 177 width = subset->width(); |
| 177 top = subset->fTop; | 178 top = subset->fTop; |
| 178 height = subset->height(); | 179 height = subset->height(); |
| 179 } else { | 180 } else { |
| 180 left = 0; | 181 left = 0; |
| 181 width = this->info().fWidth; | 182 width = this->info().fWidth; |
| 182 top = 0; | 183 top = 0; |
| 183 height = this->info().fHeight; | 184 height = this->info().fHeight; |
| 184 } | 185 } |
| 185 if (!dst->allocPixels(SkImageInfo::MakeN32Premul(width, height))) { | 186 if (!dst->allocPixels(SkImageInfo::MakeN32Premul(width, height))) { |
| 186 SkDebugf("SkGrPixelRef::onReadPixels failed to alloc bitmap for result!\
n"); | 187 SkDebugf("SkGrPixelRef::onReadPixels failed to alloc bitmap for result!\
n"); |
| 187 return false; | 188 return false; |
| 188 } | 189 } |
| 189 SkAutoLockPixels al(*dst); | 190 SkAutoLockPixels al(*dst); |
| 190 void* buffer = dst->getPixels(); | 191 void* buffer = dst->getPixels(); |
| 191 return fSurface->readPixels(left, top, width, height, | 192 return fSurface->readPixels(left, top, width, height, |
| 192 kSkia8888_GrPixelConfig, | 193 kSkia8888_GrPixelConfig, |
| 193 buffer, dst->rowBytes()); | 194 buffer, dst->rowBytes()); |
| 194 } | 195 } |
| OLD | NEW |