OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2008, Google Inc. All rights reserved. | 2 * Copyright (c) 2008, Google Inc. All rights reserved. |
3 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> | 3 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> |
4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. | 4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. |
5 * | 5 * |
6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions are | 7 * modification, are permitted provided that the following conditions are |
8 * met: | 8 * met: |
9 * | 9 * |
10 * * Redistributions of source code must retain the above copyright | 10 * * Redistributions of source code must retain the above copyright |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 #include "platform/graphics/gpu/Extensions3DUtil.h" | 45 #include "platform/graphics/gpu/Extensions3DUtil.h" |
46 #include "platform/graphics/skia/NativeImageSkia.h" | 46 #include "platform/graphics/skia/NativeImageSkia.h" |
47 #include "platform/graphics/skia/SkiaUtils.h" | 47 #include "platform/graphics/skia/SkiaUtils.h" |
48 #include "platform/image-encoders/skia/JPEGImageEncoder.h" | 48 #include "platform/image-encoders/skia/JPEGImageEncoder.h" |
49 #include "platform/image-encoders/skia/PNGImageEncoder.h" | 49 #include "platform/image-encoders/skia/PNGImageEncoder.h" |
50 #include "platform/image-encoders/skia/WEBPImageEncoder.h" | 50 #include "platform/image-encoders/skia/WEBPImageEncoder.h" |
51 #include "public/platform/Platform.h" | 51 #include "public/platform/Platform.h" |
52 #include "public/platform/WebExternalTextureMailbox.h" | 52 #include "public/platform/WebExternalTextureMailbox.h" |
53 #include "public/platform/WebGraphicsContext3D.h" | 53 #include "public/platform/WebGraphicsContext3D.h" |
54 #include "public/platform/WebGraphicsContext3DProvider.h" | 54 #include "public/platform/WebGraphicsContext3DProvider.h" |
| 55 #include "third_party/skia/include/core/SkPicture.h" |
55 #include "third_party/skia/include/effects/SkTableColorFilter.h" | 56 #include "third_party/skia/include/effects/SkTableColorFilter.h" |
56 #include "wtf/MathExtras.h" | 57 #include "wtf/MathExtras.h" |
57 #include "wtf/text/Base64.h" | 58 #include "wtf/text/Base64.h" |
58 #include "wtf/text/WTFString.h" | 59 #include "wtf/text/WTFString.h" |
59 | 60 |
60 using namespace std; | 61 using namespace std; |
61 | 62 |
62 namespace WebCore { | 63 namespace WebCore { |
63 | 64 |
64 PassOwnPtr<ImageBuffer> ImageBuffer::create(PassOwnPtr<ImageBufferSurface> surfa
ce) | 65 PassOwnPtr<ImageBuffer> ImageBuffer::create(PassOwnPtr<ImageBufferSurface> surfa
ce) |
65 { | 66 { |
66 if (!surface->isValid()) | 67 if (!surface->isValid()) |
67 return nullptr; | 68 return nullptr; |
68 return adoptPtr(new ImageBuffer(surface)); | 69 return adoptPtr(new ImageBuffer(surface)); |
69 } | 70 } |
70 | 71 |
71 PassOwnPtr<ImageBuffer> ImageBuffer::create(const IntSize& size, OpacityMode opa
cityMode) | 72 PassOwnPtr<ImageBuffer> ImageBuffer::create(const IntSize& size, OpacityMode opa
cityMode) |
72 { | 73 { |
73 OwnPtr<ImageBufferSurface> surface = adoptPtr(new UnacceleratedImageBufferSu
rface(size, opacityMode)); | 74 OwnPtr<ImageBufferSurface> surface = adoptPtr(new UnacceleratedImageBufferSu
rface(size, opacityMode)); |
74 if (!surface->isValid()) | 75 if (!surface->isValid()) |
75 return nullptr; | 76 return nullptr; |
76 return adoptPtr(new ImageBuffer(surface.release())); | 77 return adoptPtr(new ImageBuffer(surface.release())); |
77 } | 78 } |
78 | 79 |
79 ImageBuffer::ImageBuffer(PassOwnPtr<ImageBufferSurface> surface) | 80 ImageBuffer::ImageBuffer(PassOwnPtr<ImageBufferSurface> surface) |
80 : m_surface(surface) | 81 : m_surface(surface) |
81 , m_client(0) | 82 , m_client(0) |
82 { | 83 { |
83 m_surface->setImageBuffer(this); | |
84 if (m_surface->canvas()) { | 84 if (m_surface->canvas()) { |
85 m_context = adoptPtr(new GraphicsContext(m_surface->canvas())); | 85 m_context = adoptPtr(new GraphicsContext(m_surface->canvas())); |
86 m_context->setCertainlyOpaque(m_surface->opacityMode() == Opaque); | 86 m_context->setCertainlyOpaque(m_surface->opacityMode() == Opaque); |
87 m_context->setAccelerated(m_surface->isAccelerated()); | 87 m_context->setAccelerated(m_surface->isAccelerated()); |
88 } | 88 } |
| 89 m_surface->setImageBuffer(this); |
89 } | 90 } |
90 | 91 |
91 ImageBuffer::~ImageBuffer() | 92 ImageBuffer::~ImageBuffer() |
92 { | 93 { |
93 } | 94 } |
94 | 95 |
95 GraphicsContext* ImageBuffer::context() const | 96 GraphicsContext* ImageBuffer::context() const |
96 { | 97 { |
97 if (!isSurfaceValid()) | 98 if (!isSurfaceValid()) |
98 return 0; | 99 return 0; |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 return drawingBuffer->copyToPlatformTexture(context3D, tex, GL_RGBA, | 230 return drawingBuffer->copyToPlatformTexture(context3D, tex, GL_RGBA, |
230 GL_UNSIGNED_BYTE, 0, true, false, fromFrontBuffer); | 231 GL_UNSIGNED_BYTE, 0, true, false, fromFrontBuffer); |
231 } | 232 } |
232 | 233 |
233 void ImageBuffer::draw(GraphicsContext* context, const FloatRect& destRect, cons
t FloatRect* srcPtr, CompositeOperator op) | 234 void ImageBuffer::draw(GraphicsContext* context, const FloatRect& destRect, cons
t FloatRect* srcPtr, CompositeOperator op) |
234 { | 235 { |
235 if (!isSurfaceValid()) | 236 if (!isSurfaceValid()) |
236 return; | 237 return; |
237 | 238 |
238 FloatRect srcRect = srcPtr ? *srcPtr : FloatRect(FloatPoint(), size()); | 239 FloatRect srcRect = srcPtr ? *srcPtr : FloatRect(FloatPoint(), size()); |
| 240 RefPtr<SkPicture> picture = m_surface->getPicture(); |
| 241 if (picture) { |
| 242 context->drawPicture(picture.release(), destRect, srcRect, op, blink::We
bBlendModeNormal); |
| 243 return; |
| 244 } |
| 245 |
239 SkBitmap bitmap = m_surface->bitmap(); | 246 SkBitmap bitmap = m_surface->bitmap(); |
240 // For ImageBufferSurface that enables cachedBitmap, Use the cached Bitmap f
or CPU side usage | 247 // For ImageBufferSurface that enables cachedBitmap, Use the cached Bitmap f
or CPU side usage |
241 // if it is available, otherwise generate and use it. | 248 // if it is available, otherwise generate and use it. |
242 if (!context->isAccelerated() && m_surface->isAccelerated() && m_surface->ca
chedBitmapEnabled() && isSurfaceValid()) { | 249 if (!context->isAccelerated() && m_surface->isAccelerated() && m_surface->ca
chedBitmapEnabled() && isSurfaceValid()) { |
243 m_surface->updateCachedBitmapIfNeeded(); | 250 m_surface->updateCachedBitmapIfNeeded(); |
244 bitmap = m_surface->cachedBitmap(); | 251 bitmap = m_surface->cachedBitmap(); |
245 } | 252 } |
246 | 253 |
247 RefPtr<Image> image = BitmapImage::create(NativeImageSkia::create(drawNeedsC
opy(m_context.get(), context) ? deepSkBitmapCopy(bitmap) : bitmap)); | 254 RefPtr<Image> image = BitmapImage::create(NativeImageSkia::create(drawNeedsC
opy(m_context.get(), context) ? deepSkBitmapCopy(bitmap) : bitmap)); |
248 | 255 |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 if (!encodeImage(imageData, mimeType, quality, &encodedImage)) | 416 if (!encodeImage(imageData, mimeType, quality, &encodedImage)) |
410 return "data:,"; | 417 return "data:,"; |
411 | 418 |
412 Vector<char> base64Data; | 419 Vector<char> base64Data; |
413 base64Encode(encodedImage, base64Data); | 420 base64Encode(encodedImage, base64Data); |
414 | 421 |
415 return "data:" + mimeType + ";base64," + base64Data; | 422 return "data:" + mimeType + ";base64," + base64Data; |
416 } | 423 } |
417 | 424 |
418 } // namespace WebCore | 425 } // namespace WebCore |
OLD | NEW |