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

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

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

Powered by Google App Engine
This is Rietveld 408576698