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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 #include "wtf/text/WTFString.h" | 65 #include "wtf/text/WTFString.h" |
66 #include "wtf/typed_arrays/ArrayBufferContents.h" | 66 #include "wtf/typed_arrays/ArrayBufferContents.h" |
67 #include <memory> | 67 #include <memory> |
68 | 68 |
69 namespace blink { | 69 namespace blink { |
70 | 70 |
71 std::unique_ptr<ImageBuffer> ImageBuffer::create( | 71 std::unique_ptr<ImageBuffer> ImageBuffer::create( |
72 std::unique_ptr<ImageBufferSurface> surface) { | 72 std::unique_ptr<ImageBufferSurface> surface) { |
73 if (!surface->isValid()) | 73 if (!surface->isValid()) |
74 return nullptr; | 74 return nullptr; |
75 return wrapUnique(new ImageBuffer(std::move(surface))); | 75 return WTF::wrapUnique(new ImageBuffer(std::move(surface))); |
76 } | 76 } |
77 | 77 |
78 std::unique_ptr<ImageBuffer> ImageBuffer::create( | 78 std::unique_ptr<ImageBuffer> ImageBuffer::create( |
79 const IntSize& size, | 79 const IntSize& size, |
80 OpacityMode opacityMode, | 80 OpacityMode opacityMode, |
81 ImageInitializationMode initializationMode, | 81 ImageInitializationMode initializationMode, |
82 sk_sp<SkColorSpace> colorSpace) { | 82 sk_sp<SkColorSpace> colorSpace) { |
83 std::unique_ptr<ImageBufferSurface> surface( | 83 std::unique_ptr<ImageBufferSurface> surface( |
84 wrapUnique(new UnacceleratedImageBufferSurface( | 84 WTF::wrapUnique(new UnacceleratedImageBufferSurface( |
85 size, opacityMode, initializationMode, std::move(colorSpace)))); | 85 size, opacityMode, initializationMode, std::move(colorSpace)))); |
86 if (!surface->isValid()) | 86 if (!surface->isValid()) |
87 return nullptr; | 87 return nullptr; |
88 return wrapUnique(new ImageBuffer(std::move(surface))); | 88 return WTF::wrapUnique(new ImageBuffer(std::move(surface))); |
89 } | 89 } |
90 | 90 |
91 ImageBuffer::ImageBuffer(std::unique_ptr<ImageBufferSurface> surface) | 91 ImageBuffer::ImageBuffer(std::unique_ptr<ImageBufferSurface> surface) |
92 : m_weakPtrFactory(this), | 92 : m_weakPtrFactory(this), |
93 m_snapshotState(InitialSnapshotState), | 93 m_snapshotState(InitialSnapshotState), |
94 m_surface(std::move(surface)), | 94 m_surface(std::move(surface)), |
95 m_client(0), | 95 m_client(0), |
96 m_gpuMemoryUsage(0) { | 96 m_gpuMemoryUsage(0) { |
97 m_surface->setImageBuffer(this); | 97 m_surface->setImageBuffer(this); |
98 updateGPUMemoryUsage(); | 98 updateGPUMemoryUsage(); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 return false; | 233 return false; |
234 | 234 |
235 DCHECK(textureImage->isTextureBacked()); // The isAccelerated() check above | 235 DCHECK(textureImage->isTextureBacked()); // The isAccelerated() check above |
236 // should guarantee this. | 236 // should guarantee this. |
237 // Get the texture ID, flushing pending operations if needed. | 237 // Get the texture ID, flushing pending operations if needed. |
238 const GrGLTextureInfo* textureInfo = skia::GrBackendObjectToGrGLTextureInfo( | 238 const GrGLTextureInfo* textureInfo = skia::GrBackendObjectToGrGLTextureInfo( |
239 textureImage->getTextureHandle(true)); | 239 textureImage->getTextureHandle(true)); |
240 if (!textureInfo || !textureInfo->fID) | 240 if (!textureInfo || !textureInfo->fID) |
241 return false; | 241 return false; |
242 | 242 |
243 std::unique_ptr<WebGraphicsContext3DProvider> provider = wrapUnique( | 243 std::unique_ptr<WebGraphicsContext3DProvider> provider = WTF::wrapUnique( |
244 Platform::current()->createSharedOffscreenGraphicsContext3DProvider()); | 244 Platform::current()->createSharedOffscreenGraphicsContext3DProvider()); |
245 if (!provider || !provider->grContext()) | 245 if (!provider || !provider->grContext()) |
246 return false; | 246 return false; |
247 gpu::gles2::GLES2Interface* sharedGL = provider->contextGL(); | 247 gpu::gles2::GLES2Interface* sharedGL = provider->contextGL(); |
248 | 248 |
249 gpu::Mailbox mailbox; | 249 gpu::Mailbox mailbox; |
250 | 250 |
251 // Contexts may be in a different share group. We must transfer the texture | 251 // Contexts may be in a different share group. We must transfer the texture |
252 // through a mailbox first. | 252 // through a mailbox first. |
253 sharedGL->GenMailboxCHROMIUM(mailbox.name); | 253 sharedGL->GenMailboxCHROMIUM(mailbox.name); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 grContext->resetContext(kTextureBinding_GrGLBackendState); | 294 grContext->resetContext(kTextureBinding_GrGLBackendState); |
295 | 295 |
296 return true; | 296 return true; |
297 } | 297 } |
298 | 298 |
299 bool ImageBuffer::copyRenderingResultsFromDrawingBuffer( | 299 bool ImageBuffer::copyRenderingResultsFromDrawingBuffer( |
300 DrawingBuffer* drawingBuffer, | 300 DrawingBuffer* drawingBuffer, |
301 SourceDrawingBuffer sourceBuffer) { | 301 SourceDrawingBuffer sourceBuffer) { |
302 if (!drawingBuffer || !m_surface->isAccelerated()) | 302 if (!drawingBuffer || !m_surface->isAccelerated()) |
303 return false; | 303 return false; |
304 std::unique_ptr<WebGraphicsContext3DProvider> provider = wrapUnique( | 304 std::unique_ptr<WebGraphicsContext3DProvider> provider = WTF::wrapUnique( |
305 Platform::current()->createSharedOffscreenGraphicsContext3DProvider()); | 305 Platform::current()->createSharedOffscreenGraphicsContext3DProvider()); |
306 if (!provider) | 306 if (!provider) |
307 return false; | 307 return false; |
308 gpu::gles2::GLES2Interface* gl = provider->contextGL(); | 308 gpu::gles2::GLES2Interface* gl = provider->contextGL(); |
309 GLuint textureId = m_surface->getBackingTextureHandleForOverwrite(); | 309 GLuint textureId = m_surface->getBackingTextureHandleForOverwrite(); |
310 if (!textureId) | 310 if (!textureId) |
311 return false; | 311 return false; |
312 | 312 |
313 gl->Flush(); | 313 gl->Flush(); |
314 | 314 |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 } | 495 } |
496 | 496 |
497 class UnacceleratedSurfaceFactory | 497 class UnacceleratedSurfaceFactory |
498 : public RecordingImageBufferFallbackSurfaceFactory { | 498 : public RecordingImageBufferFallbackSurfaceFactory { |
499 public: | 499 public: |
500 virtual std::unique_ptr<ImageBufferSurface> createSurface( | 500 virtual std::unique_ptr<ImageBufferSurface> createSurface( |
501 const IntSize& size, | 501 const IntSize& size, |
502 OpacityMode opacityMode, | 502 OpacityMode opacityMode, |
503 sk_sp<SkColorSpace> colorSpace, | 503 sk_sp<SkColorSpace> colorSpace, |
504 SkColorType colorType) { | 504 SkColorType colorType) { |
505 return wrapUnique(new UnacceleratedImageBufferSurface( | 505 return WTF::wrapUnique(new UnacceleratedImageBufferSurface( |
506 size, opacityMode, InitializeImagePixels, std::move(colorSpace), | 506 size, opacityMode, InitializeImagePixels, std::move(colorSpace), |
507 colorType)); | 507 colorType)); |
508 } | 508 } |
509 | 509 |
510 virtual ~UnacceleratedSurfaceFactory() {} | 510 virtual ~UnacceleratedSurfaceFactory() {} |
511 }; | 511 }; |
512 | 512 |
513 void ImageBuffer::disableAcceleration() { | 513 void ImageBuffer::disableAcceleration() { |
514 if (!isAccelerated()) | 514 if (!isAccelerated()) |
515 return; | 515 return; |
516 | 516 |
517 sk_sp<SkImage> image = | 517 sk_sp<SkImage> image = |
518 m_surface->newImageSnapshot(PreferNoAcceleration, SnapshotReasonPaint); | 518 m_surface->newImageSnapshot(PreferNoAcceleration, SnapshotReasonPaint); |
519 // Using a GPU-backed image with RecordingImageBufferSurface | 519 // Using a GPU-backed image with RecordingImageBufferSurface |
520 // will fail at playback time. | 520 // will fail at playback time. |
521 image = image->makeNonTextureImage(); | 521 image = image->makeNonTextureImage(); |
522 | 522 |
523 // Create and configure a recording (unaccelerated) surface. | 523 // Create and configure a recording (unaccelerated) surface. |
524 std::unique_ptr<RecordingImageBufferFallbackSurfaceFactory> surfaceFactory = | 524 std::unique_ptr<RecordingImageBufferFallbackSurfaceFactory> surfaceFactory = |
525 makeUnique<UnacceleratedSurfaceFactory>(); | 525 WTF::makeUnique<UnacceleratedSurfaceFactory>(); |
526 std::unique_ptr<ImageBufferSurface> surface = | 526 std::unique_ptr<ImageBufferSurface> surface = |
527 wrapUnique(new RecordingImageBufferSurface( | 527 WTF::wrapUnique(new RecordingImageBufferSurface( |
528 m_surface->size(), std::move(surfaceFactory), | 528 m_surface->size(), std::move(surfaceFactory), |
529 m_surface->getOpacityMode(), m_surface->colorSpace())); | 529 m_surface->getOpacityMode(), m_surface->colorSpace())); |
530 surface->canvas()->drawImage(image.get(), 0, 0); | 530 surface->canvas()->drawImage(image.get(), 0, 0); |
531 surface->setImageBuffer(this); | 531 surface->setImageBuffer(this); |
532 if (m_client) | 532 if (m_client) |
533 m_client->restoreCanvasMatrixClipStack(surface->canvas()); | 533 m_client->restoreCanvasMatrixClipStack(surface->canvas()); |
534 m_surface = std::move(surface); | 534 m_surface = std::move(surface); |
535 | 535 |
536 didDisableAcceleration(); | 536 didDisableAcceleration(); |
537 } | 537 } |
(...skipping 24 matching lines...) Expand all Loading... |
562 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); | 562 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); |
563 | 563 |
564 Vector<unsigned char> result; | 564 Vector<unsigned char> result; |
565 if (!encodeImage(mimeType, quality, &result)) | 565 if (!encodeImage(mimeType, quality, &result)) |
566 return "data:,"; | 566 return "data:,"; |
567 | 567 |
568 return "data:" + mimeType + ";base64," + base64Encode(result); | 568 return "data:" + mimeType + ";base64," + base64Encode(result); |
569 } | 569 } |
570 | 570 |
571 } // namespace blink | 571 } // namespace blink |
OLD | NEW |