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

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

Issue 14263017: Cleanup: Removing unnecessary args/complexity in SkSurface_Base and friends (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 8 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 | « 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 SkImage::Info&, 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 SkImage::Info&) 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(SkImage*, SkCanvas*) SK_OVERRIDE; 26 virtual void onCopyOnWrite() 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 ///////////////////////////////////////////////////////////////////////////////
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 } 79 }
80 80
81 void SkSurface_Gpu::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, 81 void SkSurface_Gpu::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y,
82 const SkPaint* paint) { 82 const SkPaint* paint) {
83 canvas->drawBitmap(fDevice->accessBitmap(false), x, y, paint); 83 canvas->drawBitmap(fDevice->accessBitmap(false), x, y, paint);
84 } 84 }
85 85
86 // Create a new SkGpuDevice and, if necessary, copy the contents of the old 86 // Create a new SkGpuDevice and, if necessary, copy the contents of the old
87 // device into it. Note that this flushes the SkGpuDevice but 87 // device into it. Note that this flushes the SkGpuDevice but
88 // doesn't force an OpenGL flush. 88 // doesn't force an OpenGL flush.
89 void SkSurface_Gpu::onCopyOnWrite(SkImage* image, SkCanvas* canvas) { 89 void SkSurface_Gpu::onCopyOnWrite() {
90 GrRenderTarget* rt = (GrRenderTarget*) fDevice->accessRenderTarget(); 90 GrRenderTarget* rt = (GrRenderTarget*) fDevice->accessRenderTarget();
91 91
92 // are we sharing our render target with the image? 92 // are we sharing our render target with the image?
93 if (rt->asTexture() == SkTextureImageGetTexture(image)) { 93 SkASSERT(NULL != this->getCachedImage());
94 if (rt->asTexture() == SkTextureImageGetTexture(this->getCachedImage())) {
94 SkGpuDevice* newDevice = static_cast<SkGpuDevice*>( 95 SkGpuDevice* newDevice = static_cast<SkGpuDevice*>(
95 fDevice->createCompatibleDevice(fDevice->config(), fDevice->width(), 96 fDevice->createCompatibleDevice(fDevice->config(), fDevice->width(),
96 fDevice->height(), fDevice->isOpaque())); 97 fDevice->height(), fDevice->isOpaque()));
97 SkAutoTUnref<SkGpuDevice> aurd(newDevice); 98 SkAutoTUnref<SkGpuDevice> aurd(newDevice);
98 fDevice->context()->copyTexture(rt->asTexture(), 99 fDevice->context()->copyTexture(rt->asTexture(),
99 (GrRenderTarget*)newDevice->accessRenderTarget()); 100 (GrRenderTarget*)newDevice->accessRenderTarget());
100 SkASSERT(NULL != canvas); 101 SkASSERT(NULL != this->getCachedCanvas());
101 SkASSERT(canvas->getDevice() == fDevice); 102 SkASSERT(this->getCachedCanvas()->getDevice() == fDevice);
102 canvas->setDevice(newDevice); 103 this->getCachedCanvas()->setDevice(newDevice);
103 SkRefCnt_SafeAssign(fDevice, newDevice); 104 SkRefCnt_SafeAssign(fDevice, newDevice);
104 } 105 }
105 } 106 }
106 107
107 /////////////////////////////////////////////////////////////////////////////// 108 ///////////////////////////////////////////////////////////////////////////////
108 109
109 SkSurface* SkSurface::NewRenderTargetDirect(GrContext* ctx, 110 SkSurface* SkSurface::NewRenderTargetDirect(GrContext* ctx,
110 GrRenderTarget* target) { 111 GrRenderTarget* target) {
111 if (NULL == ctx || NULL == target) { 112 if (NULL == ctx || NULL == target) {
112 return NULL; 113 return NULL;
(...skipping 17 matching lines...) Expand all
130 desc.fConfig = SkBitmapConfig2GrPixelConfig(config); 131 desc.fConfig = SkBitmapConfig2GrPixelConfig(config);
131 desc.fSampleCnt = sampleCount; 132 desc.fSampleCnt = sampleCount;
132 133
133 SkAutoTUnref<GrTexture> tex(ctx->createUncachedTexture(desc, NULL, 0)); 134 SkAutoTUnref<GrTexture> tex(ctx->createUncachedTexture(desc, NULL, 0));
134 if (NULL == tex) { 135 if (NULL == tex) {
135 return NULL; 136 return NULL;
136 } 137 }
137 138
138 return SkNEW_ARGS(SkSurface_Gpu, (ctx, tex->asRenderTarget())); 139 return SkNEW_ARGS(SkSurface_Gpu, (ctx, tex->asRenderTarget()));
139 } 140 }
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