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

Side by Side Diff: Source/platform/DragImage.cpp

Issue 1001703003: Take NativeImageSkia out behind the woodshed. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Make bitmapForCurrentFrame() return SkBitmap by value. 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2007 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 23 matching lines...) Expand all
34 #include "platform/geometry/FloatPoint.h" 34 #include "platform/geometry/FloatPoint.h"
35 #include "platform/geometry/FloatRect.h" 35 #include "platform/geometry/FloatRect.h"
36 #include "platform/geometry/IntPoint.h" 36 #include "platform/geometry/IntPoint.h"
37 #include "platform/graphics/BitmapImage.h" 37 #include "platform/graphics/BitmapImage.h"
38 #include "platform/graphics/Color.h" 38 #include "platform/graphics/Color.h"
39 #include "platform/graphics/GraphicsContext.h" 39 #include "platform/graphics/GraphicsContext.h"
40 #include "platform/graphics/Image.h" 40 #include "platform/graphics/Image.h"
41 #include "platform/graphics/ImageBuffer.h" 41 #include "platform/graphics/ImageBuffer.h"
42 #include "platform/graphics/paint/DisplayItemList.h" 42 #include "platform/graphics/paint/DisplayItemList.h"
43 #include "platform/graphics/paint/DrawingRecorder.h" 43 #include "platform/graphics/paint/DrawingRecorder.h"
44 #include "platform/graphics/skia/NativeImageSkia.h"
45 #include "platform/text/BidiTextRun.h" 44 #include "platform/text/BidiTextRun.h"
46 #include "platform/text/StringTruncator.h" 45 #include "platform/text/StringTruncator.h"
47 #include "platform/text/TextRun.h" 46 #include "platform/text/TextRun.h"
48 #include "platform/transforms/AffineTransform.h" 47 #include "platform/transforms/AffineTransform.h"
49 #include "platform/weborigin/KURL.h" 48 #include "platform/weborigin/KURL.h"
50 #include "skia/ext/image_operations.h" 49 #include "skia/ext/image_operations.h"
51 #include "third_party/skia/include/core/SkCanvas.h" 50 #include "third_party/skia/include/core/SkCanvas.h"
52 #include "third_party/skia/include/core/SkColor.h" 51 #include "third_party/skia/include/core/SkColor.h"
53 #include "third_party/skia/include/core/SkMatrix.h" 52 #include "third_party/skia/include/core/SkMatrix.h"
54 #include "wtf/PassOwnPtr.h" 53 #include "wtf/PassOwnPtr.h"
(...skipping 13 matching lines...) Expand all
68 const float kMaxDragLabelStringWidth = (kMaxDragLabelWidth - 2 * kDragLabelBorde rX); 67 const float kMaxDragLabelStringWidth = (kMaxDragLabelWidth - 2 * kDragLabelBorde rX);
69 68
70 const float kDragLinkLabelFontSize = 11; 69 const float kDragLinkLabelFontSize = 11;
71 const float kDragLinkUrlFontSize = 10; 70 const float kDragLinkUrlFontSize = 10;
72 71
73 PassOwnPtr<DragImage> DragImage::create(Image* image, RespectImageOrientationEnu m shouldRespectImageOrientation, float deviceScaleFactor, InterpolationQuality i nterpolationQuality) 72 PassOwnPtr<DragImage> DragImage::create(Image* image, RespectImageOrientationEnu m shouldRespectImageOrientation, float deviceScaleFactor, InterpolationQuality i nterpolationQuality)
74 { 73 {
75 if (!image) 74 if (!image)
76 return nullptr; 75 return nullptr;
77 76
78 RefPtr<NativeImageSkia> bitmap = image->nativeImageForCurrentFrame(); 77 SkBitmap bitmap = image->bitmapForCurrentFrame();
79 if (!bitmap) 78 if (bitmap.isNull())
80 return nullptr; 79 return nullptr;
81 80
82 if (image->isBitmapImage()) { 81 if (image->isBitmapImage()) {
83 ImageOrientation orientation = DefaultImageOrientation; 82 ImageOrientation orientation = DefaultImageOrientation;
84 BitmapImage* bitmapImage = toBitmapImage(image); 83 BitmapImage* bitmapImage = toBitmapImage(image);
85 IntSize sizeRespectingOrientation = bitmapImage->sizeRespectingOrientati on(); 84 IntSize sizeRespectingOrientation = bitmapImage->sizeRespectingOrientati on();
86 85
87 if (shouldRespectImageOrientation == RespectImageOrientation) 86 if (shouldRespectImageOrientation == RespectImageOrientation)
88 orientation = bitmapImage->currentFrameOrientation(); 87 orientation = bitmapImage->currentFrameOrientation();
89 88
90 if (orientation != DefaultImageOrientation) { 89 if (orientation != DefaultImageOrientation) {
91 FloatRect destRect(FloatPoint(), sizeRespectingOrientation); 90 FloatRect destRect(FloatPoint(), sizeRespectingOrientation);
92 if (orientation.usesWidthAsHeight()) 91 if (orientation.usesWidthAsHeight())
93 destRect = destRect.transposedRect(); 92 destRect = destRect.transposedRect();
94 93
95 SkBitmap skBitmap; 94 SkBitmap skBitmap;
96 if (!skBitmap.tryAllocN32Pixels(sizeRespectingOrientation.width(), s izeRespectingOrientation.height())) 95 if (!skBitmap.tryAllocN32Pixels(sizeRespectingOrientation.width(), s izeRespectingOrientation.height()))
97 return nullptr; 96 return nullptr;
98 97
99 skBitmap.eraseColor(SK_ColorTRANSPARENT); 98 skBitmap.eraseColor(SK_ColorTRANSPARENT);
100 SkCanvas canvas(skBitmap); 99 SkCanvas canvas(skBitmap);
101 canvas.concat(affineTransformToSkMatrix(orientation.transformFromDef ault(sizeRespectingOrientation))); 100 canvas.concat(affineTransformToSkMatrix(orientation.transformFromDef ault(sizeRespectingOrientation)));
102 canvas.drawBitmapRect(bitmap->bitmap(), 0, destRect); 101 canvas.drawBitmapRect(bitmap, 0, destRect);
103 102
104 return adoptPtr(new DragImage(skBitmap, deviceScaleFactor, interpola tionQuality)); 103 return adoptPtr(new DragImage(skBitmap, deviceScaleFactor, interpola tionQuality));
105 } 104 }
106 } 105 }
107 106
108 SkBitmap skBitmap; 107 SkBitmap skBitmap;
109 if (!bitmap->bitmap().copyTo(&skBitmap, kN32_SkColorType)) 108 if (!bitmap.copyTo(&skBitmap, kN32_SkColorType))
110 return nullptr; 109 return nullptr;
111 return adoptPtr(new DragImage(skBitmap, deviceScaleFactor, interpolationQual ity)); 110 return adoptPtr(new DragImage(skBitmap, deviceScaleFactor, interpolationQual ity));
112 } 111 }
113 112
114 static Font deriveDragLabelFont(int size, FontWeight fontWeight, const FontDescr iption& systemFont) 113 static Font deriveDragLabelFont(int size, FontWeight fontWeight, const FontDescr iption& systemFont)
115 { 114 {
116 FontDescription description = systemFont; 115 FontDescription description = systemFont;
117 description.setWeight(fontWeight); 116 description.setWeight(fontWeight);
118 description.setSpecifiedSize(size); 117 description.setSpecifiedSize(size);
119 description.setComputedSize(size); 118 description.setComputedSize(size);
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 *pixel = SkPreMultiplyARGB( 289 *pixel = SkPreMultiplyARGB(
291 SkColorGetA(*pixel) * fraction, 290 SkColorGetA(*pixel) * fraction,
292 SkColorGetR(*pixel), 291 SkColorGetR(*pixel),
293 SkColorGetG(*pixel), 292 SkColorGetG(*pixel),
294 SkColorGetB(*pixel)); 293 SkColorGetB(*pixel));
295 } 294 }
296 } 295 }
297 } 296 }
298 297
299 } // namespace blink 298 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698