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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 static SkBitmap make_bitmap(GrContext* context, GrRenderTarget* renderTarget) { | 151 static SkBitmap make_bitmap(GrContext* context, GrRenderTarget* renderTarget) { |
| 152 bool isOpaque; | 152 bool isOpaque; |
| 153 SkBitmap::Config config = grConfig2skConfig(renderTarget->config(), &isOpaqu e); | 153 SkBitmap::Config config = grConfig2skConfig(renderTarget->config(), &isOpaqu e); |
| 154 | 154 |
| 155 SkBitmap bitmap; | 155 SkBitmap bitmap; |
| 156 bitmap.setConfig(config, renderTarget->width(), renderTarget->height(), 0, | 156 bitmap.setConfig(config, renderTarget->width(), renderTarget->height(), 0, |
| 157 isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); | 157 isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); |
| 158 return bitmap; | 158 return bitmap; |
| 159 } | 159 } |
| 160 | 160 |
| 161 SkGpuDevice* SkGpuDevice::Create(GrSurface* surface) { | 161 SkGpuDevice* SkGpuDevice::Create(GrSurface* surface, unsigned flags) { |
| 162 SkASSERT(NULL != surface); | 162 SkASSERT(NULL != surface); |
| 163 if (NULL == surface->asRenderTarget() || NULL == surface->getContext()) { | 163 if (NULL == surface->asRenderTarget() || NULL == surface->getContext()) { |
| 164 return NULL; | 164 return NULL; |
| 165 } | 165 } |
| 166 if (surface->asTexture()) { | 166 if (surface->asTexture()) { |
| 167 return SkNEW_ARGS(SkGpuDevice, (surface->getContext(), surface->asTextur e())); | 167 return SkNEW_ARGS(SkGpuDevice, (surface->getContext(), surface->asTextur e(), flags)); |
| 168 } else { | 168 } else { |
| 169 return SkNEW_ARGS(SkGpuDevice, (surface->getContext(), surface->asRender Target())); | 169 return SkNEW_ARGS(SkGpuDevice, (surface->getContext(), surface->asRender Target(), flags)); |
| 170 } | 170 } |
| 171 } | 171 } |
| 172 | 172 |
| 173 SkGpuDevice::SkGpuDevice(GrContext* context, GrTexture* texture) | 173 SkGpuDevice::SkGpuDevice(GrContext* context, GrTexture* texture, unsigned flags) |
| 174 : SkBitmapDevice(make_bitmap(context, texture->asRenderTarget())) { | 174 : SkBitmapDevice(make_bitmap(context, texture->asRenderTarget())) { |
| 175 this->initFromRenderTarget(context, texture->asRenderTarget(), false); | 175 this->initFromRenderTarget(context, texture->asRenderTarget(), flags); |
| 176 } | 176 } |
| 177 | 177 |
| 178 SkGpuDevice::SkGpuDevice(GrContext* context, GrRenderTarget* renderTarget) | 178 SkGpuDevice::SkGpuDevice(GrContext* context, GrRenderTarget* renderTarget, unsig ned flags) |
| 179 : SkBitmapDevice(make_bitmap(context, renderTarget)) { | 179 : SkBitmapDevice(make_bitmap(context, renderTarget)) { |
| 180 this->initFromRenderTarget(context, renderTarget, false); | 180 this->initFromRenderTarget(context, renderTarget, flags); |
| 181 } | 181 } |
| 182 | 182 |
| 183 void SkGpuDevice::initFromRenderTarget(GrContext* context, | 183 void SkGpuDevice::initFromRenderTarget(GrContext* context, |
| 184 GrRenderTarget* renderTarget, | 184 GrRenderTarget* renderTarget, |
| 185 bool cached) { | 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)); | 191 fMainTextContext = SkNEW_ARGS(GrDistanceFieldTextContext, (fContext, fLeakyP roperties)); |
| 192 fFallbackTextContext = SkNEW_ARGS(GrBitmapTextContext, (fContext, fLeakyProp erties)); | 192 fFallbackTextContext = SkNEW_ARGS(GrBitmapTextContext, (fContext, fLeakyProp erties)); |
| 193 | 193 |
| 194 fRenderTarget = NULL; | 194 fRenderTarget = NULL; |
| 195 fNeedClear = false; | 195 fNeedClear = flags & kNeedClear_Flag; |
| 196 | 196 |
| 197 SkASSERT(NULL != renderTarget); | 197 SkASSERT(NULL != renderTarget); |
| 198 fRenderTarget = renderTarget; | 198 fRenderTarget = renderTarget; |
| 199 fRenderTarget->ref(); | 199 fRenderTarget->ref(); |
| 200 | 200 |
| 201 // 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 |
| 202 // on the RT but not vice-versa. | 202 // on the RT but not vice-versa. |
| 203 // 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 |
| 204 // busting chrome (for a currently unknown reason). | 204 // busting chrome (for a currently unknown reason). |
| 205 GrSurface* surface = fRenderTarget->asTexture(); | 205 GrSurface* surface = fRenderTarget->asTexture(); |
| 206 if (NULL == surface) { | 206 if (NULL == surface) { |
| 207 surface = fRenderTarget; | 207 surface = fRenderTarget; |
| 208 } | 208 } |
| 209 | 209 |
| 210 SkImageInfo info; | 210 SkImageInfo info; |
| 211 surface->asImageInfo(&info); | 211 surface->asImageInfo(&info); |
| 212 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (info, surface, cached)); | 212 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (info, surface, flags & kCached_Fl ag)); |
|
bungeman-skia
2014/03/19 23:23:26
This is causing the Windows bots to fail about con
| |
| 213 | 213 |
| 214 this->setPixelRef(pr)->unref(); | 214 this->setPixelRef(pr)->unref(); |
| 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 } |
| (...skipping 1736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1959 SkBaseDevice* SkGpuDevice::onCreateDevice(const SkImageInfo& info, Usage usage) { | 1959 SkBaseDevice* SkGpuDevice::onCreateDevice(const SkImageInfo& info, Usage usage) { |
| 1960 GrTextureDesc desc; | 1960 GrTextureDesc desc; |
| 1961 desc.fConfig = fRenderTarget->config(); | 1961 desc.fConfig = fRenderTarget->config(); |
| 1962 desc.fFlags = kRenderTarget_GrTextureFlagBit; | 1962 desc.fFlags = kRenderTarget_GrTextureFlagBit; |
| 1963 desc.fWidth = info.width(); | 1963 desc.fWidth = info.width(); |
| 1964 desc.fHeight = info.height(); | 1964 desc.fHeight = info.height(); |
| 1965 desc.fSampleCnt = fRenderTarget->numSamples(); | 1965 desc.fSampleCnt = fRenderTarget->numSamples(); |
| 1966 | 1966 |
| 1967 SkAutoTUnref<GrTexture> texture; | 1967 SkAutoTUnref<GrTexture> texture; |
| 1968 // Skia's convention is to only clear a device if it is non-opaque. | 1968 // Skia's convention is to only clear a device if it is non-opaque. |
| 1969 bool needClear = !info.isOpaque(); | 1969 unsigned flags = info.isOpaque() ? 0 : kNeedClear_Flag; |
| 1970 | 1970 |
| 1971 #if CACHE_COMPATIBLE_DEVICE_TEXTURES | 1971 #if CACHE_COMPATIBLE_DEVICE_TEXTURES |
| 1972 // layers are never draw in repeat modes, so we can request an approx | 1972 // layers are never draw in repeat modes, so we can request an approx |
| 1973 // match and ignore any padding. | 1973 // match and ignore any padding. |
| 1974 flags |= kCached_Flag; | |
| 1974 const GrContext::ScratchTexMatch match = (kSaveLayer_Usage == usage) ? | 1975 const GrContext::ScratchTexMatch match = (kSaveLayer_Usage == usage) ? |
| 1975 GrContext::kApprox_ScratchTexMat ch : | 1976 GrContext::kApprox_ScratchTexMat ch : |
| 1976 GrContext::kExact_ScratchTexMatc h; | 1977 GrContext::kExact_ScratchTexMatc h; |
| 1977 texture.reset(fContext->lockAndRefScratchTexture(desc, match)); | 1978 texture.reset(fContext->lockAndRefScratchTexture(desc, match)); |
| 1978 #else | 1979 #else |
| 1979 texture.reset(fContext->createUncachedTexture(desc, NULL, 0)); | 1980 texture.reset(fContext->createUncachedTexture(desc, NULL, 0)); |
| 1980 #endif | 1981 #endif |
| 1981 if (NULL != texture.get()) { | 1982 if (NULL != texture.get()) { |
| 1982 return SkNEW_ARGS(SkGpuDevice,(fContext, texture, needClear)); | 1983 return SkGpuDevice::Create(texture, flags); |
| 1983 } else { | 1984 } else { |
| 1984 GrPrintf("---- failed to create compatible device texture [%d %d]\n", | 1985 GrPrintf("---- failed to create compatible device texture [%d %d]\n", |
| 1985 info.width(), info.height()); | 1986 info.width(), info.height()); |
| 1986 return NULL; | 1987 return NULL; |
| 1987 } | 1988 } |
| 1988 } | 1989 } |
| 1989 | 1990 |
| 1990 SkSurface* SkGpuDevice::newSurface(const SkImageInfo& info) { | 1991 SkSurface* SkGpuDevice::newSurface(const SkImageInfo& info) { |
| 1991 return SkSurface::NewRenderTarget(fContext, info, fRenderTarget->numSamples( )); | 1992 return SkSurface::NewRenderTarget(fContext, info, fRenderTarget->numSamples( )); |
| 1992 } | 1993 } |
| 1993 | 1994 |
| 1994 SkGpuDevice::SkGpuDevice(GrContext* context, | |
| 1995 GrTexture* texture, | |
| 1996 bool needClear) | |
| 1997 : SkBitmapDevice(make_bitmap(context, texture->asRenderTarget())) { | |
| 1998 | |
| 1999 SkASSERT(texture && texture->asRenderTarget()); | |
| 2000 // This constructor is called from onCreateDevice. It has locked the RT in t he texture | |
| 2001 // cache. We pass true for the third argument so that it will get unlocked. | |
| 2002 this->initFromRenderTarget(context, texture->asRenderTarget(), true); | |
| 2003 fNeedClear = needClear; | |
| 2004 } | |
| 2005 | |
| 2006 class GPUAccelData : public SkPicture::AccelData { | 1995 class GPUAccelData : public SkPicture::AccelData { |
| 2007 public: | 1996 public: |
| 2008 GPUAccelData(Key key) : INHERITED(key) { } | 1997 GPUAccelData(Key key) : INHERITED(key) { } |
| 2009 | 1998 |
| 2010 protected: | 1999 protected: |
| 2011 | 2000 |
| 2012 private: | 2001 private: |
| 2013 typedef SkPicture::AccelData INHERITED; | 2002 typedef SkPicture::AccelData INHERITED; |
| 2014 }; | 2003 }; |
| 2015 | 2004 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 2036 if (NULL == data) { | 2025 if (NULL == data) { |
| 2037 return false; | 2026 return false; |
| 2038 } | 2027 } |
| 2039 | 2028 |
| 2040 #if 0 | 2029 #if 0 |
| 2041 const GPUAccelData *gpuData = static_cast<const GPUAccelData*>(data); | 2030 const GPUAccelData *gpuData = static_cast<const GPUAccelData*>(data); |
| 2042 #endif | 2031 #endif |
| 2043 | 2032 |
| 2044 return false; | 2033 return false; |
| 2045 } | 2034 } |
| OLD | NEW |