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

Side by Side Diff: src/image/SkSurface_Gpu.cpp

Issue 54363008: move SkImage::ColorType into SkColorType (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 1 month 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
« no previous file with comments | « src/image/SkSurface_Base.h ('k') | src/image/SkSurface_Picture.cpp » ('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 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkSurface_Base.h" 8 #include "SkSurface_Base.h"
9 #include "SkImagePriv.h" 9 #include "SkImagePriv.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
11 #include "SkGpuDevice.h" 11 #include "SkGpuDevice.h"
12 12
13 class SkSurface_Gpu : public SkSurface_Base { 13 class SkSurface_Gpu : public SkSurface_Base {
14 public: 14 public:
15 SK_DECLARE_INST_COUNT(SkSurface_Gpu) 15 SK_DECLARE_INST_COUNT(SkSurface_Gpu)
16 16
17 SkSurface_Gpu(GrContext*, const SkImage::Info&, int sampleCount); 17 SkSurface_Gpu(GrContext*, const SkImageInfo&, int sampleCount);
18 SkSurface_Gpu(GrContext*, GrRenderTarget*); 18 SkSurface_Gpu(GrContext*, GrRenderTarget*);
19 virtual ~SkSurface_Gpu(); 19 virtual ~SkSurface_Gpu();
20 20
21 virtual SkCanvas* onNewCanvas() SK_OVERRIDE; 21 virtual SkCanvas* onNewCanvas() SK_OVERRIDE;
22 virtual SkSurface* onNewSurface(const SkImage::Info&) SK_OVERRIDE; 22 virtual SkSurface* onNewSurface(const SkImageInfo&) SK_OVERRIDE;
23 virtual SkImage* onNewImageSnapshot() SK_OVERRIDE; 23 virtual SkImage* onNewImageSnapshot() SK_OVERRIDE;
24 virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, 24 virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y,
25 const SkPaint*) SK_OVERRIDE; 25 const SkPaint*) SK_OVERRIDE;
26 virtual void onCopyOnWrite(ContentChangeMode) SK_OVERRIDE; 26 virtual void onCopyOnWrite(ContentChangeMode) SK_OVERRIDE;
27 27
28 private: 28 private:
29 SkGpuDevice* fDevice; 29 SkGpuDevice* fDevice;
30 30
31 typedef SkSurface_Base INHERITED; 31 typedef SkSurface_Base INHERITED;
32 }; 32 };
33 33
34 SK_DEFINE_INST_COUNT(SkSurface_Gpu) 34 SK_DEFINE_INST_COUNT(SkSurface_Gpu)
35 35
36 /////////////////////////////////////////////////////////////////////////////// 36 ///////////////////////////////////////////////////////////////////////////////
37 37
38 SkSurface_Gpu::SkSurface_Gpu(GrContext* ctx, const SkImage::Info& info, 38 SkSurface_Gpu::SkSurface_Gpu(GrContext* ctx, const SkImageInfo& info,
39 int sampleCount) 39 int sampleCount)
40 : INHERITED(info.fWidth, info.fHeight) { 40 : INHERITED(info.fWidth, info.fHeight) {
41 SkBitmap::Config config = SkImageInfoToBitmapConfig(info); 41 SkBitmap::Config config = SkImageInfoToBitmapConfig(info);
42 42
43 fDevice = SkNEW_ARGS(SkGpuDevice, (ctx, config, info.fWidth, info.fHeight, s ampleCount)); 43 fDevice = SkNEW_ARGS(SkGpuDevice, (ctx, config, info.fWidth, info.fHeight, s ampleCount));
44 44
45 if (!SkAlphaTypeIsOpaque(info.fAlphaType)) { 45 if (!SkAlphaTypeIsOpaque(info.fAlphaType)) {
46 fDevice->clear(0x0); 46 fDevice->clear(0x0);
47 } 47 }
48 } 48 }
49 49
50 SkSurface_Gpu::SkSurface_Gpu(GrContext* ctx, GrRenderTarget* renderTarget) 50 SkSurface_Gpu::SkSurface_Gpu(GrContext* ctx, GrRenderTarget* renderTarget)
51 : INHERITED(renderTarget->width(), renderTarget->height()) { 51 : INHERITED(renderTarget->width(), renderTarget->height()) {
52 fDevice = SkNEW_ARGS(SkGpuDevice, (ctx, renderTarget)); 52 fDevice = SkNEW_ARGS(SkGpuDevice, (ctx, renderTarget));
53 53
54 if (kRGB_565_GrPixelConfig != renderTarget->config()) { 54 if (kRGB_565_GrPixelConfig != renderTarget->config()) {
55 fDevice->clear(0x0); 55 fDevice->clear(0x0);
56 } 56 }
57 } 57 }
58 58
59 SkSurface_Gpu::~SkSurface_Gpu() { 59 SkSurface_Gpu::~SkSurface_Gpu() {
60 SkSafeUnref(fDevice); 60 SkSafeUnref(fDevice);
61 } 61 }
62 62
63 SkCanvas* SkSurface_Gpu::onNewCanvas() { 63 SkCanvas* SkSurface_Gpu::onNewCanvas() {
64 return SkNEW_ARGS(SkCanvas, (fDevice)); 64 return SkNEW_ARGS(SkCanvas, (fDevice));
65 } 65 }
66 66
67 SkSurface* SkSurface_Gpu::onNewSurface(const SkImage::Info& info) { 67 SkSurface* SkSurface_Gpu::onNewSurface(const SkImageInfo& info) {
68 GrRenderTarget* rt = fDevice->accessRenderTarget(); 68 GrRenderTarget* rt = fDevice->accessRenderTarget();
69 int sampleCount = rt->numSamples(); 69 int sampleCount = rt->numSamples();
70 return SkSurface::NewRenderTarget(fDevice->context(), info, sampleCount); 70 return SkSurface::NewRenderTarget(fDevice->context(), info, sampleCount);
71 } 71 }
72 72
73 SkImage* SkSurface_Gpu::onNewImageSnapshot() { 73 SkImage* SkSurface_Gpu::onNewImageSnapshot() {
74 return SkImage::NewTexture(fDevice->accessBitmap(false)); 74 return SkImage::NewTexture(fDevice->accessBitmap(false));
75 } 75 }
76 76
77 void SkSurface_Gpu::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, 77 void SkSurface_Gpu::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y,
(...skipping 28 matching lines...) Expand all
106 106
107 SkSurface* SkSurface::NewRenderTargetDirect(GrContext* ctx, 107 SkSurface* SkSurface::NewRenderTargetDirect(GrContext* ctx,
108 GrRenderTarget* target) { 108 GrRenderTarget* target) {
109 if (NULL == ctx || NULL == target) { 109 if (NULL == ctx || NULL == target) {
110 return NULL; 110 return NULL;
111 } 111 }
112 112
113 return SkNEW_ARGS(SkSurface_Gpu, (ctx, target)); 113 return SkNEW_ARGS(SkSurface_Gpu, (ctx, target));
114 } 114 }
115 115
116 SkSurface* SkSurface::NewRenderTarget(GrContext* ctx, const SkImage::Info& info, int sampleCount) { 116 SkSurface* SkSurface::NewRenderTarget(GrContext* ctx, const SkImageInfo& info, i nt sampleCount) {
117 if (NULL == ctx) { 117 if (NULL == ctx) {
118 return NULL; 118 return NULL;
119 } 119 }
120 120
121 SkBitmap::Config config = SkImageInfoToBitmapConfig(info); 121 SkBitmap::Config config = SkImageInfoToBitmapConfig(info);
122 122
123 GrTextureDesc desc; 123 GrTextureDesc desc;
124 desc.fFlags = kRenderTarget_GrTextureFlagBit | kCheckAllocation_GrTextureFla gBit; 124 desc.fFlags = kRenderTarget_GrTextureFlagBit | kCheckAllocation_GrTextureFla gBit;
125 desc.fWidth = info.fWidth; 125 desc.fWidth = info.fWidth;
126 desc.fHeight = info.fHeight; 126 desc.fHeight = info.fHeight;
127 desc.fConfig = SkBitmapConfig2GrPixelConfig(config); 127 desc.fConfig = SkBitmapConfig2GrPixelConfig(config);
128 desc.fSampleCnt = sampleCount; 128 desc.fSampleCnt = sampleCount;
129 129
130 SkAutoTUnref<GrTexture> tex(ctx->createUncachedTexture(desc, NULL, 0)); 130 SkAutoTUnref<GrTexture> tex(ctx->createUncachedTexture(desc, NULL, 0));
131 if (NULL == tex) { 131 if (NULL == tex) {
132 return NULL; 132 return NULL;
133 } 133 }
134 134
135 return SkNEW_ARGS(SkSurface_Gpu, (ctx, tex->asRenderTarget())); 135 return SkNEW_ARGS(SkSurface_Gpu, (ctx, tex->asRenderTarget()));
136 } 136 }
OLDNEW
« no previous file with comments | « src/image/SkSurface_Base.h ('k') | src/image/SkSurface_Picture.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698