| 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 "GrBlurUtils.h" | 10 #include "GrBlurUtils.h" |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 } | 149 } |
| 150 unsigned flags; | 150 unsigned flags; |
| 151 if (!CheckAlphaTypeAndGetFlags(nullptr, init, &flags)) { | 151 if (!CheckAlphaTypeAndGetFlags(nullptr, init, &flags)) { |
| 152 return nullptr; | 152 return nullptr; |
| 153 } | 153 } |
| 154 return new SkGpuDevice(rt, width, height, props, flags); | 154 return new SkGpuDevice(rt, width, height, props, flags); |
| 155 } | 155 } |
| 156 | 156 |
| 157 SkGpuDevice* SkGpuDevice::Create(GrContext* context, SkSurface::Budgeted budgete
d, | 157 SkGpuDevice* SkGpuDevice::Create(GrContext* context, SkSurface::Budgeted budgete
d, |
| 158 const SkImageInfo& info, int sampleCount, | 158 const SkImageInfo& info, int sampleCount, |
| 159 const SkSurfaceProps* props, InitContents init)
{ | 159 const SkSurfaceProps* props, InitContents init, |
| 160 TextureStorageAllocator* customAllocator) { |
| 160 unsigned flags; | 161 unsigned flags; |
| 161 if (!CheckAlphaTypeAndGetFlags(&info, init, &flags)) { | 162 if (!CheckAlphaTypeAndGetFlags(&info, init, &flags)) { |
| 162 return nullptr; | 163 return nullptr; |
| 163 } | 164 } |
| 164 | 165 |
| 165 SkAutoTUnref<GrRenderTarget> rt(CreateRenderTarget(context, budgeted, info,
sampleCount)); | 166 SkAutoTUnref<GrRenderTarget> rt(CreateRenderTarget( |
| 167 context, budgeted, info, sampleCount, customAllocator)); |
| 166 if (nullptr == rt) { | 168 if (nullptr == rt) { |
| 167 return nullptr; | 169 return nullptr; |
| 168 } | 170 } |
| 169 | 171 |
| 170 return new SkGpuDevice(rt, info.width(), info.height(), props, flags); | 172 return new SkGpuDevice(rt, info.width(), info.height(), props, flags); |
| 171 } | 173 } |
| 172 | 174 |
| 173 SkGpuDevice::SkGpuDevice(GrRenderTarget* rt, int width, int height, | 175 SkGpuDevice::SkGpuDevice(GrRenderTarget* rt, int width, int height, |
| 174 const SkSurfaceProps* props, unsigned flags) | 176 const SkSurfaceProps* props, unsigned flags) |
| 175 : INHERITED(SkSurfacePropsCopyOrDefault(props)) | 177 : INHERITED(SkSurfacePropsCopyOrDefault(props)) |
| 176 , fContext(SkRef(rt->getContext())) | 178 , fContext(SkRef(rt->getContext())) |
| 177 , fRenderTarget(SkRef(rt)) { | 179 , fRenderTarget(SkRef(rt)) { |
| 178 fNeedClear = SkToBool(flags & kNeedClear_Flag); | 180 fNeedClear = SkToBool(flags & kNeedClear_Flag); |
| 179 fOpaque = SkToBool(flags & kIsOpaque_Flag); | 181 fOpaque = SkToBool(flags & kIsOpaque_Flag); |
| 180 | 182 |
| 181 SkAlphaType at = fOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType; | 183 SkAlphaType at = fOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType; |
| 182 SkImageInfo info = rt->surfacePriv().info(at).makeWH(width, height); | 184 SkImageInfo info = rt->surfacePriv().info(at).makeWH(width, height); |
| 183 SkPixelRef* pr = new SkGrPixelRef(info, rt); | 185 SkPixelRef* pr = new SkGrPixelRef(info, rt); |
| 184 fLegacyBitmap.setInfo(info); | 186 fLegacyBitmap.setInfo(info); |
| 185 fLegacyBitmap.setPixelRef(pr)->unref(); | 187 fLegacyBitmap.setPixelRef(pr)->unref(); |
| 186 | 188 |
| 187 fDrawContext.reset(this->context()->drawContext(rt, &this->surfaceProps())); | 189 fDrawContext.reset(this->context()->drawContext(rt, &this->surfaceProps())); |
| 188 } | 190 } |
| 189 | 191 |
| 190 GrRenderTarget* SkGpuDevice::CreateRenderTarget(GrContext* context, SkSurface::B
udgeted budgeted, | 192 GrRenderTarget* SkGpuDevice::CreateRenderTarget(GrContext* context, SkSurface::B
udgeted budgeted, |
| 191 const SkImageInfo& origInfo, int
sampleCount) { | 193 const SkImageInfo& origInfo, int
sampleCount, |
| 194 TextureStorageAllocator* texture
StorageAllocator) { |
| 192 if (kUnknown_SkColorType == origInfo.colorType() || | 195 if (kUnknown_SkColorType == origInfo.colorType() || |
| 193 origInfo.width() < 0 || origInfo.height() < 0) { | 196 origInfo.width() < 0 || origInfo.height() < 0) { |
| 194 return nullptr; | 197 return nullptr; |
| 195 } | 198 } |
| 196 | 199 |
| 197 if (!context) { | 200 if (!context) { |
| 198 return nullptr; | 201 return nullptr; |
| 199 } | 202 } |
| 200 | 203 |
| 201 SkColorType ct = origInfo.colorType(); | 204 SkColorType ct = origInfo.colorType(); |
| 202 SkAlphaType at = origInfo.alphaType(); | 205 SkAlphaType at = origInfo.alphaType(); |
| 203 if (kRGB_565_SkColorType == ct) { | 206 if (kRGB_565_SkColorType == ct) { |
| 204 at = kOpaque_SkAlphaType; // force this setting | 207 at = kOpaque_SkAlphaType; // force this setting |
| 205 } else if (ct != kBGRA_8888_SkColorType && ct != kRGBA_8888_SkColorType) { | 208 } else if (ct != kBGRA_8888_SkColorType && ct != kRGBA_8888_SkColorType) { |
| 206 // Fall back from whatever ct was to default of kRGBA or kBGRA which is
aliased as kN32 | 209 // Fall back from whatever ct was to default of kRGBA or kBGRA which is
aliased as kN32 |
| 207 ct = kN32_SkColorType; | 210 ct = kN32_SkColorType; |
| 208 } | 211 } |
| 209 if (kOpaque_SkAlphaType != at) { | 212 if (kOpaque_SkAlphaType != at) { |
| 210 at = kPremul_SkAlphaType; // force this setting | 213 at = kPremul_SkAlphaType; // force this setting |
| 211 } | 214 } |
| 212 const SkImageInfo info = SkImageInfo::Make(origInfo.width(), origInfo.height
(), ct, at); | 215 const SkImageInfo info = SkImageInfo::Make(origInfo.width(), origInfo.height
(), ct, at); |
| 213 | 216 |
| 214 GrSurfaceDesc desc; | 217 GrSurfaceDesc desc; |
| 215 desc.fFlags = kRenderTarget_GrSurfaceFlag; | 218 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 216 desc.fWidth = info.width(); | 219 desc.fWidth = info.width(); |
| 217 desc.fHeight = info.height(); | 220 desc.fHeight = info.height(); |
| 218 desc.fConfig = SkImageInfo2GrPixelConfig(info); | 221 desc.fConfig = SkImageInfo2GrPixelConfig(info); |
| 219 desc.fSampleCnt = sampleCount; | 222 desc.fSampleCnt = sampleCount; |
| 223 desc.fTextureStorageAllocator = textureStorageAllocator; |
| 220 GrTexture* texture = context->textureProvider()->createTexture( | 224 GrTexture* texture = context->textureProvider()->createTexture( |
| 221 desc, SkToBool(budgeted), nullptr, 0); | 225 desc, SkToBool(budgeted), nullptr, 0); |
| 222 if (nullptr == texture) { | 226 if (nullptr == texture) { |
| 223 return nullptr; | 227 return nullptr; |
| 224 } | 228 } |
| 225 SkASSERT(nullptr != texture->asRenderTarget()); | 229 SkASSERT(nullptr != texture->asRenderTarget()); |
| 226 return texture->asRenderTarget(); | 230 return texture->asRenderTarget(); |
| 227 } | 231 } |
| 228 | 232 |
| 229 /////////////////////////////////////////////////////////////////////////////// | 233 /////////////////////////////////////////////////////////////////////////////// |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 void SkGpuDevice::replaceRenderTarget(bool shouldRetainContent) { | 333 void SkGpuDevice::replaceRenderTarget(bool shouldRetainContent) { |
| 330 ASSERT_SINGLE_OWNER | 334 ASSERT_SINGLE_OWNER |
| 331 // Caller must have accessed the render target, because it knows the rt must
be replaced. | 335 // Caller must have accessed the render target, because it knows the rt must
be replaced. |
| 332 SkASSERT(!fNeedClear); | 336 SkASSERT(!fNeedClear); |
| 333 | 337 |
| 334 SkSurface::Budgeted budgeted = | 338 SkSurface::Budgeted budgeted = |
| 335 fRenderTarget->resourcePriv().isBudgeted() ? SkSurface::kYes_Budgete
d | 339 fRenderTarget->resourcePriv().isBudgeted() ? SkSurface::kYes_Budgete
d |
| 336 : SkSurface::kNo_Budgeted
; | 340 : SkSurface::kNo_Budgeted
; |
| 337 | 341 |
| 338 SkAutoTUnref<GrRenderTarget> newRT(CreateRenderTarget( | 342 SkAutoTUnref<GrRenderTarget> newRT(CreateRenderTarget( |
| 339 this->context(), budgeted, this->imageInfo(), fRenderTarget->desc().fSam
pleCnt)); | 343 this->context(), budgeted, this->imageInfo(), fRenderTarget->desc().fSam
pleCnt, |
| 344 fRenderTarget->desc().fTextureStorageAllocator)); |
| 340 | 345 |
| 341 if (nullptr == newRT) { | 346 if (nullptr == newRT) { |
| 342 return; | 347 return; |
| 343 } | 348 } |
| 344 | 349 |
| 345 if (shouldRetainContent) { | 350 if (shouldRetainContent) { |
| 346 if (fRenderTarget->wasDestroyed()) { | 351 if (fRenderTarget->wasDestroyed()) { |
| 347 return; | 352 return; |
| 348 } | 353 } |
| 349 this->context()->copySurface(newRT, fRenderTarget); | 354 this->context()->copySurface(newRT, fRenderTarget); |
| (...skipping 1131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1481 fRenderTarget->isUnifiedMultisampled(); | 1486 fRenderTarget->isUnifiedMultisampled(); |
| 1482 bool doBicubic; | 1487 bool doBicubic; |
| 1483 GrTextureParams::FilterMode textureFilterMode = | 1488 GrTextureParams::FilterMode textureFilterMode = |
| 1484 GrSkFilterQualityToGrFilterMode(paint.getFilterQuality(), *draw.fMatrix,
SkMatrix::I(), | 1489 GrSkFilterQualityToGrFilterMode(paint.getFilterQuality(), *draw.fMatrix,
SkMatrix::I(), |
| 1485 &doBicubic); | 1490 &doBicubic); |
| 1486 if (useFallback || doBicubic || GrTextureParams::kNone_FilterMode != texture
FilterMode) { | 1491 if (useFallback || doBicubic || GrTextureParams::kNone_FilterMode != texture
FilterMode) { |
| 1487 SkNinePatchIter iter(producer->width(), producer->height(), center, dst)
; | 1492 SkNinePatchIter iter(producer->width(), producer->height(), center, dst)
; |
| 1488 | 1493 |
| 1489 SkRect srcR, dstR; | 1494 SkRect srcR, dstR; |
| 1490 while (iter.next(&srcR, &dstR)) { | 1495 while (iter.next(&srcR, &dstR)) { |
| 1491 this->drawTextureProducer(producer, &srcR, &dstR, SkCanvas::kStrict_
SrcRectConstraint, | 1496 this->drawTextureProducer(producer, &srcR, &dstR, SkCanvas::kStrict_
SrcRectConstraint, |
| 1492 *draw.fMatrix, fClip, paint); | 1497 *draw.fMatrix, fClip, paint); |
| 1493 } | 1498 } |
| 1494 return; | 1499 return; |
| 1495 } | 1500 } |
| 1496 | 1501 |
| 1497 static const GrTextureParams::FilterMode kMode = GrTextureParams::kNone_Filt
erMode; | 1502 static const GrTextureParams::FilterMode kMode = GrTextureParams::kNone_Filt
erMode; |
| 1498 SkAutoTUnref<const GrFragmentProcessor> fp( | 1503 SkAutoTUnref<const GrFragmentProcessor> fp( |
| 1499 producer->createFragmentProcessor(SkMatrix::I(), | 1504 producer->createFragmentProcessor(SkMatrix::I(), |
| 1500 SkRect::MakeIWH(producer->width(), pro
ducer->height()), | 1505 SkRect::MakeIWH(producer->width(), pro
ducer->height()), |
| 1501 GrTextureProducer::kNo_FilterConstrain
t, true, | 1506 GrTextureProducer::kNo_FilterConstrain
t, true, |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1900 } | 1905 } |
| 1901 | 1906 |
| 1902 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { | 1907 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { |
| 1903 ASSERT_SINGLE_OWNER | 1908 ASSERT_SINGLE_OWNER |
| 1904 // We always return a transient cache, so it is freed after each | 1909 // We always return a transient cache, so it is freed after each |
| 1905 // filter traversal. | 1910 // filter traversal. |
| 1906 return SkGpuDevice::NewImageFilterCache(); | 1911 return SkGpuDevice::NewImageFilterCache(); |
| 1907 } | 1912 } |
| 1908 | 1913 |
| 1909 #endif | 1914 #endif |
| OLD | NEW |