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

Side by Side Diff: Source/core/platform/graphics/ImageBuffer.cpp

Issue 22929012: Change Canvas2DLayerBridge to stay alive until last mailbox is returned. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 4 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 | Annotate | Revision Log
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 #include "third_party/skia/include/gpu/GrContext.h" 54 #include "third_party/skia/include/gpu/GrContext.h"
55 #include "third_party/skia/include/gpu/SkGpuDevice.h" 55 #include "third_party/skia/include/gpu/SkGpuDevice.h"
56 #include "wtf/MathExtras.h" 56 #include "wtf/MathExtras.h"
57 #include "wtf/text/Base64.h" 57 #include "wtf/text/Base64.h"
58 #include "wtf/text/WTFString.h" 58 #include "wtf/text/WTFString.h"
59 59
60 using namespace std; 60 using namespace std;
61 61
62 namespace WebCore { 62 namespace WebCore {
63 63
64 static SkCanvas* createAcceleratedCanvas(const IntSize& size, OwnPtr<Canvas2DLay erBridge>* outLayerBridge, OpacityMode opacityMode) 64 static SkCanvas* createAcceleratedCanvas(const IntSize& size, Canvas2DLayerBridg ePtr* outLayerBridge, OpacityMode opacityMode)
65 { 65 {
66 RefPtr<GraphicsContext3D> context3D = SharedGraphicsContext3D::get(); 66 RefPtr<GraphicsContext3D> context3D = SharedGraphicsContext3D::get();
67 if (!context3D) 67 if (!context3D)
68 return 0; 68 return 0;
69 Canvas2DLayerBridge::OpacityMode bridgeOpacityMode = opacityMode == Opaque ? Canvas2DLayerBridge::Opaque : Canvas2DLayerBridge::NonOpaque; 69 Canvas2DLayerBridge::OpacityMode bridgeOpacityMode = opacityMode == Opaque ? Canvas2DLayerBridge::Opaque : Canvas2DLayerBridge::NonOpaque;
70 *outLayerBridge = Canvas2DLayerBridge::create(context3D.release(), size, bri dgeOpacityMode); 70 *outLayerBridge = Canvas2DLayerBridge::create(context3D.release(), size, bri dgeOpacityMode);
71 // If canvas buffer allocation failed, debug build will have asserted 71 // If canvas buffer allocation failed, debug build will have asserted
72 // For release builds, we must verify whether the device has a render target 72 // For release builds, we must verify whether the device has a render target
73 return (*outLayerBridge) ? (*outLayerBridge)->getCanvas() : 0; 73 return outLayerBridge->get() ? (*outLayerBridge)->getCanvas() : 0;
74 } 74 }
75 75
76 static SkCanvas* createNonPlatformCanvas(const IntSize& size) 76 static SkCanvas* createNonPlatformCanvas(const IntSize& size)
77 { 77 {
78 SkAutoTUnref<SkDevice> device(new SkDevice(SkBitmap::kARGB_8888_Config, size .width(), size.height())); 78 SkAutoTUnref<SkDevice> device(new SkDevice(SkBitmap::kARGB_8888_Config, size .width(), size.height()));
79 SkPixelRef* pixelRef = device->accessBitmap(false).pixelRef(); 79 SkPixelRef* pixelRef = device->accessBitmap(false).pixelRef();
80 return pixelRef ? new SkCanvas(device) : 0; 80 return pixelRef ? new SkCanvas(device) : 0;
81 } 81 }
82 82
83 PassOwnPtr<ImageBuffer> ImageBuffer::createCompatibleBuffer(const IntSize& size, float resolutionScale, const GraphicsContext* context, bool hasAlpha) 83 PassOwnPtr<ImageBuffer> ImageBuffer::createCompatibleBuffer(const IntSize& size, float resolutionScale, const GraphicsContext* context, bool hasAlpha)
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 156
157 success = true; 157 success = true;
158 } 158 }
159 159
160 ImageBuffer::~ImageBuffer() 160 ImageBuffer::~ImageBuffer()
161 { 161 {
162 } 162 }
163 163
164 GraphicsContext* ImageBuffer::context() const 164 GraphicsContext* ImageBuffer::context() const
165 { 165 {
166 if (m_layerBridge) { 166 if (m_layerBridge.get()) {
167 // We're using context acquisition as a signal that someone is about to render into our buffer and we need 167 // We're using context acquisition as a signal that someone is about to render into our buffer and we need
168 // to be ready. This isn't logically const-correct, hence the cast. 168 // to be ready. This isn't logically const-correct, hence the cast.
169 const_cast<Canvas2DLayerBridge*>(m_layerBridge.get())->contextAcquired() ; 169 const_cast<Canvas2DLayerBridge*>(m_layerBridge.get())->contextAcquired() ;
170 } 170 }
171 return m_context.get(); 171 return m_context.get();
172 } 172 }
173 173
174 174
175 bool ImageBuffer::isValid() const 175 bool ImageBuffer::isValid() const
176 { 176 {
(...skipping 21 matching lines...) Expand all
198 return BitmapImage::create(NativeImageSkia::create(copyBehavior == CopyBacki ngStore ? deepSkBitmapCopy(bitmap) : bitmap, m_resolutionScale)); 198 return BitmapImage::create(NativeImageSkia::create(copyBehavior == CopyBacki ngStore ? deepSkBitmapCopy(bitmap) : bitmap, m_resolutionScale));
199 } 199 }
200 200
201 BackingStoreCopy ImageBuffer::fastCopyImageMode() 201 BackingStoreCopy ImageBuffer::fastCopyImageMode()
202 { 202 {
203 return DontCopyBackingStore; 203 return DontCopyBackingStore;
204 } 204 }
205 205
206 WebKit::WebLayer* ImageBuffer::platformLayer() const 206 WebKit::WebLayer* ImageBuffer::platformLayer() const
207 { 207 {
208 return m_layerBridge ? m_layerBridge->layer() : 0; 208 return m_layerBridge.get() ? m_layerBridge->layer() : 0;
209 } 209 }
210 210
211 bool ImageBuffer::copyToPlatformTexture(GraphicsContext3D& context, Platform3DOb ject texture, GC3Denum internalFormat, GC3Denum destType, GC3Dint level, bool pr emultiplyAlpha, bool flipY) 211 bool ImageBuffer::copyToPlatformTexture(GraphicsContext3D& context, Platform3DOb ject texture, GC3Denum internalFormat, GC3Denum destType, GC3Dint level, bool pr emultiplyAlpha, bool flipY)
212 { 212 {
213 if (!m_layerBridge || !platformLayer() || !isValid()) 213 if (!m_layerBridge.get() || !platformLayer() || !isValid())
214 return false; 214 return false;
215 215
216 Platform3DObject sourceTexture = m_layerBridge->backBufferTexture(); 216 Platform3DObject sourceTexture = m_layerBridge->backBufferTexture();
217 217
218 if (!context.makeContextCurrent()) 218 if (!context.makeContextCurrent())
219 return false; 219 return false;
220 220
221 Extensions3D* extensions = context.getExtensions(); 221 Extensions3D* extensions = context.getExtensions();
222 if (!extensions->supports("GL_CHROMIUM_copy_texture") || !extensions->suppor ts("GL_CHROMIUM_flipy") 222 if (!extensions->supports("GL_CHROMIUM_copy_texture") || !extensions->suppor ts("GL_CHROMIUM_flipy")
223 || !extensions->canUseCopyTextureCHROMIUM(internalFormat, destType, leve l)) 223 || !extensions->canUseCopyTextureCHROMIUM(internalFormat, destType, leve l))
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 if (!encodeImage(imageData, mimeType, quality, &encodedImage)) 489 if (!encodeImage(imageData, mimeType, quality, &encodedImage))
490 return "data:,"; 490 return "data:,";
491 491
492 Vector<char> base64Data; 492 Vector<char> base64Data;
493 base64Encode(encodedImage, base64Data); 493 base64Encode(encodedImage, base64Data);
494 494
495 return "data:" + mimeType + ";base64," + base64Data; 495 return "data:" + mimeType + ";base64," + base64Data;
496 } 496 }
497 497
498 } // namespace WebCore 498 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698