| 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 default: // If it is unpremul or unknown don't try to render | 120 default: // If it is unpremul or unknown don't try to render |
| 121 return false; | 121 return false; |
| 122 } | 122 } |
| 123 } | 123 } |
| 124 if (kClear_InitContents == init) { | 124 if (kClear_InitContents == init) { |
| 125 *flags |= kNeedClear_Flag; | 125 *flags |= kNeedClear_Flag; |
| 126 } | 126 } |
| 127 return true; | 127 return true; |
| 128 } | 128 } |
| 129 | 129 |
| 130 SkGpuDevice* SkGpuDevice::Create(GrRenderTarget* rt, const SkSurfaceProps* props
, | 130 sk_sp<SkGpuDevice> SkGpuDevice::Make(sk_sp<GrRenderTarget> rt, const SkSurfacePr
ops* props, |
| 131 InitContents init) { | 131 InitContents init) { |
| 132 return SkGpuDevice::Create(rt, rt->width(), rt->height(), props, init); | 132 const int width = rt->width(); |
| 133 const int height = rt->height(); |
| 134 return SkGpuDevice::Make(std::move(rt), width, height, props, init); |
| 133 } | 135 } |
| 134 | 136 |
| 135 SkGpuDevice* SkGpuDevice::Create(GrRenderTarget* rt, int width, int height, | 137 sk_sp<SkGpuDevice> SkGpuDevice::Make(sk_sp<GrRenderTarget> rt, int width, int he
ight, |
| 136 const SkSurfaceProps* props, InitContents init)
{ | 138 const SkSurfaceProps* props, InitContents i
nit) { |
| 137 if (!rt || rt->wasDestroyed()) { | 139 if (!rt || rt->wasDestroyed()) { |
| 138 return nullptr; | 140 return nullptr; |
| 139 } | 141 } |
| 140 unsigned flags; | 142 unsigned flags; |
| 141 if (!CheckAlphaTypeAndGetFlags(nullptr, init, &flags)) { | 143 if (!CheckAlphaTypeAndGetFlags(nullptr, init, &flags)) { |
| 142 return nullptr; | 144 return nullptr; |
| 143 } | 145 } |
| 144 return new SkGpuDevice(rt, width, height, props, flags); | 146 return sk_sp<SkGpuDevice>(new SkGpuDevice(rt.get(), width, height, props, fl
ags)); |
| 145 } | 147 } |
| 146 | 148 |
| 147 SkGpuDevice* SkGpuDevice::Create(GrContext* context, SkBudgeted budgeted, | 149 sk_sp<SkGpuDevice> SkGpuDevice::Make(GrContext* context, SkBudgeted budgeted, |
| 148 const SkImageInfo& info, int sampleCount, | 150 const SkImageInfo& info, int sampleCount, |
| 149 const SkSurfaceProps* props, InitContents init)
{ | 151 const SkSurfaceProps* props, InitContents i
nit) { |
| 150 unsigned flags; | 152 unsigned flags; |
| 151 if (!CheckAlphaTypeAndGetFlags(&info, init, &flags)) { | 153 if (!CheckAlphaTypeAndGetFlags(&info, init, &flags)) { |
| 152 return nullptr; | 154 return nullptr; |
| 153 } | 155 } |
| 154 | 156 |
| 155 SkAutoTUnref<GrRenderTarget> rt(CreateRenderTarget(context, budgeted, info,
sampleCount)); | 157 SkAutoTUnref<GrRenderTarget> rt(CreateRenderTarget(context, budgeted, info,
sampleCount)); |
| 156 if (nullptr == rt) { | 158 if (!rt) { |
| 157 return nullptr; | 159 return nullptr; |
| 158 } | 160 } |
| 159 | 161 |
| 160 return new SkGpuDevice(rt, info.width(), info.height(), props, flags); | 162 return sk_sp<SkGpuDevice>(new SkGpuDevice(rt, info.width(), info.height(), p
rops, flags)); |
| 161 } | 163 } |
| 162 | 164 |
| 163 SkGpuDevice::SkGpuDevice(GrRenderTarget* rt, int width, int height, | 165 SkGpuDevice::SkGpuDevice(GrRenderTarget* rt, int width, int height, |
| 164 const SkSurfaceProps* props, unsigned flags) | 166 const SkSurfaceProps* props, unsigned flags) |
| 165 : INHERITED(SkSurfacePropsCopyOrDefault(props)) | 167 : INHERITED(SkSurfacePropsCopyOrDefault(props)) |
| 166 , fContext(SkRef(rt->getContext())) | 168 , fContext(SkRef(rt->getContext())) |
| 167 , fRenderTarget(SkRef(rt)) { | 169 , fRenderTarget(SkRef(rt)) { |
| 168 fOpaque = SkToBool(flags & kIsOpaque_Flag); | 170 fOpaque = SkToBool(flags & kIsOpaque_Flag); |
| 169 | 171 |
| 170 SkAlphaType at = fOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType; | 172 SkAlphaType at = fOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType; |
| (...skipping 1578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1749 // layers are never draw in repeat modes, so we can request an approx | 1751 // layers are never draw in repeat modes, so we can request an approx |
| 1750 // match and ignore any padding. | 1752 // match and ignore any padding. |
| 1751 if (kNever_TileUsage == cinfo.fTileUsage) { | 1753 if (kNever_TileUsage == cinfo.fTileUsage) { |
| 1752 texture.reset(fContext->textureProvider()->createApproxTexture(desc)); | 1754 texture.reset(fContext->textureProvider()->createApproxTexture(desc)); |
| 1753 } else { | 1755 } else { |
| 1754 texture.reset(fContext->textureProvider()->createTexture(desc, SkBudgete
d::kYes)); | 1756 texture.reset(fContext->textureProvider()->createTexture(desc, SkBudgete
d::kYes)); |
| 1755 } | 1757 } |
| 1756 | 1758 |
| 1757 if (texture) { | 1759 if (texture) { |
| 1758 SkSurfaceProps props(this->surfaceProps().flags(), cinfo.fPixelGeometry)
; | 1760 SkSurfaceProps props(this->surfaceProps().flags(), cinfo.fPixelGeometry)
; |
| 1759 return SkGpuDevice::Create( | 1761 return SkGpuDevice::Make(sk_ref_sp(texture->asRenderTarget()), |
| 1760 texture->asRenderTarget(), cinfo.fInfo.width(), cinfo.fInfo.height()
, &props, init); | 1762 cinfo.fInfo.width(), cinfo.fInfo.height(), |
| 1763 &props, init).release(); |
| 1761 } else { | 1764 } else { |
| 1762 SkErrorInternals::SetError( kInternalError_SkError, | 1765 SkErrorInternals::SetError( kInternalError_SkError, |
| 1763 "---- failed to create gpu device texture [%
d %d]\n", | 1766 "---- failed to create gpu device texture [%
d %d]\n", |
| 1764 cinfo.fInfo.width(), cinfo.fInfo.height()); | 1767 cinfo.fInfo.width(), cinfo.fInfo.height()); |
| 1765 return nullptr; | 1768 return nullptr; |
| 1766 } | 1769 } |
| 1767 } | 1770 } |
| 1768 | 1771 |
| 1769 sk_sp<SkSurface> SkGpuDevice::makeSurface(const SkImageInfo& info, const SkSurfa
ceProps& props) { | 1772 sk_sp<SkSurface> SkGpuDevice::makeSurface(const SkImageInfo& info, const SkSurfa
ceProps& props) { |
| 1770 ASSERT_SINGLE_OWNER | 1773 ASSERT_SINGLE_OWNER |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1846 } | 1849 } |
| 1847 | 1850 |
| 1848 SkImageFilterCache* SkGpuDevice::getImageFilterCache() { | 1851 SkImageFilterCache* SkGpuDevice::getImageFilterCache() { |
| 1849 ASSERT_SINGLE_OWNER | 1852 ASSERT_SINGLE_OWNER |
| 1850 // We always return a transient cache, so it is freed after each | 1853 // We always return a transient cache, so it is freed after each |
| 1851 // filter traversal. | 1854 // filter traversal. |
| 1852 return SkImageFilterCache::Create(kDefaultImageFilterCacheSize); | 1855 return SkImageFilterCache::Create(kDefaultImageFilterCacheSize); |
| 1853 } | 1856 } |
| 1854 | 1857 |
| 1855 #endif | 1858 #endif |
| OLD | NEW |