diff options
author | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-04-07 23:45:31 +0000 |
---|---|---|
committer | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-04-07 23:45:31 +0000 |
commit | 8865d09cf81bd38359421024badde36109bbf41d (patch) | |
tree | 443682d0f036f27753e4d2626740bed62221567d /src/core | |
parent | 98f4e5cea30690259ef808ec063380d3ba8740b0 (diff) |
Revert of Initial picture shader implementation (https://codereview.chromium.org/221923007/)
Reason for revert:
breaking the buildbots. Subsequent CL only addressed CompareGMs but GenerateGMs are also failing.
Original issue's description:
> Initial picture shader implementation
>
> This CL adds an SkPictureShader class to support SkPicture-based
> patterns.
>
> The implementation renders the picture into an SkBitmap tile and then
> delegates to SkBitmapProcShader for the actual operation.
>
> R=reed@google.com,robertphillips@google.com,bsalomon@google.com
>
> Committed: http://code.google.com/p/skia/source/detail?r=14085
R=bsalomon@google.com, reed@google.com, robertphillips@google.com, fmalita@chromium.org
TBR=bsalomon@google.com, fmalita@chromium.org, reed@google.com, robertphillips@google.com
NOTREECHECKS=true
NOTRY=true
Author: bensong@google.com
Review URL: https://codereview.chromium.org/227553010
git-svn-id: http://skia.googlecode.com/svn/trunk@14087 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/SkPictureShader.cpp | 185 | ||||
-rw-r--r-- | src/core/SkPictureShader.h | 60 | ||||
-rw-r--r-- | src/core/SkShader.cpp | 6 |
3 files changed, 0 insertions, 251 deletions
diff --git a/src/core/SkPictureShader.cpp b/src/core/SkPictureShader.cpp deleted file mode 100644 index 15df3a37a5..0000000000 --- a/src/core/SkPictureShader.cpp +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Copyright 2014 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "SkPictureShader.h" - -#include "SkBitmap.h" -#include "SkBitmapProcShader.h" -#include "SkCanvas.h" -#include "SkMatrixUtils.h" -#include "SkPicture.h" -#include "SkReadBuffer.h" - -#if SK_SUPPORT_GPU -#include "GrContext.h" -#endif - -SkPictureShader::SkPictureShader(SkPicture* picture, TileMode tmx, TileMode tmy) - : fPicture(picture) - , fTmx(tmx) - , fTmy(tmy) { - SkSafeRef(fPicture); -} - -SkPictureShader::SkPictureShader(SkReadBuffer& buffer) - : INHERITED(buffer) { - fTmx = static_cast<SkShader::TileMode>(buffer.read32()); - fTmy = static_cast<SkShader::TileMode>(buffer.read32()); - if (buffer.readBool()) { - fPicture = SkPicture::CreateFromBuffer(buffer); - } else { - fPicture = NULL; - } -} - -SkPictureShader::~SkPictureShader() { - SkSafeUnref(fPicture); -} - -SkPictureShader* SkPictureShader::Create(SkPicture* picture, TileMode tmx, TileMode tmy) { - return SkNEW_ARGS(SkPictureShader, (picture, tmx, tmy)); -} - -void SkPictureShader::flatten(SkWriteBuffer& buffer) const { - this->INHERITED::flatten(buffer); - - buffer.write32(fTmx); - buffer.write32(fTmy); - buffer.writeBool(NULL != fPicture); - if (fPicture) { - fPicture->flatten(buffer); - } -} - -bool SkPictureShader::buildBitmapShader(const SkMatrix& matrix) const { - if (!fPicture || (0 == fPicture->width() && 0 == fPicture->height())) { - return false; - } - - SkMatrix m; - if (this->hasLocalMatrix()) { - m.setConcat(matrix, this->getLocalMatrix()); - } else { - m = matrix; - } - - // Use a rotation-invariant scale - SkPoint scale; - if (!SkDecomposeUpper2x2(m, NULL, &scale, NULL)) { - // Decomposition failed, use an approximation. - scale.set(SkScalarSqrt(m.getScaleX() * m.getScaleX() + m.getSkewX() * m.getSkewX()), - SkScalarSqrt(m.getScaleY() * m.getScaleY() + m.getSkewY() * m.getSkewY())); - } - SkSize scaledSize = SkSize::Make(scale.x() * fPicture->width(), scale.y() * fPicture->height()); - - SkISize tileSize = scaledSize.toRound(); - if (tileSize.isEmpty()) { - return false; - } - - // The actual scale, compensating for rounding. - SkSize tileScale = SkSize::Make(SkIntToScalar(tileSize.width()) / fPicture->width(), - SkIntToScalar(tileSize.height()) / fPicture->height()); - - if (!fCachedShader || tileScale != fCachedTileScale) { - SkBitmap bm; - if (!bm.allocN32Pixels(tileSize.width(), tileSize.height())) { - return false; - } - bm.eraseColor(SK_ColorTRANSPARENT); - - SkCanvas canvas(bm); - canvas.scale(tileScale.width(), tileScale.height()); - canvas.drawPicture(*fPicture); - - fCachedShader.reset(CreateBitmapShader(bm, fTmx, fTmy)); - fCachedTileScale = tileScale; - } - - SkMatrix shaderMatrix = this->getLocalMatrix(); - shaderMatrix.preScale(1 / tileScale.width(), 1 / tileScale.height()); - fCachedShader->setLocalMatrix(shaderMatrix); - - return true; -} - -bool SkPictureShader::setContext(const SkBitmap& device, - const SkPaint& paint, - const SkMatrix& matrix) { - if (!this->buildBitmapShader(matrix)) { - return false; - } - - if (!this->INHERITED::setContext(device, paint, matrix)) { - return false; - } - - SkASSERT(fCachedShader); - if (!fCachedShader->setContext(device, paint, matrix)) { - this->INHERITED::endContext(); - return false; - } - - return true; -} - -void SkPictureShader::endContext() { - SkASSERT(fCachedShader); - fCachedShader->endContext(); - - this->INHERITED::endContext(); -} - -uint32_t SkPictureShader::getFlags() { - if (NULL != fCachedShader) { - return fCachedShader->getFlags(); - } - return 0; -} - -SkShader::ShadeProc SkPictureShader::asAShadeProc(void** ctx) { - if (fCachedShader) { - return fCachedShader->asAShadeProc(ctx); - } - return NULL; -} - -void SkPictureShader::shadeSpan(int x, int y, SkPMColor dstC[], int count) { - SkASSERT(fCachedShader); - fCachedShader->shadeSpan(x, y, dstC, count); -} - -void SkPictureShader::shadeSpan16(int x, int y, uint16_t dstC[], int count) { - SkASSERT(fCachedShader); - fCachedShader->shadeSpan16(x, y, dstC, count); -} - -#ifndef SK_IGNORE_TO_STRING -void SkPictureShader::toString(SkString* str) const { - static const char* gTileModeName[SkShader::kTileModeCount] = { - "clamp", "repeat", "mirror" - }; - - str->appendf("PictureShader: [%d:%d] ", - fPicture ? fPicture->width() : 0, - fPicture ? fPicture->height() : 0); - - str->appendf("(%s, %s)", gTileModeName[fTmx], gTileModeName[fTmy]); - - this->INHERITED::toString(str); -} -#endif - -#if SK_SUPPORT_GPU -GrEffectRef* SkPictureShader::asNewEffect(GrContext* context, const SkPaint& paint) const { - if (!this->buildBitmapShader(context->getMatrix())) { - return NULL; - } - SkASSERT(fCachedShader); - return fCachedShader->asNewEffect(context, paint); -} -#endif diff --git a/src/core/SkPictureShader.h b/src/core/SkPictureShader.h deleted file mode 100644 index ea74b56d73..0000000000 --- a/src/core/SkPictureShader.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2014 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkPictureShader_DEFINED -#define SkPictureShader_DEFINED - -#include "SkShader.h" - -class SkBitmap; -class SkPicture; - -/* - * An SkPictureShader can be used to draw SkPicture-based patterns. - * - * The SkPicture is first rendered into a tile, which is then used to shade the area according - * to specified tiling rules. - */ -class SkPictureShader : public SkShader { -public: - static SkPictureShader* Create(SkPicture*, TileMode, TileMode); - virtual ~SkPictureShader(); - - virtual bool setContext(const SkBitmap&, const SkPaint&, const SkMatrix&) SK_OVERRIDE; - virtual void endContext() SK_OVERRIDE; - virtual uint32_t getFlags() SK_OVERRIDE; - - virtual ShadeProc asAShadeProc(void** ctx) SK_OVERRIDE; - virtual void shadeSpan(int x, int y, SkPMColor dstC[], int count) SK_OVERRIDE; - virtual void shadeSpan16(int x, int y, uint16_t dstC[], int count) SK_OVERRIDE; - - SK_TO_STRING_OVERRIDE() - SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPictureShader) - -#if SK_SUPPORT_GPU - GrEffectRef* asNewEffect(GrContext*, const SkPaint&) const SK_OVERRIDE; -#endif - -protected: - SkPictureShader(SkReadBuffer&); - virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; - -private: - SkPictureShader(SkPicture*, TileMode, TileMode); - - bool buildBitmapShader(const SkMatrix&) const; - - SkPicture* fPicture; - TileMode fTmx, fTmy; - - mutable SkAutoTUnref<SkShader> fCachedShader; - mutable SkSize fCachedTileScale; - - typedef SkShader INHERITED; -}; - -#endif // SkPictureShader_DEFINED diff --git a/src/core/SkShader.cpp b/src/core/SkShader.cpp index e337b7d906..31b208e2cc 100644 --- a/src/core/SkShader.cpp +++ b/src/core/SkShader.cpp @@ -9,8 +9,6 @@ #include "SkReadBuffer.h" #include "SkMallocPixelRef.h" #include "SkPaint.h" -#include "SkPicture.h" -#include "SkPictureShader.h" #include "SkScalar.h" #include "SkShader.h" #include "SkWriteBuffer.h" @@ -181,10 +179,6 @@ SkShader* SkShader::CreateBitmapShader(const SkBitmap& src, return ::CreateBitmapShader(src, tmx, tmy, NULL); } -SkShader* SkShader::CreatePictureShader(SkPicture* src, TileMode tmx, TileMode tmy) { - return SkPictureShader::Create(src, tmx, tmy); -} - #ifndef SK_IGNORE_TO_STRING void SkShader::toString(SkString* str) const { if (this->hasLocalMatrix()) { |