提交 f6aa6899 编写于 作者: C Chinmay Garde

Use the physical size to key the images cached in the rasterizer

上级 4f356fa5
......@@ -17,14 +17,16 @@ PictureLayer::~PictureLayer() {
void PictureLayer::Paint(PaintContext::ScopedFrame& frame) {
DCHECK(picture_);
const SkRect& bounds = paint_bounds();
const SkISize size = SkISize::Make(bounds.width(), bounds.height());
SkCanvas& canvas = frame.canvas();
PictureRasterzier& rasterizer = frame.paint_context().rasterizer();
const SkRect& bounds = paint_bounds();
const SkMatrix& ctm = canvas.getTotalMatrix();
const SkISize physical_size = SkISize::Make(
bounds.width() * ctm.getScaleX(), bounds.height() * ctm.getScaleY());
PictureRasterzier& rasterizer = frame.paint_context().rasterizer();
RefPtr<SkImage> image = rasterizer.GetCachedImageIfPresent(
frame.paint_context(), frame.gr_context(), picture_.get(), size,
canvas.getTotalMatrix());
frame.paint_context(), frame.gr_context(), picture_.get(), physical_size,
ctm);
if (image) {
canvas.drawImage(image.get(), offset_.x(), offset_.y());
......
......@@ -42,13 +42,13 @@ RefPtr<SkImage> PictureRasterzier::ImageFromPicture(
PaintContext& context,
GrContext* gr_context,
SkPicture* picture,
const SkISize& size,
const SkMatrix& incomingCTM) {
const SkISize& physical_size,
const SkMatrix& incoming_ctm) {
// Step 1: Create a texture from the context's texture provider
GrSurfaceDesc desc;
desc.fWidth = size.width() * incomingCTM.getScaleX();
desc.fHeight = size.height() * incomingCTM.getScaleY();
desc.fWidth = physical_size.width();
desc.fHeight = physical_size.height();
desc.fFlags = kRenderTarget_GrSurfaceFlag;
desc.fConfig = kRGBA_8888_GrPixelConfig;
......@@ -65,10 +65,8 @@ RefPtr<SkImage> PictureRasterzier::ImageFromPicture(
GrBackendTextureDesc backendDesc;
backendDesc.fConfig = desc.fConfig;
// Note that here, we are not using GrSurfaceDesc's dimensions as those are
// not in point space.
backendDesc.fWidth = size.width();
backendDesc.fHeight = size.height();
backendDesc.fWidth = physical_size.width() / incoming_ctm.getScaleX();
backendDesc.fHeight = physical_size.height() / incoming_ctm.getScaleY();
backendDesc.fSampleCnt = desc.fSampleCnt;
backendDesc.fFlags = kRenderTarget_GrBackendTextureFlag;
backendDesc.fConfig = desc.fConfig;
......@@ -86,7 +84,7 @@ RefPtr<SkImage> PictureRasterzier::ImageFromPicture(
SkCanvas* canvas = surface->getCanvas();
DCHECK(canvas);
canvas->setMatrix(incomingCTM);
canvas->setMatrix(incoming_ctm);
canvas->drawPicture(picture);
if (context.options().isEnabled(
......@@ -111,13 +109,13 @@ RefPtr<SkImage> PictureRasterzier::GetCachedImageIfPresent(
PaintContext& context,
GrContext* gr_context,
SkPicture* picture,
const SkISize& size,
const SkMatrix& incomingCTM) {
if (size.isEmpty() || picture == nullptr || gr_context == nullptr) {
const SkISize& physical_size,
const SkMatrix& incoming_ctm) {
if (physical_size.isEmpty() || picture == nullptr || gr_context == nullptr) {
return nullptr;
}
const Key key(picture->uniqueID(), size);
const Key key(picture->uniqueID(), physical_size);
Value& value = cache_[key];
......@@ -131,8 +129,8 @@ RefPtr<SkImage> PictureRasterzier::GetCachedImageIfPresent(
<< "Did you forget to call PurgeCache between frames?";
if (!value.image) {
value.image =
ImageFromPicture(context, gr_context, picture, size, incomingCTM);
value.image = ImageFromPicture(context, gr_context, picture, physical_size,
incoming_ctm);
}
if (value.image) {
......
......@@ -28,8 +28,8 @@ class PictureRasterzier {
RefPtr<SkImage> GetCachedImageIfPresent(PaintContext& context,
GrContext* gr_context,
SkPicture* picture,
const SkISize& size,
const SkMatrix& incomingCTM);
const SkISize& physical_size,
const SkMatrix& incoming_ctm);
void PurgeCache();
......@@ -81,7 +81,7 @@ class PictureRasterzier {
RefPtr<SkImage> ImageFromPicture(PaintContext& context,
GrContext* gr_context,
SkPicture* picture,
const SkISize& size,
const SkISize& physical_size,
const SkMatrix& incomingCTM);
DISALLOW_COPY_AND_ASSIGN(PictureRasterzier);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册