| 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 #include "GrContext.h" | 12 #include "GrContext.h" |
| 13 #include "GrTexture.h" | 13 #include "GrTexture.h" |
| 14 #include "SkGr.h" | 14 #include "SkGr.h" |
| 15 #include "SkRect.h" | 15 #include "SkRect.h" |
| 16 | 16 |
| 17 // since we call lockPixels recursively on fBitmap, we need a distinct mutex, | 17 // since we call lockPixels recursively on fBitmap, we need a distinct mutex, |
| 18 // to avoid deadlock with the default one provided by SkPixelRef. | 18 // to avoid deadlock with the default one provided by SkPixelRef. |
| 19 SK_DECLARE_STATIC_MUTEX(gROLockPixelsPixelRefMutex); | 19 SK_DECLARE_STATIC_MUTEX(gROLockPixelsPixelRefMutex); |
| 20 | 20 |
| 21 SkROLockPixelsPixelRef::SkROLockPixelsPixelRef() : INHERITED(&gROLockPixelsPixel
RefMutex) { | 21 SkROLockPixelsPixelRef::SkROLockPixelsPixelRef(const SkImageInfo& info) |
| 22 : INHERITED(info, &gROLockPixelsPixelRefMutex) { |
| 22 } | 23 } |
| 23 | 24 |
| 24 SkROLockPixelsPixelRef::~SkROLockPixelsPixelRef() { | 25 SkROLockPixelsPixelRef::~SkROLockPixelsPixelRef() { |
| 25 } | 26 } |
| 26 | 27 |
| 27 void* SkROLockPixelsPixelRef::onLockPixels(SkColorTable** ctable) { | 28 bool SkROLockPixelsPixelRef::onNewLockPixels(LockRec* rec) { |
| 28 if (ctable) { | |
| 29 *ctable = NULL; | |
| 30 } | |
| 31 fBitmap.reset(); | 29 fBitmap.reset(); |
| 32 // SkDebugf("---------- calling readpixels in support of lockpixels\n"); | 30 // SkDebugf("---------- calling readpixels in support of lockpixels\n"); |
| 33 if (!this->onReadPixels(&fBitmap, NULL)) { | 31 if (!this->onReadPixels(&fBitmap, NULL)) { |
| 34 SkDebugf("SkROLockPixelsPixelRef::onLockPixels failed!\n"); | 32 SkDebugf("SkROLockPixelsPixelRef::onLockPixels failed!\n"); |
| 35 return NULL; | 33 return false; |
| 36 } | 34 } |
| 37 fBitmap.lockPixels(); | 35 fBitmap.lockPixels(); |
| 38 return fBitmap.getPixels(); | 36 if (NULL == fBitmap.getPixels()) { |
| 37 return false; |
| 38 } |
| 39 |
| 40 rec->fPixels = fBitmap.getPixels(); |
| 41 rec->fColorTable = NULL; |
| 42 rec->fRowBytes = fBitmap.rowBytes(); |
| 43 return true; |
| 39 } | 44 } |
| 40 | 45 |
| 41 void SkROLockPixelsPixelRef::onUnlockPixels() { | 46 void SkROLockPixelsPixelRef::onUnlockPixels() { |
| 42 fBitmap.unlockPixels(); | 47 fBitmap.unlockPixels(); |
| 43 } | 48 } |
| 44 | 49 |
| 45 bool SkROLockPixelsPixelRef::onLockPixelsAreWritable() const { | 50 bool SkROLockPixelsPixelRef::onLockPixelsAreWritable() const { |
| 46 return false; | 51 return false; |
| 47 } | 52 } |
| 48 | 53 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 69 pointStorage.set(subset->x(), subset->y()); | 74 pointStorage.set(subset->x(), subset->y()); |
| 70 topLeft = &pointStorage; | 75 topLeft = &pointStorage; |
| 71 } else { | 76 } else { |
| 72 desc.fWidth = texture->width(); | 77 desc.fWidth = texture->width(); |
| 73 desc.fHeight = texture->height(); | 78 desc.fHeight = texture->height(); |
| 74 topLeft = NULL; | 79 topLeft = NULL; |
| 75 } | 80 } |
| 76 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; | 81 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; |
| 77 desc.fConfig = SkBitmapConfig2GrPixelConfig(dstConfig); | 82 desc.fConfig = SkBitmapConfig2GrPixelConfig(dstConfig); |
| 78 | 83 |
| 84 SkImageInfo info; |
| 85 if (!GrPixelConfig2ColorType(desc.fConfig, &info.fColorType)) { |
| 86 return NULL; |
| 87 } |
| 88 info.fWidth = desc.fWidth; |
| 89 info.fHeight = desc.fHeight; |
| 90 info.fAlphaType = kPremul_SkAlphaType; |
| 91 |
| 79 GrTexture* dst = context->createUncachedTexture(desc, NULL, 0); | 92 GrTexture* dst = context->createUncachedTexture(desc, NULL, 0); |
| 80 if (NULL == dst) { | 93 if (NULL == dst) { |
| 81 return NULL; | 94 return NULL; |
| 82 } | 95 } |
| 83 | 96 |
| 84 context->copyTexture(texture, dst->asRenderTarget(), topLeft); | 97 context->copyTexture(texture, dst->asRenderTarget(), topLeft); |
| 85 | 98 |
| 86 // TODO: figure out if this is responsible for Chrome canvas errors | 99 // TODO: figure out if this is responsible for Chrome canvas errors |
| 87 #if 0 | 100 #if 0 |
| 88 // The render texture we have created (to perform the copy) isn't fully | 101 // The render texture we have created (to perform the copy) isn't fully |
| 89 // functional (since it doesn't have a stencil buffer). Release it here | 102 // functional (since it doesn't have a stencil buffer). Release it here |
| 90 // so the caller doesn't try to render to it. | 103 // so the caller doesn't try to render to it. |
| 91 // TODO: we can undo this release when dynamic stencil buffer attach/ | 104 // TODO: we can undo this release when dynamic stencil buffer attach/ |
| 92 // detach has been implemented | 105 // detach has been implemented |
| 93 dst->releaseRenderTarget(); | 106 dst->releaseRenderTarget(); |
| 94 #endif | 107 #endif |
| 95 | 108 |
| 96 SkGrPixelRef* pixelRef = SkNEW_ARGS(SkGrPixelRef, (dst)); | 109 SkGrPixelRef* pixelRef = SkNEW_ARGS(SkGrPixelRef, (info, dst)); |
| 97 SkSafeUnref(dst); | 110 SkSafeUnref(dst); |
| 98 return pixelRef; | 111 return pixelRef; |
| 99 } | 112 } |
| 100 | 113 |
| 101 /////////////////////////////////////////////////////////////////////////////// | 114 /////////////////////////////////////////////////////////////////////////////// |
| 102 | 115 |
| 103 SkGrPixelRef::SkGrPixelRef(GrSurface* surface, bool transferCacheLock) { | 116 SkGrPixelRef::SkGrPixelRef(const SkImageInfo& info, GrSurface* surface, |
| 117 bool transferCacheLock) |
| 118 : INHERITED(info) |
| 119 { |
| 104 // TODO: figure out if this is responsible for Chrome canvas errors | 120 // TODO: figure out if this is responsible for Chrome canvas errors |
| 105 #if 0 | 121 #if 0 |
| 106 // The GrTexture has a ref to the GrRenderTarget but not vice versa. | 122 // The GrTexture has a ref to the GrRenderTarget but not vice versa. |
| 107 // If the GrTexture exists take a ref to that (rather than the render | 123 // If the GrTexture exists take a ref to that (rather than the render |
| 108 // target) | 124 // target) |
| 109 fSurface = surface->asTexture(); | 125 fSurface = surface->asTexture(); |
| 110 #else | 126 #else |
| 111 fSurface = NULL; | 127 fSurface = NULL; |
| 112 #endif | 128 #endif |
| 113 if (NULL == fSurface) { | 129 if (NULL == fSurface) { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 if (!dst->allocPixels()) { | 186 if (!dst->allocPixels()) { |
| 171 SkDebugf("SkGrPixelRef::onReadPixels failed to alloc bitmap for result!\
n"); | 187 SkDebugf("SkGrPixelRef::onReadPixels failed to alloc bitmap for result!\
n"); |
| 172 return false; | 188 return false; |
| 173 } | 189 } |
| 174 SkAutoLockPixels al(*dst); | 190 SkAutoLockPixels al(*dst); |
| 175 void* buffer = dst->getPixels(); | 191 void* buffer = dst->getPixels(); |
| 176 return fSurface->readPixels(left, top, width, height, | 192 return fSurface->readPixels(left, top, width, height, |
| 177 kSkia8888_GrPixelConfig, | 193 kSkia8888_GrPixelConfig, |
| 178 buffer, dst->rowBytes()); | 194 buffer, dst->rowBytes()); |
| 179 } | 195 } |
| OLD | NEW |