| 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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 desc.fSampleCnt = sampleCount; | 243 desc.fSampleCnt = sampleCount; |
| 244 | 244 |
| 245 SkAutoTUnref<GrTexture> texture(context->createUncachedTexture(desc, NULL, 0
)); | 245 SkAutoTUnref<GrTexture> texture(context->createUncachedTexture(desc, NULL, 0
)); |
| 246 if (!texture.get()) { | 246 if (!texture.get()) { |
| 247 return NULL; | 247 return NULL; |
| 248 } | 248 } |
| 249 | 249 |
| 250 return SkNEW_ARGS(SkGpuDevice, (context, texture.get())); | 250 return SkNEW_ARGS(SkGpuDevice, (context, texture.get())); |
| 251 } | 251 } |
| 252 | 252 |
| 253 #ifdef SK_SUPPORT_LEGACY_COMPATIBLEDEVICE_CONFIG | |
| 254 static SkBitmap make_bitmap(SkBitmap::Config config, int width, int height) { | |
| 255 SkBitmap bm; | |
| 256 bm.setConfig(SkImageInfo::Make(width, height, | |
| 257 SkBitmapConfigToColorType(config), | |
| 258 kPremul_SkAlphaType)); | |
| 259 return bm; | |
| 260 } | |
| 261 SkGpuDevice::SkGpuDevice(GrContext* context, | |
| 262 SkBitmap::Config config, | |
| 263 int width, | |
| 264 int height, | |
| 265 int sampleCount) | |
| 266 : SkBitmapDevice(make_bitmap(config, width, height)) | |
| 267 { | |
| 268 fDrawProcs = NULL; | |
| 269 | |
| 270 fContext = context; | |
| 271 fContext->ref(); | |
| 272 | |
| 273 fMainTextContext = SkNEW_ARGS(GrDistanceFieldTextContext, (fContext, fLeakyP
roperties)); | |
| 274 fFallbackTextContext = SkNEW_ARGS(GrBitmapTextContext, (fContext, fLeakyProp
erties)); | |
| 275 | |
| 276 fRenderTarget = NULL; | |
| 277 fNeedClear = false; | |
| 278 | |
| 279 if (config != SkBitmap::kRGB_565_Config) { | |
| 280 config = SkBitmap::kARGB_8888_Config; | |
| 281 } | |
| 282 | |
| 283 GrTextureDesc desc; | |
| 284 desc.fFlags = kRenderTarget_GrTextureFlagBit; | |
| 285 desc.fWidth = width; | |
| 286 desc.fHeight = height; | |
| 287 desc.fConfig = SkBitmapConfig2GrPixelConfig(config); | |
| 288 desc.fSampleCnt = sampleCount; | |
| 289 | |
| 290 SkImageInfo info; | |
| 291 if (!GrPixelConfig2ColorType(desc.fConfig, &info.fColorType)) { | |
| 292 sk_throw(); | |
| 293 } | |
| 294 info.fWidth = width; | |
| 295 info.fHeight = height; | |
| 296 info.fAlphaType = kPremul_SkAlphaType; | |
| 297 | |
| 298 SkAutoTUnref<GrTexture> texture(fContext->createUncachedTexture(desc, NULL,
0)); | |
| 299 | |
| 300 if (NULL != texture) { | |
| 301 fRenderTarget = texture->asRenderTarget(); | |
| 302 fRenderTarget->ref(); | |
| 303 | |
| 304 SkASSERT(NULL != fRenderTarget); | |
| 305 | |
| 306 // wrap the bitmap with a pixelref to expose our texture | |
| 307 SkGrPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (info, texture)); | |
| 308 this->setPixelRef(pr)->unref(); | |
| 309 } else { | |
| 310 GrPrintf("--- failed to create gpu-offscreen [%d %d]\n", | |
| 311 width, height); | |
| 312 SkASSERT(false); | |
| 313 } | |
| 314 } | |
| 315 #endif | |
| 316 | |
| 317 SkGpuDevice::~SkGpuDevice() { | 253 SkGpuDevice::~SkGpuDevice() { |
| 318 if (fDrawProcs) { | 254 if (fDrawProcs) { |
| 319 delete fDrawProcs; | 255 delete fDrawProcs; |
| 320 } | 256 } |
| 321 | 257 |
| 322 delete fMainTextContext; | 258 delete fMainTextContext; |
| 323 delete fFallbackTextContext; | 259 delete fFallbackTextContext; |
| 324 | 260 |
| 325 // The GrContext takes a ref on the target. We don't want to cause the rende
r | 261 // The GrContext takes a ref on the target. We don't want to cause the rende
r |
| 326 // target to be unnecessarily kept alive. | 262 // target to be unnecessarily kept alive. |
| (...skipping 1710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2037 const GrAtlasedLayer* layer = fContext->getLayerCache()->findLayerOr
Create(picture, i); | 1973 const GrAtlasedLayer* layer = fContext->getLayerCache()->findLayerOr
Create(picture, i); |
| 2038 | 1974 |
| 2039 SkDebugf("%d (%d), ", i, layer->layerID()); | 1975 SkDebugf("%d (%d), ", i, layer->layerID()); |
| 2040 } | 1976 } |
| 2041 } | 1977 } |
| 2042 SkDebugf("\n"); | 1978 SkDebugf("\n"); |
| 2043 #endif | 1979 #endif |
| 2044 | 1980 |
| 2045 return false; | 1981 return false; |
| 2046 } | 1982 } |
| OLD | NEW |