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

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

Issue 1093673002: Removing the dependency on GraphicsContext for drawing images in 2D canvas (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebase Created 5 years, 6 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) 2 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
3 * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. All rights reserved. 3 * Copyright (C) 2004, 2005, 2006 Apple Computer, 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 void Image::fillWithSolidColor(GraphicsContext* ctxt, const FloatRect& dstRect, const Color& color, SkXfermode::Mode op) 100 void Image::fillWithSolidColor(GraphicsContext* ctxt, const FloatRect& dstRect, const Color& color, SkXfermode::Mode op)
101 { 101 {
102 if (!color.alpha()) 102 if (!color.alpha())
103 return; 103 return;
104 104
105 SkXfermode::Mode xferMode = !color.hasAlpha() && op == SkXfermode::kSrcOver_ Mode ? 105 SkXfermode::Mode xferMode = !color.hasAlpha() && op == SkXfermode::kSrcOver_ Mode ?
106 SkXfermode::kSrc_Mode : op; 106 SkXfermode::kSrc_Mode : op;
107 ctxt->fillRect(dstRect, color, xferMode); 107 ctxt->fillRect(dstRect, color, xferMode);
108 } 108 }
109 109
110 FloatRect Image::adjustForNegativeSize(const FloatRect& rect)
111 {
112 FloatRect norm = rect;
113 if (norm.width() < 0) {
114 norm.setX(norm.x() + norm.width());
115 norm.setWidth(-norm.width());
116 }
117 if (norm.height() < 0) {
118 norm.setY(norm.y() + norm.height());
119 norm.setHeight(-norm.height());
120 }
121 return norm;
122 }
123
124 void Image::drawTiled(GraphicsContext* ctxt, const FloatRect& destRect, const Fl oatPoint& srcPoint, const FloatSize& scaledTileSize, SkXfermode::Mode op, const IntSize& repeatSpacing) 110 void Image::drawTiled(GraphicsContext* ctxt, const FloatRect& destRect, const Fl oatPoint& srcPoint, const FloatSize& scaledTileSize, SkXfermode::Mode op, const IntSize& repeatSpacing)
125 { 111 {
126 if (mayFillWithSolidColor()) { 112 if (mayFillWithSolidColor()) {
127 fillWithSolidColor(ctxt, destRect, solidColor(), op); 113 fillWithSolidColor(ctxt, destRect, solidColor(), op);
128 return; 114 return;
129 } 115 }
130 116
131 // See <https://webkit.org/b/59043>. 117 // See <https://webkit.org/b/59043>.
132 ASSERT(!isBitmapImage() || notSolidColor()); 118 ASSERT(!isBitmapImage() || notSolidColor());
133 119
(...skipping 12 matching lines...) Expand all
146 oneTileRect.setY(destRect.y() + fmodf(fmodf(-srcPoint.y(), actualTileSize.he ight()) - actualTileSize.height(), actualTileSize.height())); 132 oneTileRect.setY(destRect.y() + fmodf(fmodf(-srcPoint.y(), actualTileSize.he ight()) - actualTileSize.height(), actualTileSize.height()));
147 oneTileRect.setSize(scaledTileSize); 133 oneTileRect.setSize(scaledTileSize);
148 134
149 // Check and see if a single draw of the image can cover the entire area we are supposed to tile. 135 // Check and see if a single draw of the image can cover the entire area we are supposed to tile.
150 if (oneTileRect.contains(destRect)) { 136 if (oneTileRect.contains(destRect)) {
151 FloatRect visibleSrcRect; 137 FloatRect visibleSrcRect;
152 visibleSrcRect.setX((destRect.x() - oneTileRect.x()) / scale.width()); 138 visibleSrcRect.setX((destRect.x() - oneTileRect.x()) / scale.width());
153 visibleSrcRect.setY((destRect.y() - oneTileRect.y()) / scale.height()); 139 visibleSrcRect.setY((destRect.y() - oneTileRect.y()) / scale.height());
154 visibleSrcRect.setWidth(destRect.width() / scale.width()); 140 visibleSrcRect.setWidth(destRect.width() / scale.width());
155 visibleSrcRect.setHeight(destRect.height() / scale.height()); 141 visibleSrcRect.setHeight(destRect.height() / scale.height());
156 draw(ctxt, destRect, visibleSrcRect, op, DoNotRespectImageOrientation); 142 ctxt->drawImage(this, destRect, visibleSrcRect, op, DoNotRespectImageOri entation);
157 return; 143 return;
158 } 144 }
159 145
160 FloatRect tileRect(FloatPoint(), intrinsicTileSize); 146 FloatRect tileRect(FloatPoint(), intrinsicTileSize);
161 drawPattern(ctxt, tileRect, scale, oneTileRect.location(), op, destRect, rep eatSpacing); 147 drawPattern(ctxt, tileRect, scale, oneTileRect.location(), op, destRect, rep eatSpacing);
162 148
163 startAnimation(); 149 startAnimation();
164 } 150 }
165 151
166 // FIXME: Merge with the other drawTiled eventually, since we need a combination of both for some things. 152 // FIXME: Merge with the other drawTiled eventually, since we need a combination of both for some things.
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 const float adjustedY = phase.y() + normSrcRect.y() * scale.height(); 258 const float adjustedY = phase.y() + normSrcRect.y() * scale.height();
273 localMatrix.setTranslate(SkFloatToScalar(adjustedX), SkFloatToScalar(adjuste dY)); 259 localMatrix.setTranslate(SkFloatToScalar(adjustedX), SkFloatToScalar(adjuste dY));
274 260
275 // Because no resizing occurred, the shader transform should be 261 // Because no resizing occurred, the shader transform should be
276 // set to the pattern's transform, which just includes scale. 262 // set to the pattern's transform, which just includes scale.
277 localMatrix.preScale(scale.width(), scale.height()); 263 localMatrix.preScale(scale.width(), scale.height());
278 264
279 SkBitmap bitmapToPaint; 265 SkBitmap bitmapToPaint;
280 bitmap.extractSubset(&bitmapToPaint, enclosingIntRect(normSrcRect)); 266 bitmap.extractSubset(&bitmapToPaint, enclosingIntRect(normSrcRect));
281 267
282 bool isLazyDecoded = DeferredImageDecoder::isLazyDecoded(bitmap);
283 { 268 {
284 SkPaint paint; 269 SkPaint paint = context->fillPaint();
285 int initialSaveCount = context->preparePaintForDrawRectToRect(&paint, fl oatSrcRect, 270 paint.setColor(SK_ColorBLACK);
286 destRect, compositeOp, !bitmap.isOpaque(), isLazyDecoded, bitmap.isI mmutable()); 271 paint.setXfermodeMode(compositeOp);
272 paint.setFilterQuality(context->computeFilterQuality(this, destRect, nor mSrcRect));
273 paint.setAntiAlias(context->shouldAntialiasImages());
287 RefPtr<SkShader> shader = createPatternShader(bitmapToPaint, localMatrix , paint, 274 RefPtr<SkShader> shader = createPatternShader(bitmapToPaint, localMatrix , paint,
288 FloatSize(repeatSpacing.width() / scale.width(), repeatSpacing.heigh t() / scale.height())); 275 FloatSize(repeatSpacing.width() / scale.width(), repeatSpacing.heigh t() / scale.height()));
289
290 paint.setShader(shader.get()); 276 paint.setShader(shader.get());
291 context->drawRect(destRect, paint); 277 context->drawRect(destRect, paint);
292 context->canvas()->restoreToCount(initialSaveCount);
293 } 278 }
294 279
295 if (isLazyDecoded) 280 if (DeferredImageDecoder::isLazyDecoded(bitmap))
296 PlatformInstrumentation::didDrawLazyPixelRef(bitmap.getGenerationID()); 281 PlatformInstrumentation::didDrawLazyPixelRef(bitmap.getGenerationID());
297 } 282 }
298 283
299 void Image::computeIntrinsicDimensions(Length& intrinsicWidth, Length& intrinsic Height, FloatSize& intrinsicRatio) 284 void Image::computeIntrinsicDimensions(Length& intrinsicWidth, Length& intrinsic Height, FloatSize& intrinsicRatio)
300 { 285 {
301 intrinsicRatio = size(); 286 intrinsicRatio = size();
302 intrinsicWidth = Length(intrinsicRatio.width(), Fixed); 287 intrinsicWidth = Length(intrinsicRatio.width(), Fixed);
303 intrinsicHeight = Length(intrinsicRatio.height(), Fixed); 288 intrinsicHeight = Length(intrinsicRatio.height(), Fixed);
304 } 289 }
305 290
306 PassRefPtr<Image> Image::imageForDefaultFrame() 291 PassRefPtr<Image> Image::imageForDefaultFrame()
307 { 292 {
308 RefPtr<Image> image(this); 293 RefPtr<Image> image(this);
309 294
310 return image.release(); 295 return image.release();
311 } 296 }
312 297
313 bool Image::bitmapForCurrentFrame(SkBitmap* bitmap) 298 bool Image::bitmapForCurrentFrame(SkBitmap* bitmap)
314 { 299 {
315 return false; 300 return false;
316 } 301 }
317 302
318 PassRefPtr<SkImage> Image::skImage() 303 PassRefPtr<SkImage> Image::skImage()
319 { 304 {
320 return nullptr; 305 return nullptr;
321 } 306 }
322 307
323 } // namespace blink 308 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698