GrCCClipPath.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright 2018 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #include "src/gpu/ccpr/GrCCClipPath.h"
  8. #include "include/gpu/GrRenderTarget.h"
  9. #include "include/gpu/GrTexture.h"
  10. #include "src/gpu/GrOnFlushResourceProvider.h"
  11. #include "src/gpu/GrProxyProvider.h"
  12. #include "src/gpu/ccpr/GrCCPerFlushResources.h"
  13. void GrCCClipPath::init(
  14. const SkPath& deviceSpacePath, const SkIRect& accessRect,
  15. GrCCAtlas::CoverageType atlasCoverageType, const GrCaps& caps) {
  16. SkASSERT(!this->isInitialized());
  17. fAtlasLazyProxy = GrCCAtlas::MakeLazyAtlasProxy([this](
  18. GrResourceProvider* resourceProvider, GrPixelConfig pixelConfig, int sampleCount) {
  19. SkASSERT(fHasAtlas);
  20. SkASSERT(!fHasAtlasTransform);
  21. GrTextureProxy* textureProxy = fAtlas ? fAtlas->textureProxy() : nullptr;
  22. if (!textureProxy || !textureProxy->instantiate(resourceProvider)) {
  23. fAtlasScale = fAtlasTranslate = {0, 0};
  24. SkDEBUGCODE(fHasAtlasTransform = true);
  25. return sk_sp<GrTexture>();
  26. }
  27. sk_sp<GrTexture> texture = sk_ref_sp(textureProxy->peekTexture());
  28. SkASSERT(texture);
  29. SkASSERT(texture->asRenderTarget()->numSamples() == sampleCount);
  30. SkASSERT(textureProxy->origin() == kTopLeft_GrSurfaceOrigin);
  31. fAtlasScale = {1.f / texture->width(), 1.f / texture->height()};
  32. fAtlasTranslate.set(fDevToAtlasOffset.fX * fAtlasScale.x(),
  33. fDevToAtlasOffset.fY * fAtlasScale.y());
  34. SkDEBUGCODE(fHasAtlasTransform = true);
  35. return texture;
  36. }, atlasCoverageType, caps);
  37. fDeviceSpacePath = deviceSpacePath;
  38. fDeviceSpacePath.getBounds().roundOut(&fPathDevIBounds);
  39. fAccessRect = accessRect;
  40. }
  41. void GrCCClipPath::accountForOwnPath(GrCCPerFlushResourceSpecs* specs) const {
  42. SkASSERT(this->isInitialized());
  43. ++specs->fNumClipPaths;
  44. specs->fRenderedPathStats[GrCCPerFlushResourceSpecs::kFillIdx].statPath(fDeviceSpacePath);
  45. SkIRect ibounds;
  46. if (ibounds.intersect(fAccessRect, fPathDevIBounds)) {
  47. specs->fRenderedAtlasSpecs.accountForSpace(ibounds.width(), ibounds.height());
  48. }
  49. }
  50. void GrCCClipPath::renderPathInAtlas(GrCCPerFlushResources* resources,
  51. GrOnFlushResourceProvider* onFlushRP) {
  52. SkASSERT(this->isInitialized());
  53. SkASSERT(!fHasAtlas);
  54. fAtlas = resources->renderDeviceSpacePathInAtlas(
  55. fAccessRect, fDeviceSpacePath, fPathDevIBounds, GrFillRuleForSkPath(fDeviceSpacePath),
  56. &fDevToAtlasOffset);
  57. SkDEBUGCODE(fHasAtlas = true);
  58. }