| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 fBitmap.unlockPixels(); | 47 fBitmap.unlockPixels(); |
| 48 } | 48 } |
| 49 | 49 |
| 50 bool SkROLockPixelsPixelRef::onLockPixelsAreWritable() const { | 50 bool SkROLockPixelsPixelRef::onLockPixelsAreWritable() const { |
| 51 return false; | 51 return false; |
| 52 } | 52 } |
| 53 | 53 |
| 54 /////////////////////////////////////////////////////////////////////////////// | 54 /////////////////////////////////////////////////////////////////////////////// |
| 55 | 55 |
| 56 static SkGrPixelRef* copy_to_new_texture_pixelref(GrTexture* texture, SkColorTyp
e dstCT, | 56 static SkGrPixelRef* copy_to_new_texture_pixelref(GrTexture* texture, SkColorTyp
e dstCT, |
| 57 const SkIRect* subset) { | 57 SkColorProfileType dstPT, cons
t SkIRect* subset) { |
| 58 if (NULL == texture || kUnknown_SkColorType == dstCT) { | 58 if (NULL == texture || kUnknown_SkColorType == dstCT) { |
| 59 return NULL; | 59 return NULL; |
| 60 } | 60 } |
| 61 GrContext* context = texture->getContext(); | 61 GrContext* context = texture->getContext(); |
| 62 if (NULL == context) { | 62 if (NULL == context) { |
| 63 return NULL; | 63 return NULL; |
| 64 } | 64 } |
| 65 GrSurfaceDesc desc; | 65 GrSurfaceDesc desc; |
| 66 | 66 |
| 67 SkIRect srcRect; | 67 SkIRect srcRect; |
| 68 | 68 |
| 69 if (!subset) { | 69 if (!subset) { |
| 70 desc.fWidth = texture->width(); | 70 desc.fWidth = texture->width(); |
| 71 desc.fHeight = texture->height(); | 71 desc.fHeight = texture->height(); |
| 72 srcRect = SkIRect::MakeWH(texture->width(), texture->height()); | 72 srcRect = SkIRect::MakeWH(texture->width(), texture->height()); |
| 73 } else { | 73 } else { |
| 74 SkASSERT(SkIRect::MakeWH(texture->width(), texture->height()).contains(*
subset)); | 74 SkASSERT(SkIRect::MakeWH(texture->width(), texture->height()).contains(*
subset)); |
| 75 // Create a new texture that is the size of subset. | 75 // Create a new texture that is the size of subset. |
| 76 desc.fWidth = subset->width(); | 76 desc.fWidth = subset->width(); |
| 77 desc.fHeight = subset->height(); | 77 desc.fHeight = subset->height(); |
| 78 srcRect = *subset; | 78 srcRect = *subset; |
| 79 } | 79 } |
| 80 desc.fFlags = kRenderTarget_GrSurfaceFlag | kNoStencil_GrSurfaceFlag; | 80 desc.fFlags = kRenderTarget_GrSurfaceFlag | kNoStencil_GrSurfaceFlag; |
| 81 desc.fConfig = SkImageInfo2GrPixelConfig(dstCT, kPremul_SkAlphaType); | 81 desc.fConfig = SkImageInfo2GrPixelConfig(dstCT, kPremul_SkAlphaType, dstPT); |
| 82 | 82 |
| 83 GrTexture* dst = context->createUncachedTexture(desc, NULL, 0); | 83 GrTexture* dst = context->createUncachedTexture(desc, NULL, 0); |
| 84 if (NULL == dst) { | 84 if (NULL == dst) { |
| 85 return NULL; | 85 return NULL; |
| 86 } | 86 } |
| 87 | 87 |
| 88 // Blink is relying on the above copy being sent to GL immediately in the ca
se when the source | 88 // Blink is relying on the above copy being sent to GL immediately in the ca
se when the source |
| 89 // is a WebGL canvas backing store. We could have a TODO to remove this flus
h flag, but we have | 89 // is a WebGL canvas backing store. We could have a TODO to remove this flus
h flag, but we have |
| 90 // a larger TODO to remove SkGrPixelRef entirely. | 90 // a larger TODO to remove SkGrPixelRef entirely. |
| 91 context->copySurface(dst->asRenderTarget(), texture, srcRect, SkIPoint::Make
(0,0), | 91 context->copySurface(dst->asRenderTarget(), texture, srcRect, SkIPoint::Make
(0,0), |
| 92 GrContext::kFlushWrites_PixelOp); | 92 GrContext::kFlushWrites_PixelOp); |
| 93 | 93 |
| 94 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, |
| 95 dstPT); |
| 95 SkGrPixelRef* pixelRef = SkNEW_ARGS(SkGrPixelRef, (info, dst)); | 96 SkGrPixelRef* pixelRef = SkNEW_ARGS(SkGrPixelRef, (info, dst)); |
| 96 SkSafeUnref(dst); | 97 SkSafeUnref(dst); |
| 97 return pixelRef; | 98 return pixelRef; |
| 98 } | 99 } |
| 99 | 100 |
| 100 /////////////////////////////////////////////////////////////////////////////// | 101 /////////////////////////////////////////////////////////////////////////////// |
| 101 | 102 |
| 102 SkGrPixelRef::SkGrPixelRef(const SkImageInfo& info, GrSurface* surface) : INHERI
TED(info) { | 103 SkGrPixelRef::SkGrPixelRef(const SkImageInfo& info, GrSurface* surface) : INHERI
TED(info) { |
| 103 // For surfaces that are both textures and render targets, the texture owns
the | 104 // For surfaces that are both textures and render targets, the texture owns
the |
| 104 // render target but not vice versa. So we ref the texture to keep both aliv
e for | 105 // render target but not vice versa. So we ref the texture to keep both aliv
e for |
| (...skipping 13 matching lines...) Expand all Loading... |
| 118 SkSafeUnref(fSurface); | 119 SkSafeUnref(fSurface); |
| 119 } | 120 } |
| 120 | 121 |
| 121 GrTexture* SkGrPixelRef::getTexture() { | 122 GrTexture* SkGrPixelRef::getTexture() { |
| 122 if (fSurface) { | 123 if (fSurface) { |
| 123 return fSurface->asTexture(); | 124 return fSurface->asTexture(); |
| 124 } | 125 } |
| 125 return NULL; | 126 return NULL; |
| 126 } | 127 } |
| 127 | 128 |
| 128 SkPixelRef* SkGrPixelRef::deepCopy(SkColorType dstCT, const SkIRect* subset) { | 129 SkPixelRef* SkGrPixelRef::deepCopy(SkColorType dstCT, SkColorProfileType dstPT, |
| 130 const SkIRect* subset) { |
| 129 if (NULL == fSurface) { | 131 if (NULL == fSurface) { |
| 130 return NULL; | 132 return NULL; |
| 131 } | 133 } |
| 132 | 134 |
| 133 // Note that when copying a render-target-backed pixel ref, we | 135 // Note that when copying a render-target-backed pixel ref, we |
| 134 // return a texture-backed pixel ref instead. This is because | 136 // return a texture-backed pixel ref instead. This is because |
| 135 // render-target pixel refs are usually created in conjunction with | 137 // render-target pixel refs are usually created in conjunction with |
| 136 // a GrTexture owned elsewhere (e.g., SkGpuDevice), and cannot live | 138 // a GrTexture owned elsewhere (e.g., SkGpuDevice), and cannot live |
| 137 // independently of that texture. Texture-backed pixel refs, on the other | 139 // independently of that texture. Texture-backed pixel refs, on the other |
| 138 // hand, own their GrTextures, and are thus self-contained. | 140 // hand, own their GrTextures, and are thus self-contained. |
| 139 return copy_to_new_texture_pixelref(fSurface->asTexture(), dstCT, subset); | 141 return copy_to_new_texture_pixelref(fSurface->asTexture(), dstCT, dstPT, sub
set); |
| 140 } | 142 } |
| 141 | 143 |
| 142 static bool tryAllocBitmapPixels(SkBitmap* bitmap) { | 144 static bool tryAllocBitmapPixels(SkBitmap* bitmap) { |
| 143 SkBitmap::Allocator* allocator = SkBitmapCache::GetAllocator(); | 145 SkBitmap::Allocator* allocator = SkBitmapCache::GetAllocator(); |
| 144 if (NULL != allocator) { | 146 if (NULL != allocator) { |
| 145 return allocator->allocPixelRef(bitmap, 0); | 147 return allocator->allocPixelRef(bitmap, 0); |
| 146 } else { | 148 } else { |
| 147 // DiscardableMemory is not available, fallback to default allocator | 149 // DiscardableMemory is not available, fallback to default allocator |
| 148 return bitmap->tryAllocPixels(); | 150 return bitmap->tryAllocPixels(); |
| 149 } | 151 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 cachedBitmap.setImmutable(); | 190 cachedBitmap.setImmutable(); |
| 189 //Add to the cache | 191 //Add to the cache |
| 190 SkBitmapCache::Add(this->getGenerationID(), bounds, cachedBitmap); | 192 SkBitmapCache::Add(this->getGenerationID(), bounds, cachedBitmap); |
| 191 | 193 |
| 192 dst->swap(cachedBitmap); | 194 dst->swap(cachedBitmap); |
| 193 } | 195 } |
| 194 | 196 |
| 195 return true; | 197 return true; |
| 196 | 198 |
| 197 } | 199 } |
| OLD | NEW |