Chromium Code Reviews| 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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 GrContext* fContext; | 123 GrContext* fContext; |
| 124 GrTextContext* fTextContext; | 124 GrTextContext* fTextContext; |
| 125 GrFontScaler* fFontScaler; // cached in the skia glyphcache | 125 GrFontScaler* fFontScaler; // cached in the skia glyphcache |
| 126 }; | 126 }; |
| 127 | 127 |
| 128 /////////////////////////////////////////////////////////////////////////////// | 128 /////////////////////////////////////////////////////////////////////////////// |
| 129 | 129 |
| 130 /* | 130 /* |
| 131 * GrRenderTarget does not know its opaqueness, only its config, so we have | 131 * GrRenderTarget does not know its opaqueness, only its config, so we have |
| 132 * to make conservative guesses when we return an "equivalent" bitmap. | 132 * to make conservative guesses when we return an "equivalent" bitmap. |
| 133 */ | 133 */ |
|
robertphillips
2014/06/27 12:02:58
Delete make_bitmap ?
reed1
2014/06/27 12:39:42
Done.
| |
| 134 static SkBitmap make_bitmap(GrContext* context, GrRenderTarget* renderTarget) { | 134 static SkBitmap make_bitmap(GrContext* context, GrRenderTarget* renderTarget) { |
| 135 SkBitmap bitmap; | 135 SkBitmap bitmap; |
| 136 bitmap.setInfo(renderTarget->info()); | 136 bitmap.setInfo(renderTarget->info()); |
| 137 return bitmap; | 137 return bitmap; |
| 138 } | 138 } |
| 139 | 139 |
| 140 SkGpuDevice* SkGpuDevice::Create(GrSurface* surface, unsigned flags) { | 140 SkGpuDevice* SkGpuDevice::Create(GrSurface* surface, unsigned flags) { |
| 141 SkASSERT(NULL != surface); | 141 SkASSERT(NULL != surface); |
| 142 if (NULL == surface->asRenderTarget() || NULL == surface->getContext()) { | 142 if (NULL == surface->asRenderTarget() || NULL == surface->getContext()) { |
| 143 return NULL; | 143 return NULL; |
| 144 } | 144 } |
| 145 if (surface->asTexture()) { | 145 if (surface->asTexture()) { |
| 146 return SkNEW_ARGS(SkGpuDevice, (surface->getContext(), surface->asTextur e(), flags)); | 146 return SkNEW_ARGS(SkGpuDevice, (surface->getContext(), surface->asTextur e(), flags)); |
| 147 } else { | 147 } else { |
| 148 return SkNEW_ARGS(SkGpuDevice, (surface->getContext(), surface->asRender Target(), flags)); | 148 return SkNEW_ARGS(SkGpuDevice, (surface->getContext(), surface->asRender Target(), flags)); |
| 149 } | 149 } |
| 150 } | 150 } |
| 151 | 151 |
| 152 SkGpuDevice::SkGpuDevice(GrContext* context, GrTexture* texture, unsigned flags) | 152 SkGpuDevice::SkGpuDevice(GrContext* context, GrTexture* texture, unsigned flags) { |
| 153 : SkBitmapDevice(make_bitmap(context, texture->asRenderTarget())) { | |
| 154 this->initFromRenderTarget(context, texture->asRenderTarget(), flags); | 153 this->initFromRenderTarget(context, texture->asRenderTarget(), flags); |
| 155 } | 154 } |
| 156 | 155 |
| 157 SkGpuDevice::SkGpuDevice(GrContext* context, GrRenderTarget* renderTarget, unsig ned flags) | 156 SkGpuDevice::SkGpuDevice(GrContext* context, GrRenderTarget* renderTarget, unsig ned flags) { |
| 158 : SkBitmapDevice(make_bitmap(context, renderTarget)) { | |
| 159 this->initFromRenderTarget(context, renderTarget, flags); | 157 this->initFromRenderTarget(context, renderTarget, flags); |
| 160 } | 158 } |
| 161 | 159 |
| 162 void SkGpuDevice::initFromRenderTarget(GrContext* context, | 160 void SkGpuDevice::initFromRenderTarget(GrContext* context, |
| 163 GrRenderTarget* renderTarget, | 161 GrRenderTarget* renderTarget, |
| 164 unsigned flags) { | 162 unsigned flags) { |
| 165 fDrawProcs = NULL; | 163 fDrawProcs = NULL; |
| 166 | 164 |
| 167 fContext = context; | 165 fContext = context; |
| 168 fContext->ref(); | 166 fContext->ref(); |
| 169 | 167 |
| 170 fRenderTarget = NULL; | 168 fRenderTarget = NULL; |
| 171 fNeedClear = flags & kNeedClear_Flag; | 169 fNeedClear = flags & kNeedClear_Flag; |
| 172 | 170 |
| 173 SkASSERT(NULL != renderTarget); | 171 SkASSERT(NULL != renderTarget); |
| 174 fRenderTarget = renderTarget; | 172 fRenderTarget = renderTarget; |
| 175 fRenderTarget->ref(); | 173 fRenderTarget->ref(); |
| 176 | 174 |
| 177 // Hold onto to the texture in the pixel ref (if there is one) because the t exture holds a ref | 175 // Hold onto to the texture in the pixel ref (if there is one) because the t exture holds a ref |
| 178 // on the RT but not vice-versa. | 176 // on the RT but not vice-versa. |
| 179 // TODO: Remove this trickery once we figure out how to make SkGrPixelRef do this without | 177 // TODO: Remove this trickery once we figure out how to make SkGrPixelRef do this without |
| 180 // busting chrome (for a currently unknown reason). | 178 // busting chrome (for a currently unknown reason). |
| 181 GrSurface* surface = fRenderTarget->asTexture(); | 179 GrSurface* surface = fRenderTarget->asTexture(); |
| 182 if (NULL == surface) { | 180 if (NULL == surface) { |
| 183 surface = fRenderTarget; | 181 surface = fRenderTarget; |
| 184 } | 182 } |
| 185 | 183 |
| 186 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, | 184 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, |
| 187 (surface->info(), surface, SkToBool(flags & kCac hed_Flag))); | 185 (surface->info(), surface, SkToBool(flags & kCac hed_Flag))); |
| 188 | 186 fLegacyBitmap.setInfo(surface->info()); |
| 189 this->setPixelRef(pr)->unref(); | 187 fLegacyBitmap.setPixelRef(pr)->unref(); |
| 190 | 188 |
| 191 bool useDFFonts = !!(flags & kDFFonts_Flag); | 189 bool useDFFonts = !!(flags & kDFFonts_Flag); |
| 192 fMainTextContext = fContext->createTextContext(fRenderTarget, fLeakyProperti es, useDFFonts); | 190 fMainTextContext = fContext->createTextContext(fRenderTarget, fLeakyProperti es, useDFFonts); |
| 193 fFallbackTextContext = SkNEW_ARGS(GrBitmapTextContext, (fContext, fLeakyProp erties)); | 191 fFallbackTextContext = SkNEW_ARGS(GrBitmapTextContext, (fContext, fLeakyProp erties)); |
| 194 } | 192 } |
| 195 | 193 |
| 196 SkGpuDevice* SkGpuDevice::Create(GrContext* context, const SkImageInfo& origInfo , | 194 SkGpuDevice* SkGpuDevice::Create(GrContext* context, const SkImageInfo& origInfo , |
| 197 int sampleCount) { | 195 int sampleCount) { |
| 198 if (kUnknown_SkColorType == origInfo.colorType() || | 196 if (kUnknown_SkColorType == origInfo.colorType() || |
| 199 origInfo.width() < 0 || origInfo.height() < 0) { | 197 origInfo.width() < 0 || origInfo.height() < 0) { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 283 if (kUnknown_GrPixelConfig == config) { | 281 if (kUnknown_GrPixelConfig == config) { |
| 284 return false; | 282 return false; |
| 285 } | 283 } |
| 286 uint32_t flags = 0; | 284 uint32_t flags = 0; |
| 287 if (kUnpremul_SkAlphaType == info.alphaType()) { | 285 if (kUnpremul_SkAlphaType == info.alphaType()) { |
| 288 flags = GrContext::kUnpremul_PixelOpsFlag; | 286 flags = GrContext::kUnpremul_PixelOpsFlag; |
| 289 } | 287 } |
| 290 fRenderTarget->writePixels(x, y, info.width(), info.height(), config, pixels , rowBytes, flags); | 288 fRenderTarget->writePixels(x, y, info.width(), info.height(), config, pixels , rowBytes, flags); |
| 291 | 289 |
| 292 // need to bump our genID for compatibility with clients that "know" we have a bitmap | 290 // need to bump our genID for compatibility with clients that "know" we have a bitmap |
| 293 this->onAccessBitmap().notifyPixelsChanged(); | 291 fLegacyBitmap.notifyPixelsChanged(); |
| 294 | 292 |
| 295 return true; | 293 return true; |
| 296 } | 294 } |
| 297 | 295 |
| 298 const SkBitmap& SkGpuDevice::onAccessBitmap() { | 296 const SkBitmap& SkGpuDevice::onAccessBitmap() { |
| 299 DO_DEFERRED_CLEAR(); | 297 DO_DEFERRED_CLEAR(); |
| 300 return INHERITED::onAccessBitmap(); | 298 return fLegacyBitmap; |
| 301 } | 299 } |
| 302 | 300 |
| 303 void SkGpuDevice::onAttachToCanvas(SkCanvas* canvas) { | 301 void SkGpuDevice::onAttachToCanvas(SkCanvas* canvas) { |
| 304 INHERITED::onAttachToCanvas(canvas); | 302 INHERITED::onAttachToCanvas(canvas); |
| 305 | 303 |
| 306 // Canvas promises that this ptr is valid until onDetachFromCanvas is called | 304 // Canvas promises that this ptr is valid until onDetachFromCanvas is called |
| 307 fClipData.fClipStack = canvas->getClipStack(); | 305 fClipData.fClipStack = canvas->getClipStack(); |
| 308 } | 306 } |
| 309 | 307 |
| 310 void SkGpuDevice::onDetachFromCanvas() { | 308 void SkGpuDevice::onDetachFromCanvas() { |
| (...skipping 1685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1996 picture->fPlayback->setReplacements(NULL); | 1994 picture->fPlayback->setReplacements(NULL); |
| 1997 | 1995 |
| 1998 // unlock the layers | 1996 // unlock the layers |
| 1999 for (int i = 0; i < gpuData->numSaveLayers(); ++i) { | 1997 for (int i = 0; i < gpuData->numSaveLayers(); ++i) { |
| 2000 GrCachedLayer* layer = fContext->getLayerCache()->findLayer(picture, i); | 1998 GrCachedLayer* layer = fContext->getLayerCache()->findLayer(picture, i); |
| 2001 fContext->getLayerCache()->unlock(layer); | 1999 fContext->getLayerCache()->unlock(layer); |
| 2002 } | 2000 } |
| 2003 | 2001 |
| 2004 return true; | 2002 return true; |
| 2005 } | 2003 } |
| OLD | NEW |