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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 fOpaque = SkToBool(flags & kIsOpaque_Flag); | 191 fOpaque = SkToBool(flags & kIsOpaque_Flag); |
192 | 192 |
193 fRenderTarget = SkRef(rt); | 193 fRenderTarget = SkRef(rt); |
194 | 194 |
195 SkAlphaType at = fOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType; | 195 SkAlphaType at = fOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType; |
196 SkImageInfo info = rt->surfacePriv().info(at).makeWH(width, height); | 196 SkImageInfo info = rt->surfacePriv().info(at).makeWH(width, height); |
197 SkPixelRef* pr = new SkGrPixelRef(info, rt); | 197 SkPixelRef* pr = new SkGrPixelRef(info, rt); |
198 fLegacyBitmap.setInfo(info); | 198 fLegacyBitmap.setInfo(info); |
199 fLegacyBitmap.setPixelRef(pr)->unref(); | 199 fLegacyBitmap.setPixelRef(pr)->unref(); |
200 | 200 |
201 fDrawContext.reset(fContext->drawContext(rt, &this->surfaceProps())); | 201 fDrawContext.reset(this->context()->drawContext(rt, &this->surfaceProps())); |
202 } | 202 } |
203 | 203 |
204 GrRenderTarget* SkGpuDevice::CreateRenderTarget(GrContext* context, SkSurface::B
udgeted budgeted, | 204 GrRenderTarget* SkGpuDevice::CreateRenderTarget(GrContext* context, SkSurface::B
udgeted budgeted, |
205 const SkImageInfo& origInfo, int
sampleCount) { | 205 const SkImageInfo& origInfo, int
sampleCount) { |
206 if (kUnknown_SkColorType == origInfo.colorType() || | 206 if (kUnknown_SkColorType == origInfo.colorType() || |
207 origInfo.width() < 0 || origInfo.height() < 0) { | 207 origInfo.width() < 0 || origInfo.height() < 0) { |
208 return nullptr; | 208 return nullptr; |
209 } | 209 } |
210 | 210 |
211 if (!context) { | 211 if (!context) { |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 | 342 |
343 void SkGpuDevice::replaceRenderTarget(bool shouldRetainContent) { | 343 void SkGpuDevice::replaceRenderTarget(bool shouldRetainContent) { |
344 // Caller must have accessed the render target, because it knows the rt must
be replaced. | 344 // Caller must have accessed the render target, because it knows the rt must
be replaced. |
345 SkASSERT(!fNeedClear); | 345 SkASSERT(!fNeedClear); |
346 | 346 |
347 SkSurface::Budgeted budgeted = | 347 SkSurface::Budgeted budgeted = |
348 fRenderTarget->resourcePriv().isBudgeted() ? SkSurface::kYes_Budgete
d | 348 fRenderTarget->resourcePriv().isBudgeted() ? SkSurface::kYes_Budgete
d |
349 : SkSurface::kNo_Budgeted
; | 349 : SkSurface::kNo_Budgeted
; |
350 | 350 |
351 SkAutoTUnref<GrRenderTarget> newRT(CreateRenderTarget( | 351 SkAutoTUnref<GrRenderTarget> newRT(CreateRenderTarget( |
352 fRenderTarget->getContext(), budgeted, this->imageInfo(), fRenderTarget-
>desc().fSampleCnt)); | 352 this->context(), budgeted, this->imageInfo(), fRenderTarget->desc().fSam
pleCnt)); |
353 | 353 |
354 if (nullptr == newRT) { | 354 if (nullptr == newRT) { |
355 return; | 355 return; |
356 } | 356 } |
357 | 357 |
358 if (shouldRetainContent) { | 358 if (shouldRetainContent) { |
359 if (fRenderTarget->wasDestroyed()) { | 359 if (fRenderTarget->wasDestroyed()) { |
360 return; | 360 return; |
361 } | 361 } |
362 this->context()->copySurface(newRT, fRenderTarget); | 362 this->context()->copySurface(newRT, fRenderTarget); |
363 } | 363 } |
364 | 364 |
365 SkASSERT(fRenderTarget != newRT); | 365 SkASSERT(fRenderTarget != newRT); |
366 | 366 |
367 fRenderTarget->unref(); | 367 fRenderTarget->unref(); |
368 fRenderTarget = newRT.detach(); | 368 fRenderTarget = newRT.detach(); |
369 | 369 |
370 #ifdef SK_DEBUG | 370 #ifdef SK_DEBUG |
371 SkImageInfo info = fRenderTarget->surfacePriv().info(fOpaque ? kOpaque_SkAlp
haType : | 371 SkImageInfo info = fRenderTarget->surfacePriv().info(fOpaque ? kOpaque_SkAlp
haType : |
372 kPremul_SkAlp
haType); | 372 kPremul_SkAlp
haType); |
373 SkASSERT(info == fLegacyBitmap.info()); | 373 SkASSERT(info == fLegacyBitmap.info()); |
374 #endif | 374 #endif |
375 SkPixelRef* pr = new SkGrPixelRef(fLegacyBitmap.info(), fRenderTarget); | 375 SkPixelRef* pr = new SkGrPixelRef(fLegacyBitmap.info(), fRenderTarget); |
376 fLegacyBitmap.setPixelRef(pr)->unref(); | 376 fLegacyBitmap.setPixelRef(pr)->unref(); |
377 | 377 |
378 fDrawContext.reset(fRenderTarget->getContext()->drawContext(fRenderTarget, | 378 fDrawContext.reset(this->context()->drawContext(fRenderTarget, &this->surfac
eProps())); |
379 &this->surfacePr
ops())); | |
380 } | 379 } |
381 | 380 |
382 /////////////////////////////////////////////////////////////////////////////// | 381 /////////////////////////////////////////////////////////////////////////////// |
383 | 382 |
384 void SkGpuDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { | 383 void SkGpuDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { |
385 CHECK_SHOULD_DRAW(draw); | 384 CHECK_SHOULD_DRAW(draw); |
386 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPaint", fContext); | 385 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPaint", fContext); |
387 | 386 |
388 GrPaint grPaint; | 387 GrPaint grPaint; |
389 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, &grPaint)) { | 388 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, &grPaint)) { |
(...skipping 1626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2016 #endif | 2015 #endif |
2017 } | 2016 } |
2018 | 2017 |
2019 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { | 2018 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { |
2020 // We always return a transient cache, so it is freed after each | 2019 // We always return a transient cache, so it is freed after each |
2021 // filter traversal. | 2020 // filter traversal. |
2022 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); | 2021 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); |
2023 } | 2022 } |
2024 | 2023 |
2025 #endif | 2024 #endif |
OLD | NEW |