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

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

Issue 21858004: Refactoring Canvas2DLayerBridge to make it easier to write unit tests (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixed similarity blunder 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
« no previous file with comments | « Source/core/core.gypi ('k') | Source/core/platform/graphics/chromium/Canvas2DLayerBridge.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 namespace {
65
66 class AcceleratedLayerHelper : public Canvas2DLayerBridge::Helper {
67 public:
68 virtual PassRefPtr<GraphicsContext3D> getContext() OVERRIDE
69 {
70 return SharedGraphicsContext3D::get();
71 }
72
73 virtual SkSurface* createSurface(GraphicsContext3D* context3D, const IntSize & size) OVERRIDE
74 {
75 ASSERT(!context3D->webContext()->isContextLost());
76 GrContext* gr = context3D->grContext();
77 if (!gr)
78 return 0;
79 gr->resetContext();
80 SkImage::Info info;
81 info.fWidth = size.width();
82 info.fHeight = size.height();
83 info.fColorType = SkImage::kPMColor_ColorType;
84 info.fAlphaType = SkImage::kPremul_AlphaType;
85 return SkSurface::NewRenderTarget(gr, info);
86 }
87 };
88
89 } // unnamed namespace
90
64 static SkCanvas* createAcceleratedCanvas(const IntSize& size, OwnPtr<Canvas2DLay erBridge>* outLayerBridge, OpacityMode opacityMode) 91 static SkCanvas* createAcceleratedCanvas(const IntSize& size, OwnPtr<Canvas2DLay erBridge>* outLayerBridge, OpacityMode opacityMode)
65 { 92 {
66 RefPtr<GraphicsContext3D> context3D = SharedGraphicsContext3D::get(); 93 OwnPtr<AcceleratedLayerHelper> helper = adoptPtr(new AcceleratedLayerHelper) ;
67 if (!context3D) 94 if (!helper->getContext())
68 return 0; 95 return 0;
69 Canvas2DLayerBridge::OpacityMode bridgeOpacityMode = opacityMode == Opaque ? Canvas2DLayerBridge::Opaque : Canvas2DLayerBridge::NonOpaque; 96 Canvas2DLayerBridge::OpacityMode bridgeOpacityMode = opacityMode == Opaque ? Canvas2DLayerBridge::Opaque : Canvas2DLayerBridge::NonOpaque;
70 *outLayerBridge = Canvas2DLayerBridge::create(context3D.release(), size, bri dgeOpacityMode); 97 *outLayerBridge = Canvas2DLayerBridge::create(helper.release(), size, bridge OpacityMode);
71 // If canvas buffer allocation failed, debug build will have asserted 98 // If canvas buffer allocation failed, debug build will have asserted
72 // For release builds, we must verify whether the device has a render target 99 // For release builds, we must verify whether the device has a render target
73 return (*outLayerBridge) ? (*outLayerBridge)->getCanvas() : 0; 100 return (*outLayerBridge) ? (*outLayerBridge)->getCanvas() : 0;
74 } 101 }
75 102
76 static SkCanvas* createNonPlatformCanvas(const IntSize& size) 103 static SkCanvas* createNonPlatformCanvas(const IntSize& size)
77 { 104 {
78 SkAutoTUnref<SkDevice> device(new SkDevice(SkBitmap::kARGB_8888_Config, size .width(), size.height())); 105 SkAutoTUnref<SkDevice> device(new SkDevice(SkBitmap::kARGB_8888_Config, size .width(), size.height()));
79 SkPixelRef* pixelRef = device->accessBitmap(false).pixelRef(); 106 SkPixelRef* pixelRef = device->accessBitmap(false).pixelRef();
80 return pixelRef ? new SkCanvas(device) : 0; 107 return pixelRef ? new SkCanvas(device) : 0;
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 if (!encodeImage(imageData, mimeType, quality, &encodedImage)) 516 if (!encodeImage(imageData, mimeType, quality, &encodedImage))
490 return "data:,"; 517 return "data:,";
491 518
492 Vector<char> base64Data; 519 Vector<char> base64Data;
493 base64Encode(encodedImage, base64Data); 520 base64Encode(encodedImage, base64Data);
494 521
495 return "data:" + mimeType + ";base64," + base64Data; 522 return "data:" + mimeType + ";base64," + base64Data;
496 } 523 }
497 524
498 } // namespace WebCore 525 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/core.gypi ('k') | Source/core/platform/graphics/chromium/Canvas2DLayerBridge.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698