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

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: pdr corrections + needsrebaselines 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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 oneTileRect.setY(destRect.y() + fmodf(fmodf(-srcPoint.y(), actualTileSize.he ight()) - actualTileSize.height(), actualTileSize.height())); 146 oneTileRect.setY(destRect.y() + fmodf(fmodf(-srcPoint.y(), actualTileSize.he ight()) - actualTileSize.height(), actualTileSize.height()));
147 oneTileRect.setSize(scaledTileSize); 147 oneTileRect.setSize(scaledTileSize);
148 148
149 // Check and see if a single draw of the image can cover the entire area we are supposed to tile. 149 // 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)) { 150 if (oneTileRect.contains(destRect)) {
151 FloatRect visibleSrcRect; 151 FloatRect visibleSrcRect;
152 visibleSrcRect.setX((destRect.x() - oneTileRect.x()) / scale.width()); 152 visibleSrcRect.setX((destRect.x() - oneTileRect.x()) / scale.width());
153 visibleSrcRect.setY((destRect.y() - oneTileRect.y()) / scale.height()); 153 visibleSrcRect.setY((destRect.y() - oneTileRect.y()) / scale.height());
154 visibleSrcRect.setWidth(destRect.width() / scale.width()); 154 visibleSrcRect.setWidth(destRect.width() / scale.width());
155 visibleSrcRect.setHeight(destRect.height() / scale.height()); 155 visibleSrcRect.setHeight(destRect.height() / scale.height());
156 draw(ctxt, destRect, visibleSrcRect, op, DoNotRespectImageOrientation); 156 ctxt->drawImage(this, destRect, visibleSrcRect, op, DoNotRespectImageOri entation);
157 return; 157 return;
158 } 158 }
159 159
160 FloatRect tileRect(FloatPoint(), intrinsicTileSize); 160 FloatRect tileRect(FloatPoint(), intrinsicTileSize);
161 drawPattern(ctxt, tileRect, scale, oneTileRect.location(), op, destRect, rep eatSpacing); 161 drawPattern(ctxt, tileRect, scale, oneTileRect.location(), op, destRect, rep eatSpacing);
162 162
163 startAnimation(); 163 startAnimation();
164 } 164 }
165 165
166 // FIXME: Merge with the other drawTiled eventually, since we need a combination of both for some things. 166 // 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(); 272 const float adjustedY = phase.y() + normSrcRect.y() * scale.height();
273 localMatrix.setTranslate(SkFloatToScalar(adjustedX), SkFloatToScalar(adjuste dY)); 273 localMatrix.setTranslate(SkFloatToScalar(adjustedX), SkFloatToScalar(adjuste dY));
274 274
275 // Because no resizing occurred, the shader transform should be 275 // Because no resizing occurred, the shader transform should be
276 // set to the pattern's transform, which just includes scale. 276 // set to the pattern's transform, which just includes scale.
277 localMatrix.preScale(scale.width(), scale.height()); 277 localMatrix.preScale(scale.width(), scale.height());
278 278
279 SkBitmap bitmapToPaint; 279 SkBitmap bitmapToPaint;
280 bitmap.extractSubset(&bitmapToPaint, enclosingIntRect(normSrcRect)); 280 bitmap.extractSubset(&bitmapToPaint, enclosingIntRect(normSrcRect));
281 281
282 bool isLazyDecoded = DeferredImageDecoder::isLazyDecoded(bitmap);
283 { 282 {
284 SkPaint paint; 283 SkPaint paint = context->fillPaint();
285 int initialSaveCount = context->preparePaintForDrawRectToRect(&paint, fl oatSrcRect, 284 paint.setColor(SK_ColorBLACK);
286 destRect, compositeOp, !bitmap.isOpaque(), isLazyDecoded, bitmap.isI mmutable()); 285 paint.setXfermodeMode(compositeOp);
286 GraphicsContextImageFilterQualityHelper filterHelper(context);
287 paint.setFilterQuality(filterHelper.computeFilterQuality(this, destRect, normSrcRect));
288 paint.setAntiAlias(filterHelper.shouldDrawAntiAliased(destRect));
287 RefPtr<SkShader> shader = createPatternShader(bitmapToPaint, localMatrix , paint, 289 RefPtr<SkShader> shader = createPatternShader(bitmapToPaint, localMatrix , paint,
288 FloatSize(repeatSpacing.width() / scale.width(), repeatSpacing.heigh t() / scale.height())); 290 FloatSize(repeatSpacing.width() / scale.width(), repeatSpacing.heigh t() / scale.height()));
289
290 paint.setShader(shader.get()); 291 paint.setShader(shader.get());
291 context->drawRect(destRect, paint); 292 context->drawRect(destRect, paint);
292 context->canvas()->restoreToCount(initialSaveCount);
293 } 293 }
294 294
295 if (isLazyDecoded) 295 if (DeferredImageDecoder::isLazyDecoded(bitmap))
296 PlatformInstrumentation::didDrawLazyPixelRef(bitmap.getGenerationID()); 296 PlatformInstrumentation::didDrawLazyPixelRef(bitmap.getGenerationID());
297 } 297 }
298 298
299 void Image::computeIntrinsicDimensions(Length& intrinsicWidth, Length& intrinsic Height, FloatSize& intrinsicRatio) 299 void Image::computeIntrinsicDimensions(Length& intrinsicWidth, Length& intrinsic Height, FloatSize& intrinsicRatio)
300 { 300 {
301 intrinsicRatio = size(); 301 intrinsicRatio = size();
302 intrinsicWidth = Length(intrinsicRatio.width(), Fixed); 302 intrinsicWidth = Length(intrinsicRatio.width(), Fixed);
303 intrinsicHeight = Length(intrinsicRatio.height(), Fixed); 303 intrinsicHeight = Length(intrinsicRatio.height(), Fixed);
304 } 304 }
305 305
306 PassRefPtr<Image> Image::imageForDefaultFrame() 306 PassRefPtr<Image> Image::imageForDefaultFrame()
307 { 307 {
308 RefPtr<Image> image(this); 308 RefPtr<Image> image(this);
309 309
310 return image.release(); 310 return image.release();
311 } 311 }
312 312
313 bool Image::bitmapForCurrentFrame(SkBitmap* bitmap) 313 bool Image::bitmapForCurrentFrame(SkBitmap* bitmap)
314 { 314 {
315 return false; 315 return false;
316 } 316 }
317 317
318 PassRefPtr<SkImage> Image::skImage() 318 PassRefPtr<SkImage> Image::skImage()
319 { 319 {
320 return nullptr; 320 return nullptr;
321 } 321 }
322 322
323 } // namespace blink 323 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698