| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 #include "third_party/skia/include/gpu/GrContext.h" | 57 #include "third_party/skia/include/gpu/GrContext.h" |
| 58 #include "third_party/skia/include/gpu/SkGpuDevice.h" | 58 #include "third_party/skia/include/gpu/SkGpuDevice.h" |
| 59 #include "wtf/MathExtras.h" | 59 #include "wtf/MathExtras.h" |
| 60 #include "wtf/text/Base64.h" | 60 #include "wtf/text/Base64.h" |
| 61 #include "wtf/text/WTFString.h" | 61 #include "wtf/text/WTFString.h" |
| 62 | 62 |
| 63 using namespace std; | 63 using namespace std; |
| 64 | 64 |
| 65 namespace WebCore { | 65 namespace WebCore { |
| 66 | 66 |
| 67 static SkCanvas* createAcceleratedCanvas(const IntSize& size, OwnPtr<Canvas2DLay
erBridge>* outLayerBridge, OpacityMode opacityMode) | 67 static SkCanvas* createAcceleratedCanvas(const IntSize& size, Canvas2DLayerBridg
ePtr* outLayerBridge, OpacityMode opacityMode) |
| 68 { | 68 { |
| 69 RefPtr<GraphicsContext3D> context3D = SharedGraphicsContext3D::get(); | 69 RefPtr<GraphicsContext3D> context3D = SharedGraphicsContext3D::get(); |
| 70 if (!context3D) | 70 if (!context3D) |
| 71 return 0; | 71 return 0; |
| 72 Canvas2DLayerBridge::OpacityMode bridgeOpacityMode = opacityMode == Opaque ?
Canvas2DLayerBridge::Opaque : Canvas2DLayerBridge::NonOpaque; | 72 Canvas2DLayerBridge::OpacityMode bridgeOpacityMode = opacityMode == Opaque ?
Canvas2DLayerBridge::Opaque : Canvas2DLayerBridge::NonOpaque; |
| 73 *outLayerBridge = Canvas2DLayerBridge::create(context3D.release(), size, bri
dgeOpacityMode); | 73 *outLayerBridge = Canvas2DLayerBridge::create(context3D.release(), size, bri
dgeOpacityMode); |
| 74 // If canvas buffer allocation failed, debug build will have asserted | 74 // If canvas buffer allocation failed, debug build will have asserted |
| 75 // For release builds, we must verify whether the device has a render target | 75 // For release builds, we must verify whether the device has a render target |
| 76 return (*outLayerBridge) ? (*outLayerBridge)->getCanvas() : 0; | 76 return (*outLayerBridge) ? (*outLayerBridge)->getCanvas() : 0; |
| 77 } | 77 } |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 // We're using context acquisition as a signal that someone is about to
render into our buffer and we need | 170 // We're using context acquisition as a signal that someone is about to
render into our buffer and we need |
| 171 // to be ready. This isn't logically const-correct, hence the cast. | 171 // to be ready. This isn't logically const-correct, hence the cast. |
| 172 const_cast<Canvas2DLayerBridge*>(m_layerBridge.get())->contextAcquired()
; | 172 const_cast<Canvas2DLayerBridge*>(m_layerBridge.get())->contextAcquired()
; |
| 173 } | 173 } |
| 174 return m_context.get(); | 174 return m_context.get(); |
| 175 } | 175 } |
| 176 | 176 |
| 177 | 177 |
| 178 bool ImageBuffer::isValid() const | 178 bool ImageBuffer::isValid() const |
| 179 { | 179 { |
| 180 if (m_layerBridge.get()) | 180 if (m_layerBridge) |
| 181 return const_cast<Canvas2DLayerBridge*>(m_layerBridge.get())->isValid(); | 181 return const_cast<Canvas2DLayerBridge*>(m_layerBridge.get())->isValid(); |
| 182 return true; | 182 return true; |
| 183 } | 183 } |
| 184 | 184 |
| 185 static SkBitmap deepSkBitmapCopy(const SkBitmap& bitmap) | 185 static SkBitmap deepSkBitmapCopy(const SkBitmap& bitmap) |
| 186 { | 186 { |
| 187 SkBitmap tmp; | 187 SkBitmap tmp; |
| 188 if (!bitmap.deepCopyTo(&tmp, bitmap.config())) | 188 if (!bitmap.deepCopyTo(&tmp, bitmap.config())) |
| 189 bitmap.copyTo(&tmp, bitmap.config()); | 189 bitmap.copyTo(&tmp, bitmap.config()); |
| 190 | 190 |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 if (!encodeImage(imageData, mimeType, quality, &encodedImage)) | 492 if (!encodeImage(imageData, mimeType, quality, &encodedImage)) |
| 493 return "data:,"; | 493 return "data:,"; |
| 494 | 494 |
| 495 Vector<char> base64Data; | 495 Vector<char> base64Data; |
| 496 base64Encode(encodedImage, base64Data); | 496 base64Encode(encodedImage, base64Data); |
| 497 | 497 |
| 498 return "data:" + mimeType + ";base64," + base64Data; | 498 return "data:" + mimeType + ";base64," + base64Data; |
| 499 } | 499 } |
| 500 | 500 |
| 501 } // namespace WebCore | 501 } // namespace WebCore |
| OLD | NEW |