| 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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 } | 181 } |
| 182 | 182 |
| 183 void SkGpuDevice::initFromRenderTarget(GrContext* context, | 183 void SkGpuDevice::initFromRenderTarget(GrContext* context, |
| 184 GrRenderTarget* renderTarget, | 184 GrRenderTarget* renderTarget, |
| 185 unsigned flags) { | 185 unsigned flags) { |
| 186 fDrawProcs = NULL; | 186 fDrawProcs = NULL; |
| 187 | 187 |
| 188 fContext = context; | 188 fContext = context; |
| 189 fContext->ref(); | 189 fContext->ref(); |
| 190 | 190 |
| 191 fMainTextContext = SkNEW_ARGS(GrDistanceFieldTextContext, (fContext, fLeakyP
roperties)); |
| 192 fFallbackTextContext = SkNEW_ARGS(GrBitmapTextContext, (fContext, fLeakyProp
erties)); |
| 193 |
| 191 fRenderTarget = NULL; | 194 fRenderTarget = NULL; |
| 192 fNeedClear = flags & kNeedClear_Flag; | 195 fNeedClear = flags & kNeedClear_Flag; |
| 193 | 196 |
| 194 SkASSERT(NULL != renderTarget); | 197 SkASSERT(NULL != renderTarget); |
| 195 fRenderTarget = renderTarget; | 198 fRenderTarget = renderTarget; |
| 196 fRenderTarget->ref(); | 199 fRenderTarget->ref(); |
| 197 | 200 |
| 198 // Hold onto to the texture in the pixel ref (if there is one) because the t
exture holds a ref | 201 // Hold onto to the texture in the pixel ref (if there is one) because the t
exture holds a ref |
| 199 // on the RT but not vice-versa. | 202 // on the RT but not vice-versa. |
| 200 // TODO: Remove this trickery once we figure out how to make SkGrPixelRef do
this without | 203 // TODO: Remove this trickery once we figure out how to make SkGrPixelRef do
this without |
| 201 // busting chrome (for a currently unknown reason). | 204 // busting chrome (for a currently unknown reason). |
| 202 GrSurface* surface = fRenderTarget->asTexture(); | 205 GrSurface* surface = fRenderTarget->asTexture(); |
| 203 if (NULL == surface) { | 206 if (NULL == surface) { |
| 204 surface = fRenderTarget; | 207 surface = fRenderTarget; |
| 205 } | 208 } |
| 206 | 209 |
| 207 SkImageInfo info; | 210 SkImageInfo info; |
| 208 surface->asImageInfo(&info); | 211 surface->asImageInfo(&info); |
| 209 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (info, surface, SkToBool(flags & k
Cached_Flag))); | 212 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (info, surface, SkToBool(flags & k
Cached_Flag))); |
| 210 | 213 |
| 211 this->setPixelRef(pr)->unref(); | 214 this->setPixelRef(pr)->unref(); |
| 212 | |
| 213 fMainTextContext = fContext->createTextContext(fRenderTarget, fLeakyProperti
es); | |
| 214 fFallbackTextContext = SkNEW_ARGS(GrBitmapTextContext, (fContext, fLeakyProp
erties)); | |
| 215 } | 215 } |
| 216 | 216 |
| 217 SkGpuDevice* SkGpuDevice::Create(GrContext* context, const SkImageInfo& origInfo
, | 217 SkGpuDevice* SkGpuDevice::Create(GrContext* context, const SkImageInfo& origInfo
, |
| 218 int sampleCount) { | 218 int sampleCount) { |
| 219 if (kUnknown_SkColorType == origInfo.colorType() || | 219 if (kUnknown_SkColorType == origInfo.colorType() || |
| 220 origInfo.width() < 0 || origInfo.height() < 0) { | 220 origInfo.width() < 0 || origInfo.height() < 0) { |
| 221 return NULL; | 221 return NULL; |
| 222 } | 222 } |
| 223 | 223 |
| 224 SkImageInfo info = origInfo; | 224 SkImageInfo info = origInfo; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 int width, | 261 int width, |
| 262 int height, | 262 int height, |
| 263 int sampleCount) | 263 int sampleCount) |
| 264 : SkBitmapDevice(make_bitmap(config, width, height)) | 264 : SkBitmapDevice(make_bitmap(config, width, height)) |
| 265 { | 265 { |
| 266 fDrawProcs = NULL; | 266 fDrawProcs = NULL; |
| 267 | 267 |
| 268 fContext = context; | 268 fContext = context; |
| 269 fContext->ref(); | 269 fContext->ref(); |
| 270 | 270 |
| 271 fMainTextContext = SkNEW_ARGS(GrDistanceFieldTextContext, (fContext, fLeakyP
roperties)); |
| 272 fFallbackTextContext = SkNEW_ARGS(GrBitmapTextContext, (fContext, fLeakyProp
erties)); |
| 273 |
| 271 fRenderTarget = NULL; | 274 fRenderTarget = NULL; |
| 272 fNeedClear = false; | 275 fNeedClear = false; |
| 273 | 276 |
| 274 if (config != SkBitmap::kRGB_565_Config) { | 277 if (config != SkBitmap::kRGB_565_Config) { |
| 275 config = SkBitmap::kARGB_8888_Config; | 278 config = SkBitmap::kARGB_8888_Config; |
| 276 } | 279 } |
| 277 | 280 |
| 278 GrTextureDesc desc; | 281 GrTextureDesc desc; |
| 279 desc.fFlags = kRenderTarget_GrTextureFlagBit; | 282 desc.fFlags = kRenderTarget_GrTextureFlagBit; |
| 280 desc.fWidth = width; | 283 desc.fWidth = width; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 299 SkASSERT(NULL != fRenderTarget); | 302 SkASSERT(NULL != fRenderTarget); |
| 300 | 303 |
| 301 // wrap the bitmap with a pixelref to expose our texture | 304 // wrap the bitmap with a pixelref to expose our texture |
| 302 SkGrPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (info, texture)); | 305 SkGrPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (info, texture)); |
| 303 this->setPixelRef(pr)->unref(); | 306 this->setPixelRef(pr)->unref(); |
| 304 } else { | 307 } else { |
| 305 GrPrintf("--- failed to create gpu-offscreen [%d %d]\n", | 308 GrPrintf("--- failed to create gpu-offscreen [%d %d]\n", |
| 306 width, height); | 309 width, height); |
| 307 SkASSERT(false); | 310 SkASSERT(false); |
| 308 } | 311 } |
| 309 | |
| 310 fMainTextContext = fContext->createTextContext(fRenderTarget, fLeakyProperti
es); | |
| 311 fFallbackTextContext = SkNEW_ARGS(GrBitmapTextContext, (fContext, fLeakyProp
erties)); | |
| 312 } | 312 } |
| 313 #endif | 313 #endif |
| 314 | 314 |
| 315 SkGpuDevice::~SkGpuDevice() { | 315 SkGpuDevice::~SkGpuDevice() { |
| 316 if (fDrawProcs) { | 316 if (fDrawProcs) { |
| 317 delete fDrawProcs; | 317 delete fDrawProcs; |
| 318 } | 318 } |
| 319 | 319 |
| 320 delete fMainTextContext; | 320 delete fMainTextContext; |
| 321 delete fFallbackTextContext; | 321 delete fFallbackTextContext; |
| (...skipping 1655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1977 if (NULL == data) { | 1977 if (NULL == data) { |
| 1978 return false; | 1978 return false; |
| 1979 } | 1979 } |
| 1980 | 1980 |
| 1981 #if 0 | 1981 #if 0 |
| 1982 const GPUAccelData *gpuData = static_cast<const GPUAccelData*>(data); | 1982 const GPUAccelData *gpuData = static_cast<const GPUAccelData*>(data); |
| 1983 #endif | 1983 #endif |
| 1984 | 1984 |
| 1985 return false; | 1985 return false; |
| 1986 } | 1986 } |
| OLD | NEW |