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