SkImage-backed SkPictureShader
Instead of using an explicit image generator + SkBitmap + bitmap shader, switch to the shiny new SkImage/image generator/image shader. R=reed@google.com Review URL: https://codereview.chromium.org/1343153003
This commit is contained in:
parent
2f5891ea64
commit
97be9a0c86
@ -7,10 +7,10 @@
|
||||
|
||||
#include "SkPictureShader.h"
|
||||
|
||||
#include "SkBitmap.h"
|
||||
#include "SkBitmapProcShader.h"
|
||||
#include "SkCanvas.h"
|
||||
#include "SkImageCacherator.h"
|
||||
#include "SkImageGenerator.h"
|
||||
#include "SkImageShader.h"
|
||||
#include "SkMatrixUtils.h"
|
||||
#include "SkPicture.h"
|
||||
#include "SkReadBuffer.h"
|
||||
@ -215,20 +215,26 @@ SkShader* SkPictureShader::refBitmapShader(const SkMatrix& viewMatrix, const SkM
|
||||
this->getLocalMatrix());
|
||||
|
||||
if (!SkResourceCache::Find(key, BitmapShaderRec::Visitor, &tileShader)) {
|
||||
SkMatrix tileMatrix;
|
||||
tileMatrix.setRectToRect(fTile, SkRect::MakeIWH(tileSize.width(), tileSize.height()),
|
||||
SkMatrix tileMatrix =
|
||||
SkMatrix::MakeRectToRect(fTile, SkRect::MakeIWH(tileSize.width(), tileSize.height()),
|
||||
SkMatrix::kFill_ScaleToFit);
|
||||
SkBitmap bm;
|
||||
if (!SkDEPRECATED_InstallDiscardablePixelRef(
|
||||
SkImageGenerator::NewFromPicture(tileSize, fPicture, &tileMatrix, nullptr), &bm)) {
|
||||
SkAutoTUnref<SkImage> tileImage(
|
||||
SkImage::NewFromPicture(fPicture, tileSize, &tileMatrix, nullptr));
|
||||
if (!tileImage) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SkMatrix shaderMatrix = this->getLocalMatrix();
|
||||
shaderMatrix.preScale(1 / tileScale.width(), 1 / tileScale.height());
|
||||
tileShader.reset(CreateBitmapShader(bm, fTmx, fTmy, &shaderMatrix));
|
||||
tileShader.reset(tileImage->newShader(fTmx, fTmy, &shaderMatrix));
|
||||
|
||||
SkResourceCache::Add(new BitmapShaderRec(key, tileShader.get(), bm.getSize()));
|
||||
// The actual pixels are accounted for in the SkImage cacherator budget. Here we
|
||||
// use a rough estimate for the related objects.
|
||||
const size_t bytesUsed = sizeof(SkImageShader) +
|
||||
sizeof(SkImage) +
|
||||
sizeof(SkImageCacherator) +
|
||||
sizeof(SkImageGenerator);
|
||||
SkResourceCache::Add(new BitmapShaderRec(key, tileShader.get(), bytesUsed));
|
||||
}
|
||||
|
||||
return tileShader.detach();
|
||||
|
Loading…
Reference in New Issue
Block a user