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

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

Issue 1008243003: Nuke NativeImageSkia -- new version. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Add more WARN_UNUSED_RETURN goodness Created 5 years, 9 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 | « Source/platform/graphics/Image.h ('k') | Source/platform/graphics/ImageBuffer.cpp » ('j') | 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) 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 11 matching lines...) Expand all
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */ 25 */
26 26
27 #include "config.h" 27 #include "config.h"
28 #include "platform/graphics/Image.h" 28 #include "platform/graphics/Image.h"
29 29
30 #include "platform/Length.h" 30 #include "platform/Length.h"
31 #include "platform/MIMETypeRegistry.h" 31 #include "platform/MIMETypeRegistry.h"
32 #include "platform/PlatformInstrumentation.h"
33 #include "platform/RuntimeEnabledFeatures.h"
32 #include "platform/SharedBuffer.h" 34 #include "platform/SharedBuffer.h"
33 #include "platform/TraceEvent.h" 35 #include "platform/TraceEvent.h"
34 #include "platform/geometry/FloatPoint.h" 36 #include "platform/geometry/FloatPoint.h"
35 #include "platform/geometry/FloatRect.h" 37 #include "platform/geometry/FloatRect.h"
36 #include "platform/geometry/FloatSize.h" 38 #include "platform/geometry/FloatSize.h"
37 #include "platform/graphics/BitmapImage.h" 39 #include "platform/graphics/BitmapImage.h"
40 #include "platform/graphics/DeferredImageDecoder.h"
38 #include "platform/graphics/GraphicsContext.h" 41 #include "platform/graphics/GraphicsContext.h"
39 #include "platform/graphics/GraphicsContextStateSaver.h" 42 #include "platform/graphics/GraphicsContextStateSaver.h"
40 #include "public/platform/Platform.h" 43 #include "public/platform/Platform.h"
41 #include "public/platform/WebData.h" 44 #include "public/platform/WebData.h"
45 #include "third_party/skia/include/core/SkCanvas.h"
42 #include "third_party/skia/include/core/SkImage.h" 46 #include "third_party/skia/include/core/SkImage.h"
43 #include "wtf/MainThread.h" 47 #include "wtf/MainThread.h"
44 #include "wtf/StdLibExtras.h" 48 #include "wtf/StdLibExtras.h"
45 49
46 #include <math.h> 50 #include <math.h>
47 51
48 namespace blink { 52 namespace blink {
49 53
50 Image::Image(ImageObserver* observer) 54 Image::Image(ImageObserver* observer)
51 : m_imageObserver(observer) 55 : m_imageObserver(observer)
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 ctxt->setImageInterpolationQuality(InterpolationLow); 215 ctxt->setImageInterpolationQuality(InterpolationLow);
212 drawPattern(ctxt, srcRect, tileScaleFactor, patternPhase, op, dstRect); 216 drawPattern(ctxt, srcRect, tileScaleFactor, patternPhase, op, dstRect);
213 ctxt->setImageInterpolationQuality(previousInterpolationQuality); 217 ctxt->setImageInterpolationQuality(previousInterpolationQuality);
214 } else { 218 } else {
215 drawPattern(ctxt, srcRect, tileScaleFactor, patternPhase, op, dstRect); 219 drawPattern(ctxt, srcRect, tileScaleFactor, patternPhase, op, dstRect);
216 } 220 }
217 221
218 startAnimation(); 222 startAnimation();
219 } 223 }
220 224
225 static SkBitmap createBitmapWithSpace(const SkBitmap& bitmap, int spaceWidth, in t spaceHeight)
226 {
227 SkImageInfo info = bitmap.info();
228 info = SkImageInfo::Make(info.width() + spaceWidth, info.height() + spaceHei ght, info.colorType(), kPremul_SkAlphaType);
229
230 SkBitmap result;
231 result.allocPixels(info);
232 result.eraseColor(SK_ColorTRANSPARENT);
233 bitmap.copyPixelsTo(reinterpret_cast<uint8_t*>(result.getPixels()), result.r owBytes() * result.height(), result.rowBytes());
234
235 return result;
236 }
237
221 void Image::drawPattern(GraphicsContext* context, const FloatRect& floatSrcRect, const FloatSize& scale, 238 void Image::drawPattern(GraphicsContext* context, const FloatRect& floatSrcRect, const FloatSize& scale,
222 const FloatPoint& phase, SkXfermode::Mode op, const FloatRect& destRect, con st IntSize& repeatSpacing) 239 const FloatPoint& phase, SkXfermode::Mode compositeOp, const FloatRect& dest Rect, const IntSize& repeatSpacing)
223 { 240 {
224 TRACE_EVENT0("skia", "Image::drawPattern"); 241 TRACE_EVENT0("skia", "Image::drawPattern");
225 if (RefPtr<NativeImageSkia> bitmap = nativeImageForCurrentFrame()) 242 SkBitmap bitmap;
226 bitmap->drawPattern(context, adjustForNegativeSize(floatSrcRect), scale, phase, op, destRect, repeatSpacing); 243 if (!bitmapForCurrentFrame(&bitmap))
244 return;
245
246 FloatRect normSrcRect = floatSrcRect;
247
248 normSrcRect.intersect(FloatRect(0, 0, bitmap.width(), bitmap.height()));
249 if (destRect.isEmpty() || normSrcRect.isEmpty())
250 return; // nothing to draw
251
252 SkMatrix localMatrix;
253 // We also need to translate it such that the origin of the pattern is the
254 // origin of the destination rect, which is what WebKit expects. Skia uses
255 // the coordinate system origin as the base for the pattern. If WebKit wants
256 // a shifted image, it will shift it from there using the localMatrix.
257 const float adjustedX = phase.x() + normSrcRect.x() * scale.width();
258 const float adjustedY = phase.y() + normSrcRect.y() * scale.height();
259 localMatrix.setTranslate(SkFloatToScalar(adjustedX), SkFloatToScalar(adjuste dY));
260
261 // Because no resizing occurred, the shader transform should be
262 // set to the pattern's transform, which just includes scale.
263 localMatrix.preScale(scale.width(), scale.height());
264
265 SkBitmap bitmapToPaint;
266 bitmap.extractSubset(&bitmapToPaint, enclosingIntRect(normSrcRect));
267 if (!repeatSpacing.isZero()) {
268 SkScalar ctmScaleX = 1.0;
269 SkScalar ctmScaleY = 1.0;
270
271 if (!RuntimeEnabledFeatures::slimmingPaintEnabled()) {
272 AffineTransform ctm = context->getCTM();
273 ctmScaleX = ctm.xScale();
274 ctmScaleY = ctm.yScale();
275 }
276
277 bitmapToPaint = createBitmapWithSpace(
278 bitmapToPaint,
279 repeatSpacing.width() * ctmScaleX / scale.width(),
280 repeatSpacing.height() * ctmScaleY / scale.height());
281 }
282 RefPtr<SkShader> shader = adoptRef(SkShader::CreateBitmapShader(bitmapToPain t, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &localMatrix));
283
284 bool isLazyDecoded = DeferredImageDecoder::isLazyDecoded(bitmap);
285 {
286 SkPaint paint;
287 int initialSaveCount = context->preparePaintForDrawRectToRect(&paint, fl oatSrcRect,
288 destRect, compositeOp, !bitmap.isOpaque(), isLazyDecoded, bitmap.isI mmutable());
289 paint.setShader(shader.get());
290 context->drawRect(destRect, paint);
291 context->canvas()->restoreToCount(initialSaveCount);
292 }
293
294 if (isLazyDecoded)
295 PlatformInstrumentation::didDrawLazyPixelRef(bitmap.getGenerationID());
227 } 296 }
228 297
229 void Image::computeIntrinsicDimensions(Length& intrinsicWidth, Length& intrinsic Height, FloatSize& intrinsicRatio) 298 void Image::computeIntrinsicDimensions(Length& intrinsicWidth, Length& intrinsic Height, FloatSize& intrinsicRatio)
230 { 299 {
231 intrinsicRatio = size(); 300 intrinsicRatio = size();
232 intrinsicWidth = Length(intrinsicRatio.width(), Fixed); 301 intrinsicWidth = Length(intrinsicRatio.width(), Fixed);
233 intrinsicHeight = Length(intrinsicRatio.height(), Fixed); 302 intrinsicHeight = Length(intrinsicRatio.height(), Fixed);
234 } 303 }
235 304
236 PassRefPtr<Image> Image::imageForDefaultFrame() 305 PassRefPtr<Image> Image::imageForDefaultFrame()
237 { 306 {
238 RefPtr<Image> image(this); 307 RefPtr<Image> image(this);
239 308
240 return image.release(); 309 return image.release();
241 } 310 }
242 311
312 bool Image::bitmapForCurrentFrame(SkBitmap* bitmap)
313 {
314 return false;
315 }
316
243 PassRefPtr<SkImage> Image::skImage() 317 PassRefPtr<SkImage> Image::skImage()
244 { 318 {
245 return nullptr; 319 return nullptr;
246 } 320 }
247 321
248 } // namespace blink 322 } // namespace blink
OLDNEW
« no previous file with comments | « Source/platform/graphics/Image.h ('k') | Source/platform/graphics/ImageBuffer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698