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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 } | 117 } |
118 unsigned flags; | 118 unsigned flags; |
119 if (!CheckAlphaTypeAndGetFlags(nullptr, init, &flags)) { | 119 if (!CheckAlphaTypeAndGetFlags(nullptr, init, &flags)) { |
120 return nullptr; | 120 return nullptr; |
121 } | 121 } |
122 return sk_sp<SkBaseDevice>(new SkGpuDevice(std::move(drawContext), width, he
ight, flags)); | 122 return sk_sp<SkBaseDevice>(new SkGpuDevice(std::move(drawContext), width, he
ight, flags)); |
123 } | 123 } |
124 | 124 |
125 sk_sp<SkGpuDevice> SkGpuDevice::Make(GrContext* context, SkBudgeted budgeted, | 125 sk_sp<SkGpuDevice> SkGpuDevice::Make(GrContext* context, SkBudgeted budgeted, |
126 const SkImageInfo& info, int sampleCount, | 126 const SkImageInfo& info, int sampleCount, |
| 127 GrSurfaceOrigin origin, |
127 const SkSurfaceProps* props, InitContents i
nit) { | 128 const SkSurfaceProps* props, InitContents i
nit) { |
128 unsigned flags; | 129 unsigned flags; |
129 if (!CheckAlphaTypeAndGetFlags(&info, init, &flags)) { | 130 if (!CheckAlphaTypeAndGetFlags(&info, init, &flags)) { |
130 return nullptr; | 131 return nullptr; |
131 } | 132 } |
132 | 133 |
133 sk_sp<GrDrawContext> drawContext(CreateDrawContext(context, budgeted, info, | 134 sk_sp<GrDrawContext> drawContext(MakeDrawContext(context, budgeted, info, |
134 sampleCount, props)); | 135 sampleCount, origin, props)
); |
135 if (!drawContext) { | 136 if (!drawContext) { |
136 return nullptr; | 137 return nullptr; |
137 } | 138 } |
138 | 139 |
139 return sk_sp<SkGpuDevice>(new SkGpuDevice(std::move(drawContext), | 140 return sk_sp<SkGpuDevice>(new SkGpuDevice(std::move(drawContext), |
140 info.width(), info.height(), flags
)); | 141 info.width(), info.height(), flags
)); |
141 } | 142 } |
142 | 143 |
143 SkGpuDevice::SkGpuDevice(sk_sp<GrDrawContext> drawContext, int width, int height
, unsigned flags) | 144 SkGpuDevice::SkGpuDevice(sk_sp<GrDrawContext> drawContext, int width, int height
, unsigned flags) |
144 : INHERITED(drawContext->surfaceProps()) | 145 : INHERITED(drawContext->surfaceProps()) |
145 , fContext(SkRef(drawContext->accessRenderTarget()->getContext())) | 146 , fContext(SkRef(drawContext->accessRenderTarget()->getContext())) |
146 , fRenderTarget(drawContext->renderTarget()) | 147 , fRenderTarget(drawContext->renderTarget()) |
147 , fDrawContext(std::move(drawContext)) { | 148 , fDrawContext(std::move(drawContext)) { |
148 fSize.set(width, height); | 149 fSize.set(width, height); |
149 fOpaque = SkToBool(flags & kIsOpaque_Flag); | 150 fOpaque = SkToBool(flags & kIsOpaque_Flag); |
150 | 151 |
151 if (flags & kNeedClear_Flag) { | 152 if (flags & kNeedClear_Flag) { |
152 this->clearAll(); | 153 this->clearAll(); |
153 } | 154 } |
154 } | 155 } |
155 | 156 |
156 sk_sp<GrDrawContext> SkGpuDevice::CreateDrawContext(GrContext* context, | 157 sk_sp<GrDrawContext> SkGpuDevice::MakeDrawContext(GrContext* context, |
157 SkBudgeted budgeted, | 158 SkBudgeted budgeted, |
158 const SkImageInfo& origInfo, | 159 const SkImageInfo& origInfo, |
159 int sampleCount, | 160 int sampleCount, |
160 const SkSurfaceProps* surfac
eProps) { | 161 GrSurfaceOrigin origin, |
| 162 const SkSurfaceProps* surfaceP
rops) { |
161 if (kUnknown_SkColorType == origInfo.colorType() || | 163 if (kUnknown_SkColorType == origInfo.colorType() || |
162 origInfo.width() < 0 || origInfo.height() < 0) { | 164 origInfo.width() < 0 || origInfo.height() < 0) { |
163 return nullptr; | 165 return nullptr; |
164 } | 166 } |
165 | 167 |
166 if (!context) { | 168 if (!context) { |
167 return nullptr; | 169 return nullptr; |
168 } | 170 } |
169 | 171 |
170 SkColorType ct = origInfo.colorType(); | 172 SkColorType ct = origInfo.colorType(); |
(...skipping 10 matching lines...) Expand all Loading... |
181 if (!context->caps()->isConfigRenderable(origConfig, sampleCount > 0)) { | 183 if (!context->caps()->isConfigRenderable(origConfig, sampleCount > 0)) { |
182 // Fall back from whatever ct was to default of kRGBA or kBGRA which is
aliased as kN32 | 184 // Fall back from whatever ct was to default of kRGBA or kBGRA which is
aliased as kN32 |
183 ct = kN32_SkColorType; | 185 ct = kN32_SkColorType; |
184 } | 186 } |
185 | 187 |
186 GrPixelConfig config = SkImageInfo2GrPixelConfig(ct, at, cs, *context->caps(
)); | 188 GrPixelConfig config = SkImageInfo2GrPixelConfig(ct, at, cs, *context->caps(
)); |
187 | 189 |
188 return context->newDrawContext(SkBackingFit::kExact, // Why ex
act? | 190 return context->newDrawContext(SkBackingFit::kExact, // Why ex
act? |
189 origInfo.width(), origInfo.height(), | 191 origInfo.width(), origInfo.height(), |
190 config, sk_ref_sp(cs), sampleCount, | 192 config, sk_ref_sp(cs), sampleCount, |
191 kDefault_GrSurfaceOrigin, surfaceProps, budge
ted); | 193 origin, surfaceProps, budgeted); |
192 } | 194 } |
193 | 195 |
194 sk_sp<SkSpecialImage> SkGpuDevice::filterTexture(const SkDraw& draw, | 196 sk_sp<SkSpecialImage> SkGpuDevice::filterTexture(const SkDraw& draw, |
195 SkSpecialImage* srcImg, | 197 SkSpecialImage* srcImg, |
196 int left, int top, | 198 int left, int top, |
197 SkIPoint* offset, | 199 SkIPoint* offset, |
198 const SkImageFilter* filter) { | 200 const SkImageFilter* filter) { |
199 SkASSERT(srcImg->isTextureBacked()); | 201 SkASSERT(srcImg->isTextureBacked()); |
200 SkASSERT(filter); | 202 SkASSERT(filter); |
201 | 203 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "clearAll", fContext); | 271 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "clearAll", fContext); |
270 SkIRect rect = SkIRect::MakeWH(this->width(), this->height()); | 272 SkIRect rect = SkIRect::MakeWH(this->width(), this->height()); |
271 fDrawContext->clear(&rect, color, true); | 273 fDrawContext->clear(&rect, color, true); |
272 } | 274 } |
273 | 275 |
274 void SkGpuDevice::replaceDrawContext(bool shouldRetainContent) { | 276 void SkGpuDevice::replaceDrawContext(bool shouldRetainContent) { |
275 ASSERT_SINGLE_OWNER | 277 ASSERT_SINGLE_OWNER |
276 | 278 |
277 SkBudgeted budgeted = fRenderTarget->resourcePriv().isBudgeted(); | 279 SkBudgeted budgeted = fRenderTarget->resourcePriv().isBudgeted(); |
278 | 280 |
279 sk_sp<GrDrawContext> newDC(CreateDrawContext(this->context(), | 281 sk_sp<GrDrawContext> newDC(MakeDrawContext(this->context(), |
280 budgeted, | 282 budgeted, |
281 this->imageInfo(), | 283 this->imageInfo(), |
282 fDrawContext->numColorSamples()
, | 284 fDrawContext->numColorSamples(), |
283 &this->surfaceProps())); | 285 fDrawContext->origin(), |
| 286 &this->surfaceProps())); |
284 if (!newDC) { | 287 if (!newDC) { |
285 return; | 288 return; |
286 } | 289 } |
287 | 290 |
288 if (shouldRetainContent) { | 291 if (shouldRetainContent) { |
289 if (fRenderTarget->wasDestroyed()) { | 292 if (fRenderTarget->wasDestroyed()) { |
290 return; | 293 return; |
291 } | 294 } |
292 newDC->copySurface(fDrawContext->asTexture().get(), | 295 newDC->copySurface(fDrawContext->asTexture().get(), |
293 SkIRect::MakeWH(this->width(), this->height()), | 296 SkIRect::MakeWH(this->width(), this->height()), |
(...skipping 1468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1762 return SkGpuDevice::Make(std::move(dc), | 1765 return SkGpuDevice::Make(std::move(dc), |
1763 cinfo.fInfo.width(), cinfo.fInfo.height(), | 1766 cinfo.fInfo.width(), cinfo.fInfo.height(), |
1764 init).release(); | 1767 init).release(); |
1765 } | 1768 } |
1766 | 1769 |
1767 sk_sp<SkSurface> SkGpuDevice::makeSurface(const SkImageInfo& info, const SkSurfa
ceProps& props) { | 1770 sk_sp<SkSurface> SkGpuDevice::makeSurface(const SkImageInfo& info, const SkSurfa
ceProps& props) { |
1768 ASSERT_SINGLE_OWNER | 1771 ASSERT_SINGLE_OWNER |
1769 // TODO: Change the signature of newSurface to take a budgeted parameter. | 1772 // TODO: Change the signature of newSurface to take a budgeted parameter. |
1770 static const SkBudgeted kBudgeted = SkBudgeted::kNo; | 1773 static const SkBudgeted kBudgeted = SkBudgeted::kNo; |
1771 return SkSurface::MakeRenderTarget(fContext, kBudgeted, info, fDrawContext->
desc().fSampleCnt, | 1774 return SkSurface::MakeRenderTarget(fContext, kBudgeted, info, fDrawContext->
desc().fSampleCnt, |
1772 &props); | 1775 fDrawContext->origin(), &props); |
1773 } | 1776 } |
1774 | 1777 |
1775 SkImageFilterCache* SkGpuDevice::getImageFilterCache() { | 1778 SkImageFilterCache* SkGpuDevice::getImageFilterCache() { |
1776 ASSERT_SINGLE_OWNER | 1779 ASSERT_SINGLE_OWNER |
1777 // We always return a transient cache, so it is freed after each | 1780 // We always return a transient cache, so it is freed after each |
1778 // filter traversal. | 1781 // filter traversal. |
1779 return SkImageFilterCache::Create(kDefaultImageFilterCacheSize); | 1782 return SkImageFilterCache::Create(kDefaultImageFilterCacheSize); |
1780 } | 1783 } |
1781 | 1784 |
1782 #endif | 1785 #endif |
OLD | NEW |