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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 if (!rt || rt->wasDestroyed()) { | 140 if (!rt || rt->wasDestroyed()) { |
141 return nullptr; | 141 return nullptr; |
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, SkBudgeted budgeted, | 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 GrTextureStorageAllocator customAllocator) { |
154 unsigned flags; | 154 unsigned flags; |
155 if (!CheckAlphaTypeAndGetFlags(&info, init, &flags)) { | 155 if (!CheckAlphaTypeAndGetFlags(&info, init, &flags)) { |
156 return nullptr; | 156 return nullptr; |
157 } | 157 } |
158 | 158 |
159 SkAutoTUnref<GrRenderTarget> rt(CreateRenderTarget( | 159 SkAutoTUnref<GrRenderTarget> rt(CreateRenderTarget( |
160 context, budgeted, info, sampleCount, customAllocator)); | 160 context, budgeted, info, sampleCount, customAllocator)); |
(...skipping 17 matching lines...) Expand all Loading... |
178 fLegacyBitmap.setInfo(info); | 178 fLegacyBitmap.setInfo(info); |
179 fLegacyBitmap.setPixelRef(pr)->unref(); | 179 fLegacyBitmap.setPixelRef(pr)->unref(); |
180 | 180 |
181 fDrawContext.reset(this->context()->drawContext(rt, &this->surfaceProps())); | 181 fDrawContext.reset(this->context()->drawContext(rt, &this->surfaceProps())); |
182 if (flags & kNeedClear_Flag) { | 182 if (flags & kNeedClear_Flag) { |
183 this->clearAll(); | 183 this->clearAll(); |
184 } | 184 } |
185 } | 185 } |
186 | 186 |
187 GrRenderTarget* SkGpuDevice::CreateRenderTarget( | 187 GrRenderTarget* SkGpuDevice::CreateRenderTarget( |
188 GrContext* context, SkBudgeted budgeted, const SkImageInfo& origInfo, | 188 GrContext* context, SkSurface::Budgeted budgeted, const SkImageInfo& ori
gInfo, |
189 int sampleCount, GrTextureStorageAllocator textureStorageAllocator) { | 189 int sampleCount, GrTextureStorageAllocator textureStorageAllocator) { |
190 if (kUnknown_SkColorType == origInfo.colorType() || | 190 if (kUnknown_SkColorType == origInfo.colorType() || |
191 origInfo.width() < 0 || origInfo.height() < 0) { | 191 origInfo.width() < 0 || origInfo.height() < 0) { |
192 return nullptr; | 192 return nullptr; |
193 } | 193 } |
194 | 194 |
195 if (!context) { | 195 if (!context) { |
196 return nullptr; | 196 return nullptr; |
197 } | 197 } |
198 | 198 |
(...skipping 10 matching lines...) Expand all Loading... |
209 } | 209 } |
210 const SkImageInfo info = SkImageInfo::Make(origInfo.width(), origInfo.height
(), ct, at); | 210 const SkImageInfo info = SkImageInfo::Make(origInfo.width(), origInfo.height
(), ct, at); |
211 | 211 |
212 GrSurfaceDesc desc; | 212 GrSurfaceDesc desc; |
213 desc.fFlags = kRenderTarget_GrSurfaceFlag; | 213 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
214 desc.fWidth = info.width(); | 214 desc.fWidth = info.width(); |
215 desc.fHeight = info.height(); | 215 desc.fHeight = info.height(); |
216 desc.fConfig = SkImageInfo2GrPixelConfig(info); | 216 desc.fConfig = SkImageInfo2GrPixelConfig(info); |
217 desc.fSampleCnt = sampleCount; | 217 desc.fSampleCnt = sampleCount; |
218 desc.fTextureStorageAllocator = textureStorageAllocator; | 218 desc.fTextureStorageAllocator = textureStorageAllocator; |
219 GrTexture* texture = context->textureProvider()->createTexture(desc, budgete
d, nullptr, 0); | 219 GrTexture* texture = context->textureProvider()->createTexture( |
| 220 desc, SkToBool(budgeted), nullptr, 0); |
220 if (nullptr == texture) { | 221 if (nullptr == texture) { |
221 return nullptr; | 222 return nullptr; |
222 } | 223 } |
223 SkASSERT(nullptr != texture->asRenderTarget()); | 224 SkASSERT(nullptr != texture->asRenderTarget()); |
224 return texture->asRenderTarget(); | 225 return texture->asRenderTarget(); |
225 } | 226 } |
226 | 227 |
227 /////////////////////////////////////////////////////////////////////////////// | 228 /////////////////////////////////////////////////////////////////////////////// |
228 | 229 |
229 bool SkGpuDevice::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size
_t dstRowBytes, | 230 bool SkGpuDevice::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size
_t dstRowBytes, |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 ASSERT_SINGLE_OWNER | 314 ASSERT_SINGLE_OWNER |
314 GrColor color = 0; | 315 GrColor color = 0; |
315 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "clearAll", fContext); | 316 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "clearAll", fContext); |
316 SkIRect rect = SkIRect::MakeWH(this->width(), this->height()); | 317 SkIRect rect = SkIRect::MakeWH(this->width(), this->height()); |
317 fDrawContext->clear(&rect, color, true); | 318 fDrawContext->clear(&rect, color, true); |
318 } | 319 } |
319 | 320 |
320 void SkGpuDevice::replaceRenderTarget(bool shouldRetainContent) { | 321 void SkGpuDevice::replaceRenderTarget(bool shouldRetainContent) { |
321 ASSERT_SINGLE_OWNER | 322 ASSERT_SINGLE_OWNER |
322 | 323 |
323 SkBudgeted budgeted = fRenderTarget->resourcePriv().isBudgeted(); | 324 SkSurface::Budgeted budgeted = |
| 325 fRenderTarget->resourcePriv().isBudgeted() ? SkSurface::kYes_Budgete
d |
| 326 : SkSurface::kNo_Budgeted
; |
324 | 327 |
325 SkAutoTUnref<GrRenderTarget> newRT(CreateRenderTarget( | 328 SkAutoTUnref<GrRenderTarget> newRT(CreateRenderTarget( |
326 this->context(), budgeted, this->imageInfo(), fRenderTarget->desc().fSam
pleCnt, | 329 this->context(), budgeted, this->imageInfo(), fRenderTarget->desc().fSam
pleCnt, |
327 fRenderTarget->desc().fTextureStorageAllocator)); | 330 fRenderTarget->desc().fTextureStorageAllocator)); |
328 | 331 |
329 if (nullptr == newRT) { | 332 if (nullptr == newRT) { |
330 return; | 333 return; |
331 } | 334 } |
332 | 335 |
333 if (shouldRetainContent) { | 336 if (shouldRetainContent) { |
(...skipping 1440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1774 | 1777 |
1775 SkAutoTUnref<GrTexture> texture; | 1778 SkAutoTUnref<GrTexture> texture; |
1776 // Skia's convention is to only clear a device if it is non-opaque. | 1779 // Skia's convention is to only clear a device if it is non-opaque. |
1777 InitContents init = cinfo.fInfo.isOpaque() ? kUninit_InitContents : kClear_I
nitContents; | 1780 InitContents init = cinfo.fInfo.isOpaque() ? kUninit_InitContents : kClear_I
nitContents; |
1778 | 1781 |
1779 // layers are never draw in repeat modes, so we can request an approx | 1782 // layers are never draw in repeat modes, so we can request an approx |
1780 // match and ignore any padding. | 1783 // match and ignore any padding. |
1781 if (kNever_TileUsage == cinfo.fTileUsage) { | 1784 if (kNever_TileUsage == cinfo.fTileUsage) { |
1782 texture.reset(fContext->textureProvider()->createApproxTexture(desc)); | 1785 texture.reset(fContext->textureProvider()->createApproxTexture(desc)); |
1783 } else { | 1786 } else { |
1784 texture.reset(fContext->textureProvider()->createTexture(desc, SkBudgete
d::kYes)); | 1787 texture.reset(fContext->textureProvider()->createTexture(desc, true)); |
1785 } | 1788 } |
1786 | 1789 |
1787 if (texture) { | 1790 if (texture) { |
1788 SkSurfaceProps props(this->surfaceProps().flags(), cinfo.fPixelGeometry)
; | 1791 SkSurfaceProps props(this->surfaceProps().flags(), cinfo.fPixelGeometry)
; |
1789 return SkGpuDevice::Create( | 1792 return SkGpuDevice::Create( |
1790 texture->asRenderTarget(), cinfo.fInfo.width(), cinfo.fInfo.height()
, &props, init); | 1793 texture->asRenderTarget(), cinfo.fInfo.width(), cinfo.fInfo.height()
, &props, init); |
1791 } else { | 1794 } else { |
1792 SkErrorInternals::SetError( kInternalError_SkError, | 1795 SkErrorInternals::SetError( kInternalError_SkError, |
1793 "---- failed to create gpu device texture [%
d %d]\n", | 1796 "---- failed to create gpu device texture [%
d %d]\n", |
1794 cinfo.fInfo.width(), cinfo.fInfo.height()); | 1797 cinfo.fInfo.width(), cinfo.fInfo.height()); |
1795 return nullptr; | 1798 return nullptr; |
1796 } | 1799 } |
1797 } | 1800 } |
1798 | 1801 |
1799 SkSurface* SkGpuDevice::newSurface(const SkImageInfo& info, const SkSurfaceProps
& props) { | 1802 SkSurface* SkGpuDevice::newSurface(const SkImageInfo& info, const SkSurfaceProps
& props) { |
1800 ASSERT_SINGLE_OWNER | 1803 ASSERT_SINGLE_OWNER |
1801 // TODO: Change the signature of newSurface to take a budgeted parameter. | 1804 // TODO: Change the signature of newSurface to take a budgeted parameter. |
1802 static const SkBudgeted kBudgeted = SkBudgeted::kNo; | 1805 static const SkSurface::Budgeted kBudgeted = SkSurface::kNo_Budgeted; |
1803 return SkSurface::NewRenderTarget(fContext, kBudgeted, info, fRenderTarget->
desc().fSampleCnt, | 1806 return SkSurface::NewRenderTarget(fContext, kBudgeted, info, fRenderTarget->
desc().fSampleCnt, |
1804 &props); | 1807 &props); |
1805 } | 1808 } |
1806 | 1809 |
1807 bool SkGpuDevice::EXPERIMENTAL_drawPicture(SkCanvas* mainCanvas, const SkPicture
* mainPicture, | 1810 bool SkGpuDevice::EXPERIMENTAL_drawPicture(SkCanvas* mainCanvas, const SkPicture
* mainPicture, |
1808 const SkMatrix* matrix, const SkPaint
* paint) { | 1811 const SkMatrix* matrix, const SkPaint
* paint) { |
1809 ASSERT_SINGLE_OWNER | 1812 ASSERT_SINGLE_OWNER |
1810 #ifndef SK_IGNORE_GPU_LAYER_HOISTING | 1813 #ifndef SK_IGNORE_GPU_LAYER_HOISTING |
1811 // todo: should handle this natively | 1814 // todo: should handle this natively |
1812 if (paint) { | 1815 if (paint) { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1880 } | 1883 } |
1881 | 1884 |
1882 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { | 1885 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { |
1883 ASSERT_SINGLE_OWNER | 1886 ASSERT_SINGLE_OWNER |
1884 // We always return a transient cache, so it is freed after each | 1887 // We always return a transient cache, so it is freed after each |
1885 // filter traversal. | 1888 // filter traversal. |
1886 return SkGpuDevice::NewImageFilterCache(); | 1889 return SkGpuDevice::NewImageFilterCache(); |
1887 } | 1890 } |
1888 | 1891 |
1889 #endif | 1892 #endif |
OLD | NEW |