| 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 public: | 127 public: |
| 128 GrContext* fContext; | 128 GrContext* fContext; |
| 129 GrTextContext* fTextContext; | 129 GrTextContext* fTextContext; |
| 130 GrFontScaler* fFontScaler; // cached in the skia glyphcache | 130 GrFontScaler* fFontScaler; // cached in the skia glyphcache |
| 131 }; | 131 }; |
| 132 | 132 |
| 133 /////////////////////////////////////////////////////////////////////////////// | 133 /////////////////////////////////////////////////////////////////////////////// |
| 134 | 134 |
| 135 SkGpuDevice* SkGpuDevice::Create(GrSurface* surface, unsigned flags) { | 135 SkGpuDevice* SkGpuDevice::Create(GrSurface* surface, unsigned flags) { |
| 136 SkASSERT(NULL != surface); | 136 SkASSERT(NULL != surface); |
| 137 if (NULL == surface->asRenderTarget() || NULL == surface->getContext()) { | 137 if (NULL == surface->asRenderTarget() || surface->wasDestroyed()) { |
| 138 return NULL; | 138 return NULL; |
| 139 } | 139 } |
| 140 if (surface->asTexture()) { | 140 return SkNEW_ARGS(SkGpuDevice, (surface, flags)); |
| 141 return SkNEW_ARGS(SkGpuDevice, (surface->getContext(), surface->asTextur
e(), flags)); | |
| 142 } else { | |
| 143 return SkNEW_ARGS(SkGpuDevice, (surface->getContext(), surface->asRender
Target(), flags)); | |
| 144 } | |
| 145 } | 141 } |
| 146 | 142 |
| 147 SkGpuDevice::SkGpuDevice(GrContext* context, GrTexture* texture, unsigned flags)
{ | 143 SkGpuDevice::SkGpuDevice(GrSurface* surface, unsigned flags) { |
| 148 this->initFromRenderTarget(context, texture->asRenderTarget(), flags); | |
| 149 } | |
| 150 | 144 |
| 151 SkGpuDevice::SkGpuDevice(GrContext* context, GrRenderTarget* renderTarget, unsig
ned flags) { | |
| 152 this->initFromRenderTarget(context, renderTarget, flags); | |
| 153 } | |
| 154 | |
| 155 void SkGpuDevice::initFromRenderTarget(GrContext* context, | |
| 156 GrRenderTarget* renderTarget, | |
| 157 unsigned flags) { | |
| 158 fDrawProcs = NULL; | 145 fDrawProcs = NULL; |
| 159 | 146 |
| 160 fContext = context; | 147 fContext = SkRef(surface->getContext()); |
| 161 fContext->ref(); | |
| 162 | 148 |
| 163 fRenderTarget = NULL; | |
| 164 fNeedClear = flags & kNeedClear_Flag; | 149 fNeedClear = flags & kNeedClear_Flag; |
| 165 | 150 |
| 166 SkASSERT(NULL != renderTarget); | 151 fRenderTarget = SkRef(surface->asRenderTarget()); |
| 167 fRenderTarget = renderTarget; | |
| 168 fRenderTarget->ref(); | |
| 169 | 152 |
| 170 // Hold onto to the texture in the pixel ref (if there is one) because the t
exture holds a ref | 153 // Hold onto to the texture in the pixel ref (if there is one) because the t
exture holds a ref |
| 171 // on the RT but not vice-versa. | 154 // on the RT but not vice-versa. |
| 172 // TODO: Remove this trickery once we figure out how to make SkGrPixelRef do
this without | 155 // TODO: Remove this trickery once we figure out how to make SkGrPixelRef do
this without |
| 173 // busting chrome (for a currently unknown reason). | 156 // busting chrome (for a currently unknown reason). |
| 174 GrSurface* surface = fRenderTarget->asTexture(); | 157 surface = fRenderTarget->asTexture(); |
| 175 if (NULL == surface) { | 158 if (NULL == surface) { |
| 176 surface = fRenderTarget; | 159 surface = fRenderTarget; |
| 177 } | 160 } |
| 178 | 161 |
| 179 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, | 162 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, |
| 180 (surface->info(), surface, SkToBool(flags & kCac
hed_Flag))); | 163 (surface->info(), surface, SkToBool(flags & kCac
hed_Flag))); |
| 181 fLegacyBitmap.setInfo(surface->info()); | 164 fLegacyBitmap.setInfo(surface->info()); |
| 182 fLegacyBitmap.setPixelRef(pr)->unref(); | 165 fLegacyBitmap.setPixelRef(pr)->unref(); |
| 183 | 166 |
| 184 bool useDFFonts = !!(flags & kDFFonts_Flag); | 167 bool useDFFonts = !!(flags & kDFFonts_Flag); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 210 desc.fWidth = info.width(); | 193 desc.fWidth = info.width(); |
| 211 desc.fHeight = info.height(); | 194 desc.fHeight = info.height(); |
| 212 desc.fConfig = SkImageInfo2GrPixelConfig(info); | 195 desc.fConfig = SkImageInfo2GrPixelConfig(info); |
| 213 desc.fSampleCnt = sampleCount; | 196 desc.fSampleCnt = sampleCount; |
| 214 | 197 |
| 215 SkAutoTUnref<GrTexture> texture(context->createUncachedTexture(desc, NULL, 0
)); | 198 SkAutoTUnref<GrTexture> texture(context->createUncachedTexture(desc, NULL, 0
)); |
| 216 if (!texture.get()) { | 199 if (!texture.get()) { |
| 217 return NULL; | 200 return NULL; |
| 218 } | 201 } |
| 219 | 202 |
| 220 return SkNEW_ARGS(SkGpuDevice, (context, texture.get())); | 203 return SkNEW_ARGS(SkGpuDevice, (texture.get())); |
| 221 } | 204 } |
| 222 | 205 |
| 223 SkGpuDevice::~SkGpuDevice() { | 206 SkGpuDevice::~SkGpuDevice() { |
| 224 if (fDrawProcs) { | 207 if (fDrawProcs) { |
| 225 delete fDrawProcs; | 208 delete fDrawProcs; |
| 226 } | 209 } |
| 227 | 210 |
| 228 delete fMainTextContext; | 211 delete fMainTextContext; |
| 229 delete fFallbackTextContext; | 212 delete fFallbackTextContext; |
| 230 | 213 |
| 231 // The GrContext takes a ref on the target. We don't want to cause the rende
r | 214 // The GrContext takes a ref on the target. We don't want to cause the rende
r |
| 232 // target to be unnecessarily kept alive. | 215 // target to be unnecessarily kept alive. |
| 233 if (fContext->getRenderTarget() == fRenderTarget) { | 216 if (fContext->getRenderTarget() == fRenderTarget) { |
| 234 fContext->setRenderTarget(NULL); | 217 fContext->setRenderTarget(NULL); |
| 235 } | 218 } |
| 236 | 219 |
| 237 if (fContext->getClip() == &fClipData) { | 220 if (fContext->getClip() == &fClipData) { |
| 238 fContext->setClip(NULL); | 221 fContext->setClip(NULL); |
| 239 } | 222 } |
| 240 | 223 |
| 241 SkSafeUnref(fRenderTarget); | 224 fRenderTarget->unref(); |
| 242 fContext->unref(); | 225 fContext->unref(); |
| 243 } | 226 } |
| 244 | 227 |
| 245 /////////////////////////////////////////////////////////////////////////////// | 228 /////////////////////////////////////////////////////////////////////////////// |
| 246 | 229 |
| 247 void SkGpuDevice::makeRenderTargetCurrent() { | |
| 248 DO_DEFERRED_CLEAR(); | |
| 249 fContext->setRenderTarget(fRenderTarget); | |
| 250 } | |
| 251 | |
| 252 /////////////////////////////////////////////////////////////////////////////// | |
| 253 | |
| 254 bool SkGpuDevice::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size
_t dstRowBytes, | 230 bool SkGpuDevice::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size
_t dstRowBytes, |
| 255 int x, int y) { | 231 int x, int y) { |
| 256 DO_DEFERRED_CLEAR(); | 232 DO_DEFERRED_CLEAR(); |
| 257 | 233 |
| 258 // TODO: teach fRenderTarget to take ImageInfo directly to specify the src p
ixels | 234 // TODO: teach fRenderTarget to take ImageInfo directly to specify the src p
ixels |
| 259 GrPixelConfig config = SkImageInfo2GrPixelConfig(dstInfo); | 235 GrPixelConfig config = SkImageInfo2GrPixelConfig(dstInfo); |
| 260 if (kUnknown_GrPixelConfig == config) { | 236 if (kUnknown_GrPixelConfig == config) { |
| 261 return false; | 237 return false; |
| 262 } | 238 } |
| 263 | 239 |
| (...skipping 1909 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2173 | 2149 |
| 2174 fContext->getLayerCache()->purgeAll(); | 2150 fContext->getLayerCache()->purgeAll(); |
| 2175 #endif | 2151 #endif |
| 2176 } | 2152 } |
| 2177 | 2153 |
| 2178 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { | 2154 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { |
| 2179 // We always return a transient cache, so it is freed after each | 2155 // We always return a transient cache, so it is freed after each |
| 2180 // filter traversal. | 2156 // filter traversal. |
| 2181 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); | 2157 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); |
| 2182 } | 2158 } |
| OLD | NEW |