OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkGpuDevice.h" | 8 #include "SkGpuDevice.h" |
9 | 9 |
10 #include "effects/GrBicubicEffect.h" | 10 #include "effects/GrBicubicEffect.h" |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 static SkBitmap make_bitmap(GrContext* context, GrRenderTarget* renderTarget) { | 148 static SkBitmap make_bitmap(GrContext* context, GrRenderTarget* renderTarget) { |
149 bool isOpaque; | 149 bool isOpaque; |
150 SkBitmap::Config config = grConfig2skConfig(renderTarget->config(), &isOpaqu
e); | 150 SkBitmap::Config config = grConfig2skConfig(renderTarget->config(), &isOpaqu
e); |
151 | 151 |
152 SkBitmap bitmap; | 152 SkBitmap bitmap; |
153 bitmap.setConfig(config, renderTarget->width(), renderTarget->height(), 0, | 153 bitmap.setConfig(config, renderTarget->width(), renderTarget->height(), 0, |
154 isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); | 154 isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); |
155 return bitmap; | 155 return bitmap; |
156 } | 156 } |
157 | 157 |
| 158 /* |
| 159 * Calling SkBitmapDevice with individual params asks it to allocate pixel memo
ry. |
| 160 * We never want that, so we always need to call it with a bitmap argument |
| 161 * (which says take my allocate (or lack thereof)). |
| 162 * |
| 163 * This is a REALLY good reason to finish the clean-up of SkBaseDevice, and hav
e |
| 164 * SkGpuDevice inherit from that instead of SkBitmapDevice. |
| 165 */ |
| 166 static SkBitmap make_bitmap(SkBitmap::Config config, int width, int height, bool
isOpaque) { |
| 167 SkBitmap bm; |
| 168 bm.setConfig(config, width, height, isOpaque); |
| 169 return bm; |
| 170 } |
| 171 |
158 SkGpuDevice* SkGpuDevice::Create(GrSurface* surface) { | 172 SkGpuDevice* SkGpuDevice::Create(GrSurface* surface) { |
159 SkASSERT(NULL != surface); | 173 SkASSERT(NULL != surface); |
160 if (NULL == surface->asRenderTarget() || NULL == surface->getContext()) { | 174 if (NULL == surface->asRenderTarget() || NULL == surface->getContext()) { |
161 return NULL; | 175 return NULL; |
162 } | 176 } |
163 if (surface->asTexture()) { | 177 if (surface->asTexture()) { |
164 return SkNEW_ARGS(SkGpuDevice, (surface->getContext(), surface->asTextur
e())); | 178 return SkNEW_ARGS(SkGpuDevice, (surface->getContext(), surface->asTextur
e())); |
165 } else { | 179 } else { |
166 return SkNEW_ARGS(SkGpuDevice, (surface->getContext(), surface->asRender
Target())); | 180 return SkNEW_ARGS(SkGpuDevice, (surface->getContext(), surface->asRender
Target())); |
167 } | 181 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (surface, cached)); | 217 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (surface, cached)); |
204 | 218 |
205 this->setPixelRef(pr, 0)->unref(); | 219 this->setPixelRef(pr, 0)->unref(); |
206 } | 220 } |
207 | 221 |
208 SkGpuDevice::SkGpuDevice(GrContext* context, | 222 SkGpuDevice::SkGpuDevice(GrContext* context, |
209 SkBitmap::Config config, | 223 SkBitmap::Config config, |
210 int width, | 224 int width, |
211 int height, | 225 int height, |
212 int sampleCount) | 226 int sampleCount) |
213 : SkBitmapDevice(config, width, height, false /*isOpaque*/) { | 227 : SkBitmapDevice(make_bitmap(config, width, height, false /*isOpaque*/)) { |
214 | 228 |
215 fDrawProcs = NULL; | 229 fDrawProcs = NULL; |
216 | 230 |
217 fContext = context; | 231 fContext = context; |
218 fContext->ref(); | 232 fContext->ref(); |
219 | 233 |
220 fRenderTarget = NULL; | 234 fRenderTarget = NULL; |
221 fNeedClear = false; | 235 fNeedClear = false; |
222 | 236 |
223 if (config != SkBitmap::kRGB_565_Config) { | 237 if (config != SkBitmap::kRGB_565_Config) { |
(...skipping 1657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1881 GrTexture* texture, | 1895 GrTexture* texture, |
1882 bool needClear) | 1896 bool needClear) |
1883 : SkBitmapDevice(make_bitmap(context, texture->asRenderTarget())) { | 1897 : SkBitmapDevice(make_bitmap(context, texture->asRenderTarget())) { |
1884 | 1898 |
1885 SkASSERT(texture && texture->asRenderTarget()); | 1899 SkASSERT(texture && texture->asRenderTarget()); |
1886 // This constructor is called from onCreateCompatibleDevice. It has locked t
he RT in the texture | 1900 // This constructor is called from onCreateCompatibleDevice. It has locked t
he RT in the texture |
1887 // cache. We pass true for the third argument so that it will get unlocked. | 1901 // cache. We pass true for the third argument so that it will get unlocked. |
1888 this->initFromRenderTarget(context, texture->asRenderTarget(), true); | 1902 this->initFromRenderTarget(context, texture->asRenderTarget(), true); |
1889 fNeedClear = needClear; | 1903 fNeedClear = needClear; |
1890 } | 1904 } |
OLD | NEW |