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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 context->flush(); | 94 context->flush(); |
95 | 95 |
96 SkImageInfo info = SkImageInfo::Make(desc.fWidth, desc.fHeight, dstCT, kPrem
ul_SkAlphaType); | 96 SkImageInfo info = SkImageInfo::Make(desc.fWidth, desc.fHeight, dstCT, kPrem
ul_SkAlphaType); |
97 SkGrPixelRef* pixelRef = SkNEW_ARGS(SkGrPixelRef, (info, dst)); | 97 SkGrPixelRef* pixelRef = SkNEW_ARGS(SkGrPixelRef, (info, dst)); |
98 SkSafeUnref(dst); | 98 SkSafeUnref(dst); |
99 return pixelRef; | 99 return pixelRef; |
100 } | 100 } |
101 | 101 |
102 /////////////////////////////////////////////////////////////////////////////// | 102 /////////////////////////////////////////////////////////////////////////////// |
103 | 103 |
104 SkGrPixelRef::SkGrPixelRef(const SkImageInfo& info, GrSurface* surface) : INHERI
TED(info) { | 104 SkGrPixelRef::SkGrPixelRef(const SkImageInfo& info, GrSurface* surface, |
| 105 bool transferCacheLock) : INHERITED(info) { |
105 // For surfaces that are both textures and render targets, the texture owns
the | 106 // For surfaces that are both textures and render targets, the texture owns
the |
106 // render target but not vice versa. So we ref the texture to keep both aliv
e for | 107 // render target but not vice versa. So we ref the texture to keep both aliv
e for |
107 // the lifetime of this pixel ref. | 108 // the lifetime of this pixel ref. |
108 fSurface = SkSafeRef(surface->asTexture()); | 109 fSurface = SkSafeRef(surface->asTexture()); |
109 if (NULL == fSurface) { | 110 if (NULL == fSurface) { |
110 fSurface = SkSafeRef(surface); | 111 fSurface = SkSafeRef(surface); |
111 } | 112 } |
| 113 fUnlock = transferCacheLock; |
112 | 114 |
113 if (fSurface) { | 115 if (fSurface) { |
114 SkASSERT(info.width() <= fSurface->width()); | 116 SkASSERT(info.width() <= fSurface->width()); |
115 SkASSERT(info.height() <= fSurface->height()); | 117 SkASSERT(info.height() <= fSurface->height()); |
116 } | 118 } |
117 } | 119 } |
118 | 120 |
119 SkGrPixelRef::~SkGrPixelRef() { | 121 SkGrPixelRef::~SkGrPixelRef() { |
| 122 if (fUnlock) { |
| 123 GrContext* context = fSurface->getContext(); |
| 124 GrTexture* texture = fSurface->asTexture(); |
| 125 if (context && texture) { |
| 126 context->unlockScratchTexture(texture); |
| 127 } |
| 128 } |
120 SkSafeUnref(fSurface); | 129 SkSafeUnref(fSurface); |
121 } | 130 } |
122 | 131 |
123 GrTexture* SkGrPixelRef::getTexture() { | 132 GrTexture* SkGrPixelRef::getTexture() { |
124 if (fSurface) { | 133 if (fSurface) { |
125 return fSurface->asTexture(); | 134 return fSurface->asTexture(); |
126 } | 135 } |
127 return NULL; | 136 return NULL; |
128 } | 137 } |
129 | 138 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 cachedBitmap.setImmutable(); | 199 cachedBitmap.setImmutable(); |
191 //Add to the cache | 200 //Add to the cache |
192 SkBitmapCache::Add(this->getGenerationID(), bounds, cachedBitmap); | 201 SkBitmapCache::Add(this->getGenerationID(), bounds, cachedBitmap); |
193 | 202 |
194 dst->swap(cachedBitmap); | 203 dst->swap(cachedBitmap); |
195 } | 204 } |
196 | 205 |
197 return true; | 206 return true; |
198 | 207 |
199 } | 208 } |
OLD | NEW |