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

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: skia-ism removed 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 #include "third_party/skia/include/effects/SkBlurMaskFilter.h" 52 #include "third_party/skia/include/effects/SkBlurMaskFilter.h"
53 #include "third_party/skia/include/effects/SkCornerPathEffect.h" 53 #include "third_party/skia/include/effects/SkCornerPathEffect.h"
54 #include "third_party/skia/include/effects/SkLumaColorFilter.h" 54 #include "third_party/skia/include/effects/SkLumaColorFilter.h"
55 #include "third_party/skia/include/effects/SkMatrixImageFilter.h" 55 #include "third_party/skia/include/effects/SkMatrixImageFilter.h"
56 #include "third_party/skia/include/effects/SkPictureImageFilter.h" 56 #include "third_party/skia/include/effects/SkPictureImageFilter.h"
57 #include "third_party/skia/include/gpu/GrRenderTarget.h" 57 #include "third_party/skia/include/gpu/GrRenderTarget.h"
58 #include "third_party/skia/include/gpu/GrTexture.h" 58 #include "third_party/skia/include/gpu/GrTexture.h"
59 #include "wtf/Assertions.h" 59 #include "wtf/Assertions.h"
60 #include "wtf/MathExtras.h" 60 #include "wtf/MathExtras.h"
61 61
62 namespace {
63
64 // Tolerance value use for comparing scale factor to 1..
65 // Numerical error should not reach 6th decimal except for highly degenerate cas es,
66 // and effect of 6th decimal on scale is negligible over max span of a skia canv as
67 // which is 32k pixels.
68 const float cPictureScaleEpsilon = 0.000001;
69
70 }
71
62 namespace blink { 72 namespace blink {
63 73
64 struct GraphicsContext::RecordingState { 74 struct GraphicsContext::RecordingState {
65 RecordingState(SkPictureRecorder* recorder, SkCanvas* currentCanvas, const S kMatrix& currentMatrix, bool currentShouldSmoothFonts, 75 RecordingState(SkPictureRecorder* recorder, SkCanvas* currentCanvas, const S kMatrix& currentMatrix, bool currentShouldSmoothFonts,
66 PassRefPtr<DisplayList> displayList, RegionTrackingMode trackingMode) 76 PassRefPtr<DisplayList> displayList, RegionTrackingMode trackingMode)
67 : m_displayList(displayList) 77 : m_displayList(displayList)
68 , m_recorder(recorder) 78 , m_recorder(recorder)
69 , m_savedCanvas(currentCanvas) 79 , m_savedCanvas(currentCanvas)
70 , m_savedMatrix(currentMatrix) 80 , m_savedMatrix(currentMatrix)
71 , m_savedShouldSmoothFonts(currentShouldSmoothFonts) 81 , m_savedShouldSmoothFonts(currentShouldSmoothFonts)
(...skipping 1046 matching lines...) Expand 10 before | Expand all | Expand 10 after
1118 1128
1119 void GraphicsContext::drawImageBuffer(ImageBuffer* image, const FloatRect& dest, 1129 void GraphicsContext::drawImageBuffer(ImageBuffer* image, const FloatRect& dest,
1120 const FloatRect* src, CompositeOperator op, WebBlendMode blendMode) 1130 const FloatRect* src, CompositeOperator op, WebBlendMode blendMode)
1121 { 1131 {
1122 if (contextDisabled() || !image) 1132 if (contextDisabled() || !image)
1123 return; 1133 return;
1124 1134
1125 image->draw(this, dest, src, op, blendMode); 1135 image->draw(this, dest, src, op, blendMode);
1126 } 1136 }
1127 1137
1138 static inline bool pictureScaleIsApproximatelyOne(float x)
1139 {
1140 return fabsf(x - 1.0f) < cPictureScaleEpsilon;
1141 }
1142
1128 void GraphicsContext::drawPicture(PassRefPtr<SkPicture> picture, const FloatRect & dest, const FloatRect& src, CompositeOperator op, WebBlendMode blendMode) 1143 void GraphicsContext::drawPicture(PassRefPtr<SkPicture> picture, const FloatRect & dest, const FloatRect& src, CompositeOperator op, WebBlendMode blendMode)
1129 { 1144 {
1130 ASSERT(m_canvas); 1145 ASSERT(m_canvas);
1131 if (contextDisabled() || !picture) 1146 if (contextDisabled() || !picture)
1132 return; 1147 return;
1133 1148
1134 SkMatrix ctm = m_canvas->getTotalMatrix(); 1149 SkMatrix ctm = m_canvas->getTotalMatrix();
1135 SkRect deviceDest; 1150 SkRect deviceDest;
1136 ctm.mapRect(&deviceDest, dest); 1151 ctm.mapRect(&deviceDest, dest);
1137 SkRect sourceBounds = WebCoreFloatRectToSKRect(src); 1152 float scaleX = deviceDest.width() / src.width();
1153 float scaleY = deviceDest.height() / src.height();
1138 1154
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; 1155 SkPaint picturePaint;
1144 picturePaint.setXfermodeMode(WebCoreCompositeToSkiaComposite(op, blendMode)) ; 1156 picturePaint.setXfermodeMode(WebCoreCompositeToSkiaComposite(op, blendMode)) ;
1145 picturePaint.setImageFilter(matrixFilter.get()); 1157 SkRect sourceBounds = WebCoreFloatRectToSKRect(src);
1146 SkRect layerBounds = SkRect::MakeWH(std::max(deviceDest.width(), sourceBound s.width()), std::max(deviceDest.height(), sourceBounds.height())); 1158 if (pictureScaleIsApproximatelyOne(scaleX * m_deviceScaleFactor) && pictureS caleIsApproximatelyOne(scaleY * m_deviceScaleFactor)) {
1147 m_canvas->save(); 1159 // Fast path for canvases that are rasterized at screen resolution
1148 m_canvas->resetMatrix(); 1160 SkRect skBounds = WebCoreFloatRectToSKRect(dest);
1149 m_canvas->translate(deviceDest.x(), deviceDest.y()); 1161 m_canvas->saveLayer(&skBounds, &picturePaint);
1150 m_canvas->saveLayer(&layerBounds, &picturePaint); 1162 SkMatrix pictureTransform;
1151 m_canvas->restore(); 1163 pictureTransform.setRectToRect(sourceBounds, skBounds, SkMatrix::kFill_S caleToFit);
1152 m_canvas->restore(); 1164 m_canvas->concat(pictureTransform);
1165 m_canvas->drawPicture(picture.get());
1166 m_canvas->restore();
1167 } else {
1168 RefPtr<SkPictureImageFilter> pictureFilter = adoptRef(SkPictureImageFilt er::Create(picture.get(), sourceBounds));
1169 SkMatrix layerScale;
1170 layerScale.setScale(scaleX, scaleY);
1171 RefPtr<SkMatrixImageFilter> matrixFilter = adoptRef(SkMatrixImageFilter: :Create(layerScale, SkPaint::kLow_FilterLevel, pictureFilter.get()));
1172 picturePaint.setImageFilter(matrixFilter.get());
1173 SkRect layerBounds = SkRect::MakeWH(std::max(deviceDest.width(), sourceB ounds.width()), std::max(deviceDest.height(), sourceBounds.height()));
1174 m_canvas->save();
1175 m_canvas->resetMatrix();
1176 m_canvas->translate(deviceDest.x(), deviceDest.y());
1177 m_canvas->saveLayer(&layerBounds, &picturePaint);
1178 m_canvas->restore();
1179 m_canvas->restore();
1180 }
1153 } 1181 }
1154 1182
1155 void GraphicsContext::writePixels(const SkImageInfo& info, const void* pixels, s ize_t rowBytes, int x, int y) 1183 void GraphicsContext::writePixels(const SkImageInfo& info, const void* pixels, s ize_t rowBytes, int x, int y)
1156 { 1184 {
1157 ASSERT(m_canvas); 1185 ASSERT(m_canvas);
1158 if (contextDisabled()) 1186 if (contextDisabled())
1159 return; 1187 return;
1160 1188
1161 m_canvas->writePixels(info, pixels, rowBytes, x, y); 1189 m_canvas->writePixels(info, pixels, rowBytes, x, y);
1162 1190
(...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 2012 // 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 2013 // being set to true). We need to decide if we respect InterpolationNone
1986 // being returned from computeInterpolationQuality. 2014 // being returned from computeInterpolationQuality.
1987 resampling = InterpolationLow; 2015 resampling = InterpolationLow;
1988 } 2016 }
1989 resampling = limitInterpolationQuality(this, resampling); 2017 resampling = limitInterpolationQuality(this, resampling);
1990 paint->setFilterLevel(static_cast<SkPaint::FilterLevel>(resampling)); 2018 paint->setFilterLevel(static_cast<SkPaint::FilterLevel>(resampling));
1991 } 2019 }
1992 2020
1993 } // namespace blink 2021 } // 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