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

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

Issue 151183003: remove redundant GrContext parameter to NewRenderTargetDirect (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 10 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
« no previous file with comments | « include/core/SkSurface.h ('k') | no next file » | 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 SkImageInfo&, int sampleCount); 17 SkSurface_Gpu(GrContext*, const SkImageInfo&, int sampleCount);
18 SkSurface_Gpu(GrContext*, GrRenderTarget*); 18 SkSurface_Gpu(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 SkImageInfo&) 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 /////////////////////////////////////////////////////////////////////////////// 34 ///////////////////////////////////////////////////////////////////////////////
35 35
36 SkSurface_Gpu::SkSurface_Gpu(GrContext* ctx, const SkImageInfo& info, 36 SkSurface_Gpu::SkSurface_Gpu(GrContext* ctx, const SkImageInfo& info,
37 int sampleCount) 37 int sampleCount)
38 : INHERITED(info.fWidth, info.fHeight) { 38 : INHERITED(info.fWidth, info.fHeight) {
39 SkBitmap::Config config = SkImageInfoToBitmapConfig(info); 39 SkBitmap::Config config = SkImageInfoToBitmapConfig(info);
40 40
41 fDevice = SkNEW_ARGS(SkGpuDevice, (ctx, config, info.fWidth, info.fHeight, s ampleCount)); 41 fDevice = SkNEW_ARGS(SkGpuDevice, (ctx, config, info.fWidth, info.fHeight, s ampleCount));
42 42
43 if (!SkAlphaTypeIsOpaque(info.fAlphaType)) { 43 if (!SkAlphaTypeIsOpaque(info.fAlphaType)) {
44 fDevice->clear(0x0); 44 fDevice->clear(0x0);
45 } 45 }
46 } 46 }
47 47
48 SkSurface_Gpu::SkSurface_Gpu(GrContext* ctx, GrRenderTarget* renderTarget) 48 SkSurface_Gpu::SkSurface_Gpu(GrRenderTarget* renderTarget)
49 : INHERITED(renderTarget->width(), renderTarget->height()) { 49 : INHERITED(renderTarget->width(), renderTarget->height()) {
50 fDevice = SkNEW_ARGS(SkGpuDevice, (ctx, renderTarget)); 50 fDevice = SkNEW_ARGS(SkGpuDevice, (renderTarget->getContext(), renderTarget) );
51 51
52 if (kRGB_565_GrPixelConfig != renderTarget->config()) { 52 if (kRGB_565_GrPixelConfig != renderTarget->config()) {
53 fDevice->clear(0x0); 53 fDevice->clear(0x0);
54 } 54 }
55 } 55 }
56 56
57 SkSurface_Gpu::~SkSurface_Gpu() { 57 SkSurface_Gpu::~SkSurface_Gpu() {
58 SkSafeUnref(fDevice); 58 SkSafeUnref(fDevice);
59 } 59 }
60 60
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 } 95 }
96 SkASSERT(NULL != this->getCachedCanvas()); 96 SkASSERT(NULL != this->getCachedCanvas());
97 SkASSERT(this->getCachedCanvas()->getDevice() == fDevice); 97 SkASSERT(this->getCachedCanvas()->getDevice() == fDevice);
98 this->getCachedCanvas()->setDevice(newDevice); 98 this->getCachedCanvas()->setDevice(newDevice);
99 SkRefCnt_SafeAssign(fDevice, newDevice); 99 SkRefCnt_SafeAssign(fDevice, newDevice);
100 } 100 }
101 } 101 }
102 102
103 /////////////////////////////////////////////////////////////////////////////// 103 ///////////////////////////////////////////////////////////////////////////////
104 104
105 SkSurface* SkSurface::NewRenderTargetDirect(GrRenderTarget* target) {
106 if (NULL == target) {
107 return NULL;
108 }
109 return SkNEW_ARGS(SkSurface_Gpu, (target));
110 }
111
112 #ifdef SK_SUPPORT_LEGACY_NEWRENDERTARGETDIRECT
105 SkSurface* SkSurface::NewRenderTargetDirect(GrContext* ctx, 113 SkSurface* SkSurface::NewRenderTargetDirect(GrContext* ctx,
106 GrRenderTarget* target) { 114 GrRenderTarget* target) {
107 if (NULL == ctx || NULL == target) { 115 SkASSERT(target->getContext() == ctx);
108 return NULL; 116 return SkSurface::NewRenderTargetDirect(target);
109 }
110
111 return SkNEW_ARGS(SkSurface_Gpu, (ctx, target));
112 } 117 }
118 #endif
113 119
114 SkSurface* SkSurface::NewRenderTarget(GrContext* ctx, const SkImageInfo& info, i nt sampleCount) { 120 SkSurface* SkSurface::NewRenderTarget(GrContext* ctx, const SkImageInfo& info, i nt sampleCount) {
115 if (NULL == ctx) { 121 if (NULL == ctx) {
116 return NULL; 122 return NULL;
117 } 123 }
118 124
119 SkBitmap::Config config = SkImageInfoToBitmapConfig(info); 125 SkBitmap::Config config = SkImageInfoToBitmapConfig(info);
120 126
121 GrTextureDesc desc; 127 GrTextureDesc desc;
122 desc.fFlags = kRenderTarget_GrTextureFlagBit | kCheckAllocation_GrTextureFla gBit; 128 desc.fFlags = kRenderTarget_GrTextureFlagBit | kCheckAllocation_GrTextureFla gBit;
123 desc.fWidth = info.fWidth; 129 desc.fWidth = info.fWidth;
124 desc.fHeight = info.fHeight; 130 desc.fHeight = info.fHeight;
125 desc.fConfig = SkBitmapConfig2GrPixelConfig(config); 131 desc.fConfig = SkBitmapConfig2GrPixelConfig(config);
126 desc.fSampleCnt = sampleCount; 132 desc.fSampleCnt = sampleCount;
127 133
128 SkAutoTUnref<GrTexture> tex(ctx->createUncachedTexture(desc, NULL, 0)); 134 SkAutoTUnref<GrTexture> tex(ctx->createUncachedTexture(desc, NULL, 0));
129 if (NULL == tex) { 135 if (NULL == tex) {
130 return NULL; 136 return NULL;
131 } 137 }
132 138
133 return SkNEW_ARGS(SkSurface_Gpu, (ctx, tex->asRenderTarget())); 139 return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget()));
134 } 140 }
OLDNEW
« no previous file with comments | « include/core/SkSurface.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698