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 blink { | 63 namespace blink { |
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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 return drawingBuffer->copyToPlatformTexture(context3D, tex, GL_RGBA, | 236 return drawingBuffer->copyToPlatformTexture(context3D, tex, GL_RGBA, |
236 GL_UNSIGNED_BYTE, 0, true, false, fromFrontBuffer); | 237 GL_UNSIGNED_BYTE, 0, true, false, fromFrontBuffer); |
237 } | 238 } |
238 | 239 |
239 void ImageBuffer::draw(GraphicsContext* context, const FloatRect& destRect, cons
t FloatRect* srcPtr, CompositeOperator op) | 240 void ImageBuffer::draw(GraphicsContext* context, const FloatRect& destRect, cons
t FloatRect* srcPtr, CompositeOperator op) |
240 { | 241 { |
241 if (!isSurfaceValid()) | 242 if (!isSurfaceValid()) |
242 return; | 243 return; |
243 | 244 |
244 FloatRect srcRect = srcPtr ? *srcPtr : FloatRect(FloatPoint(), size()); | 245 FloatRect srcRect = srcPtr ? *srcPtr : FloatRect(FloatPoint(), size()); |
| 246 RefPtr<SkPicture> picture = m_surface->getPicture(); |
| 247 if (picture) { |
| 248 context->drawPicture(picture.release(), destRect, srcRect, op, blink::We
bBlendModeNormal); |
| 249 return; |
| 250 } |
| 251 |
245 SkBitmap bitmap = m_surface->bitmap(); | 252 SkBitmap bitmap = m_surface->bitmap(); |
246 // For ImageBufferSurface that enables cachedBitmap, Use the cached Bitmap f
or CPU side usage | 253 // For ImageBufferSurface that enables cachedBitmap, Use the cached Bitmap f
or CPU side usage |
247 // if it is available, otherwise generate and use it. | 254 // if it is available, otherwise generate and use it. |
248 if (!context->isAccelerated() && m_surface->isAccelerated() && m_surface->ca
chedBitmapEnabled() && isSurfaceValid()) { | 255 if (!context->isAccelerated() && m_surface->isAccelerated() && m_surface->ca
chedBitmapEnabled() && isSurfaceValid()) { |
249 m_surface->updateCachedBitmapIfNeeded(); | 256 m_surface->updateCachedBitmapIfNeeded(); |
250 bitmap = m_surface->cachedBitmap(); | 257 bitmap = m_surface->cachedBitmap(); |
251 } | 258 } |
252 | 259 |
253 RefPtr<Image> image = BitmapImage::create(NativeImageSkia::create(drawNeedsC
opy(m_context.get(), context) ? deepSkBitmapCopy(bitmap) : bitmap)); | 260 RefPtr<Image> image = BitmapImage::create(NativeImageSkia::create(drawNeedsC
opy(m_context.get(), context) ? deepSkBitmapCopy(bitmap) : bitmap)); |
254 | 261 |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 if (!encodeImage(imageData, mimeType, quality, &encodedImage)) | 422 if (!encodeImage(imageData, mimeType, quality, &encodedImage)) |
416 return "data:,"; | 423 return "data:,"; |
417 | 424 |
418 Vector<char> base64Data; | 425 Vector<char> base64Data; |
419 base64Encode(encodedImage, base64Data); | 426 base64Encode(encodedImage, base64Data); |
420 | 427 |
421 return "data:" + mimeType + ";base64," + base64Data; | 428 return "data:" + mimeType + ";base64," + base64Data; |
422 } | 429 } |
423 | 430 |
424 } // namespace blink | 431 } // namespace blink |
OLD | NEW |