Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(214)

Side by Side Diff: Source/platform/graphics/GraphicsContext.cpp

Issue 662673002: Add rendering fast path for when playing a display list canvas at 1:1 scale (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2003, 2004, 2005, 2006, 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2003, 2004, 2005, 2006, 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2013 Google Inc. All rights reserved. 3 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 1107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1118 1118
1119 void GraphicsContext::drawImageBuffer(ImageBuffer* image, const FloatRect& dest, 1119 void GraphicsContext::drawImageBuffer(ImageBuffer* image, const FloatRect& dest,
1120 const FloatRect* src, CompositeOperator op, WebBlendMode blendMode) 1120 const FloatRect* src, CompositeOperator op, WebBlendMode blendMode)
1121 { 1121 {
1122 if (contextDisabled() || !image) 1122 if (contextDisabled() || !image)
1123 return; 1123 return;
1124 1124
1125 image->draw(this, dest, src, op, blendMode); 1125 image->draw(this, dest, src, op, blendMode);
1126 } 1126 }
1127 1127
1128 static inline bool pictureScaleIsApproximatelyOne(float x)
1129 {
1130 // Function used to validate canvas scale factor.
1131 // Numerical error should not reach 6th decimal except for highly degenerate cases,
1132 // and effect of 6th decimal on scale is negligible over max span of a skia canvas
1133 // which is 32k pixels.
1134 return x > 0.999999 && x < 1.000001;
Stephen White 2014/10/16 17:38:00 Could you put this in a constant at the start of t
1135 }
1136
1128 void GraphicsContext::drawPicture(PassRefPtr<SkPicture> picture, const FloatRect & dest, const FloatRect& src, CompositeOperator op, WebBlendMode blendMode) 1137 void GraphicsContext::drawPicture(PassRefPtr<SkPicture> picture, const FloatRect & dest, const FloatRect& src, CompositeOperator op, WebBlendMode blendMode)
1129 { 1138 {
1130 ASSERT(m_canvas); 1139 ASSERT(m_canvas);
1131 if (contextDisabled() || !picture) 1140 if (contextDisabled() || !picture)
1132 return; 1141 return;
1133 1142
1134 SkMatrix ctm = m_canvas->getTotalMatrix(); 1143 SkMatrix ctm = m_canvas->getTotalMatrix();
1135 SkRect deviceDest; 1144 SkRect deviceDest;
1136 ctm.mapRect(&deviceDest, dest); 1145 ctm.mapRect(&deviceDest, dest);
1137 SkRect sourceBounds = WebCoreFloatRectToSKRect(src); 1146 float scaleX = deviceDest.width() / src.width();
1147 float scaleY = deviceDest.height() / src.height();
1138 1148
1139 RefPtr<SkPictureImageFilter> pictureFilter = adoptRef(SkPictureImageFilter:: Create(picture.get(), sourceBounds));
1140 SkMatrix layerScale;
1141 layerScale.setScale(deviceDest.width() / src.width(), deviceDest.height() / src.height());
1142 RefPtr<SkMatrixImageFilter> matrixFilter = adoptRef(SkMatrixImageFilter::Cre ate(layerScale, SkPaint::kLow_FilterLevel, pictureFilter.get()));
1143 SkPaint picturePaint; 1149 SkPaint picturePaint;
1144 picturePaint.setXfermodeMode(WebCoreCompositeToSkiaComposite(op, blendMode)) ; 1150 picturePaint.setXfermodeMode(WebCoreCompositeToSkiaComposite(op, blendMode)) ;
1145 picturePaint.setImageFilter(matrixFilter.get()); 1151 SkRect sourceBounds = WebCoreFloatRectToSKRect(src);
1146 SkRect layerBounds = SkRect::MakeWH(std::max(deviceDest.width(), sourceBound s.width()), std::max(deviceDest.height(), sourceBounds.height())); 1152 if (pictureScaleIsApproximatelyOne(scaleX * m_deviceScaleFactor) && pictureS caleIsApproximatelyOne(scaleY * m_deviceScaleFactor)) {
Stephen White 2014/10/16 17:38:00 I'm not certain, but I think that using the device
1147 m_canvas->save(); 1153 // Fast path for canvases that are rasterized at screen resolution
1148 m_canvas->resetMatrix(); 1154 SkRect skBounds = WebCoreFloatRectToSKRect(dest);
1149 m_canvas->translate(deviceDest.x(), deviceDest.y()); 1155 m_canvas->saveLayer(&skBounds, &picturePaint);
1150 m_canvas->saveLayer(&layerBounds, &picturePaint); 1156 SkMatrix pictureTransform;
1151 m_canvas->restore(); 1157 pictureTransform.setRectToRect(sourceBounds, skBounds, SkMatrix::kFill_S caleToFit);
1152 m_canvas->restore(); 1158 m_canvas->concat(pictureTransform);
1159 m_canvas->drawPicture(picture.get());
1160 m_canvas->restore();
1161 } else {
1162 RefPtr<SkPictureImageFilter> pictureFilter = adoptRef(SkPictureImageFilt er::Create(picture.get(), sourceBounds));
1163 SkMatrix layerScale;
1164 layerScale.setScale(scaleX, scaleY);
1165 RefPtr<SkMatrixImageFilter> matrixFilter = adoptRef(SkMatrixImageFilter: :Create(layerScale, SkPaint::kLow_FilterLevel, pictureFilter.get()));
1166 picturePaint.setImageFilter(matrixFilter.get());
1167 SkRect layerBounds = SkRect::MakeWH(std::max(deviceDest.width(), sourceB ounds.width()), std::max(deviceDest.height(), sourceBounds.height()));
1168 m_canvas->save();
1169 m_canvas->resetMatrix();
1170 m_canvas->translate(deviceDest.x(), deviceDest.y());
1171 m_canvas->saveLayer(&layerBounds, &picturePaint);
1172 m_canvas->restore();
1173 m_canvas->restore();
1174 }
1153 } 1175 }
1154 1176
1155 void GraphicsContext::writePixels(const SkImageInfo& info, const void* pixels, s ize_t rowBytes, int x, int y) 1177 void GraphicsContext::writePixels(const SkImageInfo& info, const void* pixels, s ize_t rowBytes, int x, int y)
1156 { 1178 {
1157 ASSERT(m_canvas); 1179 ASSERT(m_canvas);
1158 if (contextDisabled()) 1180 if (contextDisabled())
1159 return; 1181 return;
1160 1182
1161 m_canvas->writePixels(info, pixels, rowBytes, x, y); 1183 m_canvas->writePixels(info, pixels, rowBytes, x, y);
1162 1184
(...skipping 821 matching lines...) Expand 10 before | Expand all | Expand 10 after
1984 // FIXME: This is to not break tests (it results in the filter bitmap fl ag 2006 // FIXME: This is to not break tests (it results in the filter bitmap fl ag
1985 // being set to true). We need to decide if we respect InterpolationNone 2007 // being set to true). We need to decide if we respect InterpolationNone
1986 // being returned from computeInterpolationQuality. 2008 // being returned from computeInterpolationQuality.
1987 resampling = InterpolationLow; 2009 resampling = InterpolationLow;
1988 } 2010 }
1989 resampling = limitInterpolationQuality(this, resampling); 2011 resampling = limitInterpolationQuality(this, resampling);
1990 paint->setFilterLevel(static_cast<SkPaint::FilterLevel>(resampling)); 2012 paint->setFilterLevel(static_cast<SkPaint::FilterLevel>(resampling));
1991 } 2013 }
1992 2014
1993 } // namespace blink 2015 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698