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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 if (fSurface) { | 118 if (fSurface) { |
119 SkASSERT(info.width() <= fSurface->width()); | 119 SkASSERT(info.width() <= fSurface->width()); |
120 SkASSERT(info.height() <= fSurface->height()); | 120 SkASSERT(info.height() <= fSurface->height()); |
121 } | 121 } |
122 } | 122 } |
123 | 123 |
124 SkGrPixelRef::~SkGrPixelRef() { | 124 SkGrPixelRef::~SkGrPixelRef() { |
125 if (fUnlock) { | 125 if (fUnlock) { |
126 GrContext* context = fSurface->getContext(); | 126 GrContext* context = fSurface->getContext(); |
127 GrTexture* texture = fSurface->asTexture(); | 127 GrTexture* texture = fSurface->asTexture(); |
128 if (NULL != context && NULL != texture) { | 128 if (context && texture) { |
129 context->unlockScratchTexture(texture); | 129 context->unlockScratchTexture(texture); |
130 } | 130 } |
131 } | 131 } |
132 SkSafeUnref(fSurface); | 132 SkSafeUnref(fSurface); |
133 } | 133 } |
134 | 134 |
135 GrTexture* SkGrPixelRef::getTexture() { | 135 GrTexture* SkGrPixelRef::getTexture() { |
136 if (NULL != fSurface) { | 136 if (fSurface) { |
137 return fSurface->asTexture(); | 137 return fSurface->asTexture(); |
138 } | 138 } |
139 return NULL; | 139 return NULL; |
140 } | 140 } |
141 | 141 |
142 SkPixelRef* SkGrPixelRef::deepCopy(SkColorType dstCT, const SkIRect* subset) { | 142 SkPixelRef* SkGrPixelRef::deepCopy(SkColorType dstCT, const SkIRect* subset) { |
143 if (NULL == fSurface) { | 143 if (NULL == fSurface) { |
144 return NULL; | 144 return NULL; |
145 } | 145 } |
146 | 146 |
147 // Note that when copying a render-target-backed pixel ref, we | 147 // Note that when copying a render-target-backed pixel ref, we |
148 // return a texture-backed pixel ref instead. This is because | 148 // return a texture-backed pixel ref instead. This is because |
149 // render-target pixel refs are usually created in conjunction with | 149 // render-target pixel refs are usually created in conjunction with |
150 // a GrTexture owned elsewhere (e.g., SkGpuDevice), and cannot live | 150 // a GrTexture owned elsewhere (e.g., SkGpuDevice), and cannot live |
151 // independently of that texture. Texture-backed pixel refs, on the other | 151 // independently of that texture. Texture-backed pixel refs, on the other |
152 // hand, own their GrTextures, and are thus self-contained. | 152 // hand, own their GrTextures, and are thus self-contained. |
153 return copyToTexturePixelRef(fSurface->asTexture(), dstCT, subset); | 153 return copyToTexturePixelRef(fSurface->asTexture(), dstCT, subset); |
154 } | 154 } |
155 | 155 |
156 bool SkGrPixelRef::onReadPixels(SkBitmap* dst, const SkIRect* subset) { | 156 bool SkGrPixelRef::onReadPixels(SkBitmap* dst, const SkIRect* subset) { |
157 if (NULL == fSurface || fSurface->wasDestroyed()) { | 157 if (NULL == fSurface || fSurface->wasDestroyed()) { |
158 return false; | 158 return false; |
159 } | 159 } |
160 | 160 |
161 int left, top, width, height; | 161 int left, top, width, height; |
162 if (NULL != subset) { | 162 if (subset) { |
163 left = subset->fLeft; | 163 left = subset->fLeft; |
164 width = subset->width(); | 164 width = subset->width(); |
165 top = subset->fTop; | 165 top = subset->fTop; |
166 height = subset->height(); | 166 height = subset->height(); |
167 } else { | 167 } else { |
168 left = 0; | 168 left = 0; |
169 width = this->info().width(); | 169 width = this->info().width(); |
170 top = 0; | 170 top = 0; |
171 height = this->info().height(); | 171 height = this->info().height(); |
172 } | 172 } |
173 if (!dst->tryAllocN32Pixels(width, height)) { | 173 if (!dst->tryAllocN32Pixels(width, height)) { |
174 SkDebugf("SkGrPixelRef::onReadPixels failed to alloc bitmap for result!\
n"); | 174 SkDebugf("SkGrPixelRef::onReadPixels failed to alloc bitmap for result!\
n"); |
175 return false; | 175 return false; |
176 } | 176 } |
177 SkAutoLockPixels al(*dst); | 177 SkAutoLockPixels al(*dst); |
178 void* buffer = dst->getPixels(); | 178 void* buffer = dst->getPixels(); |
179 return fSurface->readPixels(left, top, width, height, | 179 return fSurface->readPixels(left, top, width, height, |
180 kSkia8888_GrPixelConfig, | 180 kSkia8888_GrPixelConfig, |
181 buffer, dst->rowBytes()); | 181 buffer, dst->rowBytes()); |
182 } | 182 } |
OLD | NEW |