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

Side by Side Diff: third_party/WebKit/Source/platform/graphics/ImageBufferSurface.cpp

Issue 1331533002: [poc] curve-filter Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix CanvasRenderingContext2D::createPattern crash for #40 Created 4 years, 11 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
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013, Google Inc. All rights reserved. 2 * Copyright (c) 2013, Google 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * 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 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 15 matching lines...) Expand all
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "platform/graphics/ImageBufferSurface.h" 31 #include "platform/graphics/ImageBufferSurface.h"
32 32
33 #include "platform/graphics/GraphicsContext.h" 33 #include "platform/graphics/GraphicsContext.h"
34 #include "platform/graphics/ImageBuffer.h" 34 #include "platform/graphics/ImageBuffer.h"
35 #include "platform/graphics/StaticBitmapImage.h" 35 #include "platform/graphics/StaticBitmapImage.h"
36 #include "third_party/skia/include/core/SkColorFilter.h"
36 #include "third_party/skia/include/core/SkImage.h" 37 #include "third_party/skia/include/core/SkImage.h"
37 38
38 class SkPicture; 39 class SkPicture;
39 40
40 namespace blink { 41 namespace blink {
41 42
42 ImageBufferSurface::ImageBufferSurface(const IntSize& size, OpacityMode opacityM ode) 43 ImageBufferSurface::ImageBufferSurface(const IntSize& size, OpacityMode opacityM ode)
43 : m_opacityMode(opacityMode) 44 : m_opacityMode(opacityMode)
44 , m_size(size) 45 , m_size(size)
45 { 46 {
46 setIsHidden(false); 47 setIsHidden(false);
47 } 48 }
48 49
49 ImageBufferSurface::~ImageBufferSurface() { } 50 ImageBufferSurface::~ImageBufferSurface() { }
50 51
51 PassRefPtr<SkPicture> ImageBufferSurface::getPicture() 52 PassRefPtr<SkPicture> ImageBufferSurface::getPicture()
52 { 53 {
53 return nullptr; 54 return nullptr;
54 } 55 }
55 56
56 void ImageBufferSurface::clear() 57 void ImageBufferSurface::clear()
57 { 58 {
58 // Clear the background transparent or opaque, as required. It would be nice if this wasn't 59 // Clear the background transparent or opaque, as required. It would be nice if this wasn't
59 // required, but the canvas is currently filled with the magic transparency 60 // required, but the canvas is currently filled with the magic transparency
60 // color. Can we have another way to manage this? 61 // color. Can we have another way to manage this?
61 if (isValid()) { 62 if (isValid()) {
62 if (m_opacityMode == Opaque) { 63 if (m_opacityMode == Opaque) {
63 canvas()->clear(SK_ColorBLACK); 64 canvas()->clear(SK_ColorBLACK); // FIXME: not color correct.
64 } else { 65 } else {
65 canvas()->clear(SK_ColorTRANSPARENT); 66 canvas()->clear(SK_ColorTRANSPARENT);
66 } 67 }
67 didDraw(FloatRect(FloatPoint(0, 0), FloatSize(size()))); 68 didDraw(FloatRect(FloatPoint(0, 0), FloatSize(size())));
68 } 69 }
69 } 70 }
70 71
71 void ImageBufferSurface::draw(GraphicsContext& context, const FloatRect& destRec t, const FloatRect& srcRect, SkXfermode::Mode op) 72 void ImageBufferSurface::draw(GraphicsContext& context, const FloatRect& destRec t, const FloatRect& srcRect, SkXfermode::Mode op, SkColorFilter* transform)
72 { 73 {
73 RefPtr<SkImage> snapshot = newImageSnapshot(PreferNoAcceleration); 74 RefPtr<SkImage> snapshot = newImageSnapshot(PreferNoAcceleration);
74 if (!snapshot) 75 if (!snapshot)
75 return; 76 return;
76 77
78 if (!transform) {
79 RefPtr<Image> image = StaticBitmapImage::create(snapshot.release());
80 context.drawImage(image.get(), destRect, srcRect, op);
81 return;
82 }
83
84 SkPaint transformPaint;
85 transformPaint.setColorFilter(transform);
86 transformPaint.setXfermodeMode(SkXfermode::kSrc_Mode);
87
88 SkPictureRecorder recorder;
89 FloatRect sourceRect = IntRect(0, 0, width(), height());
90 SkCanvas* canvas = recorder.beginRecording(sourceRect);
91 canvas->drawImage(snapshot.get(), 0, 0, &transformPaint);
92 RefPtr<SkPicture> recorded = adoptRef(recorder.endRecordingAsPicture());
93
94 SkISize size = SkISize::Make(width(), height());
95 snapshot = adoptRef(SkImage::NewFromPicture(recorded.get(), size, nullptr, n ullptr));
96
77 RefPtr<Image> image = StaticBitmapImage::create(snapshot.release()); 97 RefPtr<Image> image = StaticBitmapImage::create(snapshot.release());
78 context.drawImage(image.get(), destRect, srcRect, op); 98 context.drawImage(image.get(), destRect, srcRect, op);
79 } 99 }
80 100
81 void ImageBufferSurface::flush() 101 void ImageBufferSurface::flush()
82 { 102 {
83 canvas()->flush(); 103 canvas()->flush();
84 } 104 }
85 105
86 bool ImageBufferSurface::writePixels(const SkImageInfo& origInfo, const void* pi xels, size_t rowBytes, int x, int y) 106 bool ImageBufferSurface::writePixels(const SkImageInfo& origInfo, const void* pi xels, size_t rowBytes, int x, int y)
87 { 107 {
88 return canvas()->writePixels(origInfo, pixels, rowBytes, x, y); 108 return canvas()->writePixels(origInfo, pixels, rowBytes, x, y);
89 } 109 }
90 110
91 } // namespace blink 111 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698