| 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, SkColorType dstCT
, | 54 static SkGrPixelRef* copy_to_new_texture_pixelref(GrTexture* texture, SkColorTyp
e dstCT, |
| 55 const SkIRect* subset) { | 55 const SkIRect* subset) { |
| 56 if (NULL == texture || kUnknown_SkColorType == dstCT) { | 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 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 79 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; | 79 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; |
| 80 desc.fConfig = SkImageInfo2GrPixelConfig(dstCT, kPremul_SkAlphaType); | 80 desc.fConfig = SkImageInfo2GrPixelConfig(dstCT, kPremul_SkAlphaType); |
| 81 | 81 |
| 82 GrTexture* dst = context->createUncachedTexture(desc, NULL, 0); | 82 GrTexture* dst = context->createUncachedTexture(desc, NULL, 0); |
| 83 if (NULL == dst) { | 83 if (NULL == dst) { |
| 84 return NULL; | 84 return NULL; |
| 85 } | 85 } |
| 86 | 86 |
| 87 context->copyTexture(texture, dst->asRenderTarget(), topLeft); | 87 context->copyTexture(texture, dst->asRenderTarget(), topLeft); |
| 88 | 88 |
| 89 // TODO: figure out if this is responsible for Chrome canvas errors | 89 // Blink is relying on the above copy being sent to GL immediately in the ca
se when the source |
| 90 #if 0 | 90 // is a WebGL canvas backing store. We could have a TODO to remove this flus
h, but we have a |
| 91 // The render texture we have created (to perform the copy) isn't fully | 91 // larger TODO to remove SkGrPixelRef entirely. |
| 92 // functional (since it doesn't have a stencil buffer). Release it here | 92 context->flush(); |
| 93 // so the caller doesn't try to render to it. | |
| 94 // TODO: we can undo this release when dynamic stencil buffer attach/ | |
| 95 // detach has been implemented | |
| 96 dst->releaseRenderTarget(); | |
| 97 #endif | |
| 98 | 93 |
| 99 SkImageInfo info = SkImageInfo::Make(desc.fWidth, desc.fHeight, dstCT, kPrem
ul_SkAlphaType); | 94 SkImageInfo info = SkImageInfo::Make(desc.fWidth, desc.fHeight, dstCT, kPrem
ul_SkAlphaType); |
| 100 SkGrPixelRef* pixelRef = SkNEW_ARGS(SkGrPixelRef, (info, dst)); | 95 SkGrPixelRef* pixelRef = SkNEW_ARGS(SkGrPixelRef, (info, dst)); |
| 101 SkSafeUnref(dst); | 96 SkSafeUnref(dst); |
| 102 return pixelRef; | 97 return pixelRef; |
| 103 } | 98 } |
| 104 | 99 |
| 105 /////////////////////////////////////////////////////////////////////////////// | 100 /////////////////////////////////////////////////////////////////////////////// |
| 106 | 101 |
| 107 SkGrPixelRef::SkGrPixelRef(const SkImageInfo& info, GrSurface* surface, | 102 SkGrPixelRef::SkGrPixelRef(const SkImageInfo& info, GrSurface* surface, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 if (NULL == fSurface) { | 144 if (NULL == fSurface) { |
| 150 return NULL; | 145 return NULL; |
| 151 } | 146 } |
| 152 | 147 |
| 153 // Note that when copying a render-target-backed pixel ref, we | 148 // Note that when copying a render-target-backed pixel ref, we |
| 154 // return a texture-backed pixel ref instead. This is because | 149 // return a texture-backed pixel ref instead. This is because |
| 155 // render-target pixel refs are usually created in conjunction with | 150 // render-target pixel refs are usually created in conjunction with |
| 156 // a GrTexture owned elsewhere (e.g., SkGpuDevice), and cannot live | 151 // a GrTexture owned elsewhere (e.g., SkGpuDevice), and cannot live |
| 157 // independently of that texture. Texture-backed pixel refs, on the other | 152 // independently of that texture. Texture-backed pixel refs, on the other |
| 158 // hand, own their GrTextures, and are thus self-contained. | 153 // hand, own their GrTextures, and are thus self-contained. |
| 159 return copyToTexturePixelRef(fSurface->asTexture(), dstCT, subset); | 154 return copy_to_new_texture_pixelref(fSurface->asTexture(), dstCT, subset); |
| 160 } | 155 } |
| 161 | 156 |
| 162 bool SkGrPixelRef::onReadPixels(SkBitmap* dst, const SkIRect* subset) { | 157 bool SkGrPixelRef::onReadPixels(SkBitmap* dst, const SkIRect* subset) { |
| 163 if (NULL == fSurface || fSurface->wasDestroyed()) { | 158 if (NULL == fSurface || fSurface->wasDestroyed()) { |
| 164 return false; | 159 return false; |
| 165 } | 160 } |
| 166 | 161 |
| 167 int left, top, width, height; | 162 int left, top, width, height; |
| 168 if (NULL != subset) { | 163 if (NULL != subset) { |
| 169 left = subset->fLeft; | 164 left = subset->fLeft; |
| 170 width = subset->width(); | 165 width = subset->width(); |
| 171 top = subset->fTop; | 166 top = subset->fTop; |
| 172 height = subset->height(); | 167 height = subset->height(); |
| 173 } else { | 168 } else { |
| 174 left = 0; | 169 left = 0; |
| 175 width = this->info().fWidth; | 170 width = this->info().fWidth; |
| 176 top = 0; | 171 top = 0; |
| 177 height = this->info().fHeight; | 172 height = this->info().fHeight; |
| 178 } | 173 } |
| 179 if (!dst->allocPixels(SkImageInfo::MakeN32Premul(width, height))) { | 174 if (!dst->allocPixels(SkImageInfo::MakeN32Premul(width, height))) { |
| 180 SkDebugf("SkGrPixelRef::onReadPixels failed to alloc bitmap for result!\
n"); | 175 SkDebugf("SkGrPixelRef::onReadPixels failed to alloc bitmap for result!\
n"); |
| 181 return false; | 176 return false; |
| 182 } | 177 } |
| 183 SkAutoLockPixels al(*dst); | 178 SkAutoLockPixels al(*dst); |
| 184 void* buffer = dst->getPixels(); | 179 void* buffer = dst->getPixels(); |
| 185 return fSurface->readPixels(left, top, width, height, | 180 return fSurface->readPixels(left, top, width, height, |
| 186 kSkia8888_GrPixelConfig, | 181 kSkia8888_GrPixelConfig, |
| 187 buffer, dst->rowBytes()); | 182 buffer, dst->rowBytes()); |
| 188 } | 183 } |
| OLD | NEW |