| 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 |
| 11 #include "SkGrPixelRef.h" | 11 #include "SkGrPixelRef.h" |
| 12 | 12 |
| 13 #include "GrContext.h" | 13 #include "GrContext.h" |
| 14 #include "GrTexture.h" | 14 #include "GrTexture.h" |
| 15 #include "GrTexturePriv.h" | 15 #include "GrTexturePriv.h" |
| 16 #include "SkBitmapCache.h" | 16 #include "SkBitmapCache.h" |
| 17 #include "SkGr.h" | 17 #include "SkGr.h" |
| 18 #include "SkRect.h" | 18 #include "SkRect.h" |
| 19 | 19 |
| 20 // since we call lockPixels recursively on fBitmap, we need a distinct mutex, | |
| 21 // to avoid deadlock with the default one provided by SkPixelRef. | |
| 22 SK_DECLARE_STATIC_MUTEX(gROLockPixelsPixelRefMutex); | |
| 23 | |
| 24 SkROLockPixelsPixelRef::SkROLockPixelsPixelRef(const SkImageInfo& info) | 20 SkROLockPixelsPixelRef::SkROLockPixelsPixelRef(const SkImageInfo& info) |
| 25 : INHERITED(info, &gROLockPixelsPixelRefMutex) {} | 21 : INHERITED(info) {} |
| 26 | 22 |
| 27 SkROLockPixelsPixelRef::~SkROLockPixelsPixelRef() {} | 23 SkROLockPixelsPixelRef::~SkROLockPixelsPixelRef() {} |
| 28 | 24 |
| 29 bool SkROLockPixelsPixelRef::onNewLockPixels(LockRec* rec) { | 25 bool SkROLockPixelsPixelRef::onNewLockPixels(LockRec* rec) { |
| 30 fBitmap.reset(); | 26 fBitmap.reset(); |
| 31 // SkDebugf("---------- calling readpixels in support of lockpixels\n"); | 27 // SkDebugf("---------- calling readpixels in support of lockpixels\n"); |
| 32 if (!this->onReadPixels(&fBitmap, NULL)) { | 28 if (!this->onReadPixels(&fBitmap, NULL)) { |
| 33 SkDebugf("SkROLockPixelsPixelRef::onLockPixels failed!\n"); | 29 SkDebugf("SkROLockPixelsPixelRef::onLockPixels failed!\n"); |
| 34 return false; | 30 return false; |
| 35 } | 31 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 GrTexture* dst = context->textureProvider()->createTexture(desc, false, NULL
, 0); | 80 GrTexture* dst = context->textureProvider()->createTexture(desc, false, NULL
, 0); |
| 85 if (NULL == dst) { | 81 if (NULL == dst) { |
| 86 return NULL; | 82 return NULL; |
| 87 } | 83 } |
| 88 | 84 |
| 89 // Blink is relying on the above copy being sent to GL immediately in the ca
se when the source | 85 // Blink is relying on the above copy being sent to GL immediately in the ca
se when the source |
| 90 // is a WebGL canvas backing store. We could have a TODO to remove this flus
h flag, but we have | 86 // is a WebGL canvas backing store. We could have a TODO to remove this flus
h flag, but we have |
| 91 // a larger TODO to remove SkGrPixelRef entirely. | 87 // a larger TODO to remove SkGrPixelRef entirely. |
| 92 context->copySurface(dst->asRenderTarget(), texture, srcRect, SkIPoint::Make
(0,0), | 88 context->copySurface(dst->asRenderTarget(), texture, srcRect, SkIPoint::Make
(0,0), |
| 93 GrContext::kFlushWrites_PixelOp); | 89 GrContext::kFlushWrites_PixelOp); |
| 94 | 90 |
| 95 SkImageInfo info = SkImageInfo::Make(desc.fWidth, desc.fHeight, dstCT, kPrem
ul_SkAlphaType, | 91 SkImageInfo info = SkImageInfo::Make(desc.fWidth, desc.fHeight, dstCT, kPrem
ul_SkAlphaType, |
| 96 dstPT); | 92 dstPT); |
| 97 SkGrPixelRef* pixelRef = SkNEW_ARGS(SkGrPixelRef, (info, dst)); | 93 SkGrPixelRef* pixelRef = SkNEW_ARGS(SkGrPixelRef, (info, dst)); |
| 98 SkSafeUnref(dst); | 94 SkSafeUnref(dst); |
| 99 return pixelRef; | 95 return pixelRef; |
| 100 } | 96 } |
| 101 | 97 |
| 102 /////////////////////////////////////////////////////////////////////////////// | 98 /////////////////////////////////////////////////////////////////////////////// |
| 103 | 99 |
| 104 SkGrPixelRef::SkGrPixelRef(const SkImageInfo& info, GrSurface* surface) : INHERI
TED(info) { | 100 SkGrPixelRef::SkGrPixelRef(const SkImageInfo& info, GrSurface* surface) : INHERI
TED(info) { |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 cachedBitmap.setImmutable(); | 194 cachedBitmap.setImmutable(); |
| 199 //Add to the cache | 195 //Add to the cache |
| 200 SkBitmapCache::Add(this, bounds, cachedBitmap); | 196 SkBitmapCache::Add(this, bounds, cachedBitmap); |
| 201 | 197 |
| 202 dst->swap(cachedBitmap); | 198 dst->swap(cachedBitmap); |
| 203 } | 199 } |
| 204 | 200 |
| 205 return true; | 201 return true; |
| 206 | 202 |
| 207 } | 203 } |
| OLD | NEW |