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(const SkImageInfo& info) | 21 SkROLockPixelsPixelRef::SkROLockPixelsPixelRef(const SkImageInfo& info) |
22 : INHERITED(info, &gROLockPixelsPixelRefMutex) {} | 22 : INHERITED(info, &gROLockPixelsPixelRefMutex) {} |
23 | 23 |
24 SkROLockPixelsPixelRef::~SkROLockPixelsPixelRef() {} | 24 SkROLockPixelsPixelRef::~SkROLockPixelsPixelRef() {} |
25 | 25 |
26 void* SkROLockPixelsPixelRef::onLockPixels(SkColorTable** ctable) { | 26 bool SkROLockPixelsPixelRef::onNewLockPixels(LockRec* rec) { |
27 if (ctable) { | |
28 *ctable = NULL; | |
29 } | |
30 fBitmap.reset(); | 27 fBitmap.reset(); |
31 // SkDebugf("---------- calling readpixels in support of lockpixels\n"); | 28 // SkDebugf("---------- calling readpixels in support of lockpixels\n"); |
32 if (!this->onReadPixels(&fBitmap, NULL)) { | 29 if (!this->onReadPixels(&fBitmap, NULL)) { |
33 SkDebugf("SkROLockPixelsPixelRef::onLockPixels failed!\n"); | 30 SkDebugf("SkROLockPixelsPixelRef::onLockPixels failed!\n"); |
34 return NULL; | 31 return false; |
35 } | 32 } |
36 fBitmap.lockPixels(); | 33 fBitmap.lockPixels(); |
37 return fBitmap.getPixels(); | 34 if (NULL == fBitmap.getPixels()) { |
| 35 return false; |
| 36 } |
| 37 |
| 38 rec->fPixels = fBitmap.getPixels(); |
| 39 rec->fColorTable = NULL; |
| 40 rec->fRowBytes = fBitmap.rowBytes(); |
| 41 return true; |
38 } | 42 } |
39 | 43 |
40 void SkROLockPixelsPixelRef::onUnlockPixels() { | 44 void SkROLockPixelsPixelRef::onUnlockPixels() { |
41 fBitmap.unlockPixels(); | 45 fBitmap.unlockPixels(); |
42 } | 46 } |
43 | 47 |
44 bool SkROLockPixelsPixelRef::onLockPixelsAreWritable() const { | 48 bool SkROLockPixelsPixelRef::onLockPixelsAreWritable() const { |
45 return false; | 49 return false; |
46 } | 50 } |
47 | 51 |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 if (!dst->allocPixels()) { | 182 if (!dst->allocPixels()) { |
179 SkDebugf("SkGrPixelRef::onReadPixels failed to alloc bitmap for result!\
n"); | 183 SkDebugf("SkGrPixelRef::onReadPixels failed to alloc bitmap for result!\
n"); |
180 return false; | 184 return false; |
181 } | 185 } |
182 SkAutoLockPixels al(*dst); | 186 SkAutoLockPixels al(*dst); |
183 void* buffer = dst->getPixels(); | 187 void* buffer = dst->getPixels(); |
184 return fSurface->readPixels(left, top, width, height, | 188 return fSurface->readPixels(left, top, width, height, |
185 kSkia8888_GrPixelConfig, | 189 kSkia8888_GrPixelConfig, |
186 buffer, dst->rowBytes()); | 190 buffer, dst->rowBytes()); |
187 } | 191 } |
OLD | NEW |