| 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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 } | 142 } |
| 143 unsigned flags; | 143 unsigned flags; |
| 144 if (!CheckAlphaTypeAndGetFlags(nullptr, init, &flags)) { | 144 if (!CheckAlphaTypeAndGetFlags(nullptr, init, &flags)) { |
| 145 return nullptr; | 145 return nullptr; |
| 146 } | 146 } |
| 147 return new SkGpuDevice(rt, width, height, props, flags); | 147 return new SkGpuDevice(rt, width, height, props, flags); |
| 148 } | 148 } |
| 149 | 149 |
| 150 SkGpuDevice* SkGpuDevice::Create(GrContext* context, SkSurface::Budgeted budgete
d, | 150 SkGpuDevice* SkGpuDevice::Create(GrContext* context, SkSurface::Budgeted budgete
d, |
| 151 const SkImageInfo& info, int sampleCount, | 151 const SkImageInfo& info, int sampleCount, |
| 152 const SkSurfaceProps* props, InitContents init)
{ | 152 const SkSurfaceProps* props, InitContents init, |
| 153 GrTextureStorageAllocator customAllocator) { |
| 153 unsigned flags; | 154 unsigned flags; |
| 154 if (!CheckAlphaTypeAndGetFlags(&info, init, &flags)) { | 155 if (!CheckAlphaTypeAndGetFlags(&info, init, &flags)) { |
| 155 return nullptr; | 156 return nullptr; |
| 156 } | 157 } |
| 157 | 158 |
| 158 SkAutoTUnref<GrRenderTarget> rt(CreateRenderTarget(context, budgeted, info,
sampleCount)); | 159 SkAutoTUnref<GrRenderTarget> rt(CreateRenderTarget( |
| 160 context, budgeted, info, sampleCount, customAllocator)); |
| 159 if (nullptr == rt) { | 161 if (nullptr == rt) { |
| 160 return nullptr; | 162 return nullptr; |
| 161 } | 163 } |
| 162 | 164 |
| 163 return new SkGpuDevice(rt, info.width(), info.height(), props, flags); | 165 return new SkGpuDevice(rt, info.width(), info.height(), props, flags); |
| 164 } | 166 } |
| 165 | 167 |
| 166 SkGpuDevice::SkGpuDevice(GrRenderTarget* rt, int width, int height, | 168 SkGpuDevice::SkGpuDevice(GrRenderTarget* rt, int width, int height, |
| 167 const SkSurfaceProps* props, unsigned flags) | 169 const SkSurfaceProps* props, unsigned flags) |
| 168 : INHERITED(SkSurfacePropsCopyOrDefault(props)) | 170 : INHERITED(SkSurfacePropsCopyOrDefault(props)) |
| 169 , fContext(SkRef(rt->getContext())) | 171 , fContext(SkRef(rt->getContext())) |
| 170 , fRenderTarget(SkRef(rt)) { | 172 , fRenderTarget(SkRef(rt)) { |
| 171 fOpaque = SkToBool(flags & kIsOpaque_Flag); | 173 fOpaque = SkToBool(flags & kIsOpaque_Flag); |
| 172 | 174 |
| 173 SkAlphaType at = fOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType; | 175 SkAlphaType at = fOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType; |
| 174 SkImageInfo info = rt->surfacePriv().info(at).makeWH(width, height); | 176 SkImageInfo info = rt->surfacePriv().info(at).makeWH(width, height); |
| 175 SkPixelRef* pr = new SkGrPixelRef(info, rt); | 177 SkPixelRef* pr = new SkGrPixelRef(info, rt); |
| 176 fLegacyBitmap.setInfo(info); | 178 fLegacyBitmap.setInfo(info); |
| 177 fLegacyBitmap.setPixelRef(pr)->unref(); | 179 fLegacyBitmap.setPixelRef(pr)->unref(); |
| 178 | 180 |
| 179 fDrawContext.reset(this->context()->drawContext(rt, &this->surfaceProps())); | 181 fDrawContext.reset(this->context()->drawContext(rt, &this->surfaceProps())); |
| 180 if (flags & kNeedClear_Flag) { | 182 if (flags & kNeedClear_Flag) { |
| 181 this->clearAll(); | 183 this->clearAll(); |
| 182 } | 184 } |
| 183 } | 185 } |
| 184 | 186 |
| 185 GrRenderTarget* SkGpuDevice::CreateRenderTarget(GrContext* context, SkSurface::B
udgeted budgeted, | 187 GrRenderTarget* SkGpuDevice::CreateRenderTarget( |
| 186 const SkImageInfo& origInfo, int
sampleCount) { | 188 GrContext* context, SkSurface::Budgeted budgeted, const SkImageInfo& ori
gInfo, |
| 189 int sampleCount, GrTextureStorageAllocator textureStorageAllocator) { |
| 187 if (kUnknown_SkColorType == origInfo.colorType() || | 190 if (kUnknown_SkColorType == origInfo.colorType() || |
| 188 origInfo.width() < 0 || origInfo.height() < 0) { | 191 origInfo.width() < 0 || origInfo.height() < 0) { |
| 189 return nullptr; | 192 return nullptr; |
| 190 } | 193 } |
| 191 | 194 |
| 192 if (!context) { | 195 if (!context) { |
| 193 return nullptr; | 196 return nullptr; |
| 194 } | 197 } |
| 195 | 198 |
| 196 SkColorType ct = origInfo.colorType(); | 199 SkColorType ct = origInfo.colorType(); |
| 197 SkAlphaType at = origInfo.alphaType(); | 200 SkAlphaType at = origInfo.alphaType(); |
| 198 if (kRGB_565_SkColorType == ct) { | 201 if (kRGB_565_SkColorType == ct) { |
| 199 at = kOpaque_SkAlphaType; // force this setting | 202 at = kOpaque_SkAlphaType; // force this setting |
| 200 } else if (ct != kBGRA_8888_SkColorType && ct != kRGBA_8888_SkColorType) { | 203 } else if (ct != kBGRA_8888_SkColorType && ct != kRGBA_8888_SkColorType) { |
| 201 // Fall back from whatever ct was to default of kRGBA or kBGRA which is
aliased as kN32 | 204 // Fall back from whatever ct was to default of kRGBA or kBGRA which is
aliased as kN32 |
| 202 ct = kN32_SkColorType; | 205 ct = kN32_SkColorType; |
| 203 } | 206 } |
| 204 if (kOpaque_SkAlphaType != at) { | 207 if (kOpaque_SkAlphaType != at) { |
| 205 at = kPremul_SkAlphaType; // force this setting | 208 at = kPremul_SkAlphaType; // force this setting |
| 206 } | 209 } |
| 207 const SkImageInfo info = SkImageInfo::Make(origInfo.width(), origInfo.height
(), ct, at); | 210 const SkImageInfo info = SkImageInfo::Make(origInfo.width(), origInfo.height
(), ct, at); |
| 208 | 211 |
| 209 GrSurfaceDesc desc; | 212 GrSurfaceDesc desc; |
| 210 desc.fFlags = kRenderTarget_GrSurfaceFlag; | 213 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 211 desc.fWidth = info.width(); | 214 desc.fWidth = info.width(); |
| 212 desc.fHeight = info.height(); | 215 desc.fHeight = info.height(); |
| 213 desc.fConfig = SkImageInfo2GrPixelConfig(info); | 216 desc.fConfig = SkImageInfo2GrPixelConfig(info); |
| 214 desc.fSampleCnt = sampleCount; | 217 desc.fSampleCnt = sampleCount; |
| 218 desc.fTextureStorageAllocator = textureStorageAllocator; |
| 215 GrTexture* texture = context->textureProvider()->createTexture( | 219 GrTexture* texture = context->textureProvider()->createTexture( |
| 216 desc, SkToBool(budgeted), nullptr, 0); | 220 desc, SkToBool(budgeted), nullptr, 0); |
| 217 if (nullptr == texture) { | 221 if (nullptr == texture) { |
| 218 return nullptr; | 222 return nullptr; |
| 219 } | 223 } |
| 220 SkASSERT(nullptr != texture->asRenderTarget()); | 224 SkASSERT(nullptr != texture->asRenderTarget()); |
| 221 return texture->asRenderTarget(); | 225 return texture->asRenderTarget(); |
| 222 } | 226 } |
| 223 | 227 |
| 224 /////////////////////////////////////////////////////////////////////////////// | 228 /////////////////////////////////////////////////////////////////////////////// |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 } | 319 } |
| 316 | 320 |
| 317 void SkGpuDevice::replaceRenderTarget(bool shouldRetainContent) { | 321 void SkGpuDevice::replaceRenderTarget(bool shouldRetainContent) { |
| 318 ASSERT_SINGLE_OWNER | 322 ASSERT_SINGLE_OWNER |
| 319 | 323 |
| 320 SkSurface::Budgeted budgeted = | 324 SkSurface::Budgeted budgeted = |
| 321 fRenderTarget->resourcePriv().isBudgeted() ? SkSurface::kYes_Budgete
d | 325 fRenderTarget->resourcePriv().isBudgeted() ? SkSurface::kYes_Budgete
d |
| 322 : SkSurface::kNo_Budgeted
; | 326 : SkSurface::kNo_Budgeted
; |
| 323 | 327 |
| 324 SkAutoTUnref<GrRenderTarget> newRT(CreateRenderTarget( | 328 SkAutoTUnref<GrRenderTarget> newRT(CreateRenderTarget( |
| 325 this->context(), budgeted, this->imageInfo(), fRenderTarget->desc().fSam
pleCnt)); | 329 this->context(), budgeted, this->imageInfo(), fRenderTarget->desc().fSam
pleCnt, |
| 330 fRenderTarget->desc().fTextureStorageAllocator)); |
| 326 | 331 |
| 327 if (nullptr == newRT) { | 332 if (nullptr == newRT) { |
| 328 return; | 333 return; |
| 329 } | 334 } |
| 330 | 335 |
| 331 if (shouldRetainContent) { | 336 if (shouldRetainContent) { |
| 332 if (fRenderTarget->wasDestroyed()) { | 337 if (fRenderTarget->wasDestroyed()) { |
| 333 return; | 338 return; |
| 334 } | 339 } |
| 335 this->context()->copySurface(newRT, fRenderTarget); | 340 this->context()->copySurface(newRT, fRenderTarget); |
| (...skipping 1131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1467 fRenderTarget->isUnifiedMultisampled(); | 1472 fRenderTarget->isUnifiedMultisampled(); |
| 1468 bool doBicubic; | 1473 bool doBicubic; |
| 1469 GrTextureParams::FilterMode textureFilterMode = | 1474 GrTextureParams::FilterMode textureFilterMode = |
| 1470 GrSkFilterQualityToGrFilterMode(paint.getFilterQuality(), *draw.fMatrix,
SkMatrix::I(), | 1475 GrSkFilterQualityToGrFilterMode(paint.getFilterQuality(), *draw.fMatrix,
SkMatrix::I(), |
| 1471 &doBicubic); | 1476 &doBicubic); |
| 1472 if (useFallback || doBicubic || GrTextureParams::kNone_FilterMode != texture
FilterMode) { | 1477 if (useFallback || doBicubic || GrTextureParams::kNone_FilterMode != texture
FilterMode) { |
| 1473 SkNinePatchIter iter(producer->width(), producer->height(), center, dst)
; | 1478 SkNinePatchIter iter(producer->width(), producer->height(), center, dst)
; |
| 1474 | 1479 |
| 1475 SkRect srcR, dstR; | 1480 SkRect srcR, dstR; |
| 1476 while (iter.next(&srcR, &dstR)) { | 1481 while (iter.next(&srcR, &dstR)) { |
| 1477 this->drawTextureProducer(producer, &srcR, &dstR, SkCanvas::kStrict_
SrcRectConstraint, | 1482 this->drawTextureProducer(producer, &srcR, &dstR, SkCanvas::kStrict_
SrcRectConstraint, |
| 1478 *draw.fMatrix, fClip, paint); | 1483 *draw.fMatrix, fClip, paint); |
| 1479 } | 1484 } |
| 1480 return; | 1485 return; |
| 1481 } | 1486 } |
| 1482 | 1487 |
| 1483 static const GrTextureParams::FilterMode kMode = GrTextureParams::kNone_Filt
erMode; | 1488 static const GrTextureParams::FilterMode kMode = GrTextureParams::kNone_Filt
erMode; |
| 1484 SkAutoTUnref<const GrFragmentProcessor> fp( | 1489 SkAutoTUnref<const GrFragmentProcessor> fp( |
| 1485 producer->createFragmentProcessor(SkMatrix::I(), | 1490 producer->createFragmentProcessor(SkMatrix::I(), |
| 1486 SkRect::MakeIWH(producer->width(), pro
ducer->height()), | 1491 SkRect::MakeIWH(producer->width(), pro
ducer->height()), |
| 1487 GrTextureProducer::kNo_FilterConstrain
t, true, | 1492 GrTextureProducer::kNo_FilterConstrain
t, true, |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1885 } | 1890 } |
| 1886 | 1891 |
| 1887 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { | 1892 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { |
| 1888 ASSERT_SINGLE_OWNER | 1893 ASSERT_SINGLE_OWNER |
| 1889 // We always return a transient cache, so it is freed after each | 1894 // We always return a transient cache, so it is freed after each |
| 1890 // filter traversal. | 1895 // filter traversal. |
| 1891 return SkGpuDevice::NewImageFilterCache(); | 1896 return SkGpuDevice::NewImageFilterCache(); |
| 1892 } | 1897 } |
| 1893 | 1898 |
| 1894 #endif | 1899 #endif |
| OLD | NEW |