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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 #include "platform/image-encoders/WEBPImageEncoder.h" | 47 #include "platform/image-encoders/WEBPImageEncoder.h" |
48 #include "public/platform/Platform.h" | 48 #include "public/platform/Platform.h" |
49 #include "public/platform/WebExternalTextureMailbox.h" | 49 #include "public/platform/WebExternalTextureMailbox.h" |
50 #include "public/platform/WebGraphicsContext3DProvider.h" | 50 #include "public/platform/WebGraphicsContext3DProvider.h" |
51 #include "skia/ext/texture_handle.h" | 51 #include "skia/ext/texture_handle.h" |
52 #include "third_party/skia/include/core/SkPicture.h" | 52 #include "third_party/skia/include/core/SkPicture.h" |
53 #include "third_party/skia/include/gpu/GrContext.h" | 53 #include "third_party/skia/include/gpu/GrContext.h" |
54 #include "third_party/skia/include/gpu/gl/GrGLTypes.h" | 54 #include "third_party/skia/include/gpu/gl/GrGLTypes.h" |
55 #include "wtf/CheckedNumeric.h" | 55 #include "wtf/CheckedNumeric.h" |
56 #include "wtf/MathExtras.h" | 56 #include "wtf/MathExtras.h" |
| 57 #include "wtf/PtrUtil.h" |
57 #include "wtf/Vector.h" | 58 #include "wtf/Vector.h" |
58 #include "wtf/text/Base64.h" | 59 #include "wtf/text/Base64.h" |
59 #include "wtf/text/WTFString.h" | 60 #include "wtf/text/WTFString.h" |
60 #include "wtf/typed_arrays/ArrayBufferContents.h" | 61 #include "wtf/typed_arrays/ArrayBufferContents.h" |
| 62 #include <memory> |
61 | 63 |
62 namespace blink { | 64 namespace blink { |
63 | 65 |
64 PassOwnPtr<ImageBuffer> ImageBuffer::create(PassOwnPtr<ImageBufferSurface> surfa
ce) | 66 std::unique_ptr<ImageBuffer> ImageBuffer::create(std::unique_ptr<ImageBufferSurf
ace> surface) |
65 { | 67 { |
66 if (!surface->isValid()) | 68 if (!surface->isValid()) |
67 return nullptr; | 69 return nullptr; |
68 return adoptPtr(new ImageBuffer(std::move(surface))); | 70 return wrapUnique(new ImageBuffer(std::move(surface))); |
69 } | 71 } |
70 | 72 |
71 PassOwnPtr<ImageBuffer> ImageBuffer::create(const IntSize& size, OpacityMode opa
cityMode, ImageInitializationMode initializationMode) | 73 std::unique_ptr<ImageBuffer> ImageBuffer::create(const IntSize& size, OpacityMod
e opacityMode, ImageInitializationMode initializationMode) |
72 { | 74 { |
73 OwnPtr<ImageBufferSurface> surface(adoptPtr(new UnacceleratedImageBufferSurf
ace(size, opacityMode, initializationMode))); | 75 std::unique_ptr<ImageBufferSurface> surface(wrapUnique(new UnacceleratedImag
eBufferSurface(size, opacityMode, initializationMode))); |
74 if (!surface->isValid()) | 76 if (!surface->isValid()) |
75 return nullptr; | 77 return nullptr; |
76 return adoptPtr(new ImageBuffer(std::move(surface))); | 78 return wrapUnique(new ImageBuffer(std::move(surface))); |
77 } | 79 } |
78 | 80 |
79 ImageBuffer::ImageBuffer(PassOwnPtr<ImageBufferSurface> surface) | 81 ImageBuffer::ImageBuffer(std::unique_ptr<ImageBufferSurface> surface) |
80 : m_snapshotState(InitialSnapshotState) | 82 : m_snapshotState(InitialSnapshotState) |
81 , m_surface(std::move(surface)) | 83 , m_surface(std::move(surface)) |
82 , m_client(0) | 84 , m_client(0) |
83 , m_gpuMemoryUsage(0) | 85 , m_gpuMemoryUsage(0) |
84 { | 86 { |
85 m_surface->setImageBuffer(this); | 87 m_surface->setImageBuffer(this); |
86 updateGPUMemoryUsage(); | 88 updateGPUMemoryUsage(); |
87 } | 89 } |
88 | 90 |
89 intptr_t ImageBuffer::s_globalGPUMemoryUsage = 0; | 91 intptr_t ImageBuffer::s_globalGPUMemoryUsage = 0; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 if (!m_surface->isAccelerated()) | 199 if (!m_surface->isAccelerated()) |
198 return false; | 200 return false; |
199 | 201 |
200 | 202 |
201 ASSERT(textureImage->isTextureBacked()); // isAccelerated() check above shou
ld guarantee this | 203 ASSERT(textureImage->isTextureBacked()); // isAccelerated() check above shou
ld guarantee this |
202 // Get the texture ID, flushing pending operations if needed. | 204 // Get the texture ID, flushing pending operations if needed. |
203 const GrGLTextureInfo* textureInfo = skia::GrBackendObjectToGrGLTextureInfo(
textureImage->getTextureHandle(true)); | 205 const GrGLTextureInfo* textureInfo = skia::GrBackendObjectToGrGLTextureInfo(
textureImage->getTextureHandle(true)); |
204 if (!textureInfo || !textureInfo->fID) | 206 if (!textureInfo || !textureInfo->fID) |
205 return false; | 207 return false; |
206 | 208 |
207 OwnPtr<WebGraphicsContext3DProvider> provider = adoptPtr(Platform::current()
->createSharedOffscreenGraphicsContext3DProvider()); | 209 std::unique_ptr<WebGraphicsContext3DProvider> provider = wrapUnique(Platform
::current()->createSharedOffscreenGraphicsContext3DProvider()); |
208 if (!provider) | 210 if (!provider) |
209 return false; | 211 return false; |
210 gpu::gles2::GLES2Interface* sharedGL = provider->contextGL(); | 212 gpu::gles2::GLES2Interface* sharedGL = provider->contextGL(); |
211 | 213 |
212 OwnPtr<WebExternalTextureMailbox> mailbox = adoptPtr(new WebExternalTextureM
ailbox); | 214 std::unique_ptr<WebExternalTextureMailbox> mailbox = wrapUnique(new WebExter
nalTextureMailbox); |
213 mailbox->textureSize = WebSize(textureImage->width(), textureImage->height()
); | 215 mailbox->textureSize = WebSize(textureImage->width(), textureImage->height()
); |
214 | 216 |
215 // Contexts may be in a different share group. We must transfer the texture
through a mailbox first | 217 // Contexts may be in a different share group. We must transfer the texture
through a mailbox first |
216 sharedGL->GenMailboxCHROMIUM(mailbox->name); | 218 sharedGL->GenMailboxCHROMIUM(mailbox->name); |
217 sharedGL->ProduceTextureDirectCHROMIUM(textureInfo->fID, textureInfo->fTarge
t, mailbox->name); | 219 sharedGL->ProduceTextureDirectCHROMIUM(textureInfo->fID, textureInfo->fTarge
t, mailbox->name); |
218 const GLuint64 sharedFenceSync = sharedGL->InsertFenceSyncCHROMIUM(); | 220 const GLuint64 sharedFenceSync = sharedGL->InsertFenceSyncCHROMIUM(); |
219 sharedGL->Flush(); | 221 sharedGL->Flush(); |
220 | 222 |
221 sharedGL->GenSyncTokenCHROMIUM(sharedFenceSync, mailbox->syncToken); | 223 sharedGL->GenSyncTokenCHROMIUM(sharedFenceSync, mailbox->syncToken); |
222 mailbox->validSyncToken = true; | 224 mailbox->validSyncToken = true; |
(...skipping 18 matching lines...) Expand all Loading... |
241 // Undo grContext texture binding changes introduced in this function | 243 // Undo grContext texture binding changes introduced in this function |
242 provider->grContext()->resetContext(kTextureBinding_GrGLBackendState); | 244 provider->grContext()->resetContext(kTextureBinding_GrGLBackendState); |
243 | 245 |
244 return true; | 246 return true; |
245 } | 247 } |
246 | 248 |
247 bool ImageBuffer::copyRenderingResultsFromDrawingBuffer(DrawingBuffer* drawingBu
ffer, SourceDrawingBuffer sourceBuffer) | 249 bool ImageBuffer::copyRenderingResultsFromDrawingBuffer(DrawingBuffer* drawingBu
ffer, SourceDrawingBuffer sourceBuffer) |
248 { | 250 { |
249 if (!drawingBuffer || !m_surface->isAccelerated()) | 251 if (!drawingBuffer || !m_surface->isAccelerated()) |
250 return false; | 252 return false; |
251 OwnPtr<WebGraphicsContext3DProvider> provider = adoptPtr(Platform::current()
->createSharedOffscreenGraphicsContext3DProvider()); | 253 std::unique_ptr<WebGraphicsContext3DProvider> provider = wrapUnique(Platform
::current()->createSharedOffscreenGraphicsContext3DProvider()); |
252 if (!provider) | 254 if (!provider) |
253 return false; | 255 return false; |
254 gpu::gles2::GLES2Interface* gl = provider->contextGL(); | 256 gpu::gles2::GLES2Interface* gl = provider->contextGL(); |
255 GLuint textureId = m_surface->getBackingTextureHandleForOverwrite(); | 257 GLuint textureId = m_surface->getBackingTextureHandleForOverwrite(); |
256 if (!textureId) | 258 if (!textureId) |
257 return false; | 259 return false; |
258 | 260 |
259 gl->Flush(); | 261 gl->Flush(); |
260 | 262 |
261 return drawingBuffer->copyToPlatformTexture(gl, textureId, GL_RGBA, | 263 return drawingBuffer->copyToPlatformTexture(gl, textureId, GL_RGBA, |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); | 412 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); |
411 | 413 |
412 Vector<unsigned char> result; | 414 Vector<unsigned char> result; |
413 if (!encodeImage(mimeType, quality, &result)) | 415 if (!encodeImage(mimeType, quality, &result)) |
414 return "data:,"; | 416 return "data:,"; |
415 | 417 |
416 return "data:" + mimeType + ";base64," + base64Encode(result); | 418 return "data:" + mimeType + ";base64," + base64Encode(result); |
417 } | 419 } |
418 | 420 |
419 } // namespace blink | 421 } // namespace blink |
OLD | NEW |