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

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

Issue 12567025: Integrating SkSurface with SkDeferredCanvas (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
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* onNewImageShapshot() SK_OVERRIDE; 23 virtual SkImage* onNewImageShapshot() 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(SkImage*, SkCanvas*, bool overwrite) 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 GrRenderTarget* rt = (GrRenderTarget*) fDevice->accessRenderTarget(); 76 GrRenderTarget* rt = (GrRenderTarget*) fDevice->accessRenderTarget();
77 77
78 return SkImage::NewTexture(rt->asTexture()); 78 return SkImage::NewTexture(rt->asTexture());
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 // Copy the contents of the SkGpuDevice into a new texture and give that 86 // Create a new SkGpuDevice and, if necessary, copy the contents of the old
87 // texture to the SkImage. 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*) { 89 void SkSurface_Gpu::onCopyOnWrite(SkImage* image, SkCanvas* canvas, bool overwri te) {
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 if (rt->asTexture() == SkTextureImageGetTexture(image)) {
94 GrTextureDesc desc; 94 SkGpuDevice* newDevice = static_cast<SkGpuDevice*>(
Stephen White 2013/03/26 20:51:44 Kind of a style thing, but you could use SkAutoTUn
95 // copyTexture requires a render target as the destination 95 fDevice->createCompatibleDevice(fDevice->config(), fDevice->width(),
96 desc.fFlags = kRenderTarget_GrTextureFlagBit; 96 fDevice->height(), fDevice->isOpaque()));
97 desc.fWidth = fDevice->width(); 97 if (!overwrite) {
98 desc.fHeight = fDevice->height(); 98 fDevice->context()->copyTexture(rt->asTexture(),
99 desc.fConfig = SkBitmapConfig2GrPixelConfig(fDevice->config()); 99 (GrRenderTarget*)newDevice->accessRenderTarget());
100 desc.fSampleCnt = 0;
101
102 SkAutoTUnref<GrTexture> tex(fDevice->context()->createUncachedTexture(de sc, NULL, 0));
103 if (NULL == tex) {
104 SkTextureImageSetTexture(image, NULL);
105 return;
106 } 100 }
107 101 SkASSERT(NULL != canvas);
108 fDevice->context()->copyTexture(rt->asTexture(), tex->asRenderTarget()); 102 SkASSERT(canvas->getDevice() == fDevice);
109 103 canvas->setDevice(newDevice);
110 SkTextureImageSetTexture(image, tex); 104 SkSafeUnref(fDevice);
105 fDevice = newDevice;
Stephen White 2013/03/26 20:51:44 ... and SkRefCnt_SafeAssign() here.
111 } 106 }
112 } 107 }
113 108
114 /////////////////////////////////////////////////////////////////////////////// 109 ///////////////////////////////////////////////////////////////////////////////
115 110
116 SkSurface* SkSurface::NewRenderTargetDirect(GrContext* ctx, 111 SkSurface* SkSurface::NewRenderTargetDirect(GrContext* ctx,
117 GrRenderTarget* target) { 112 GrRenderTarget* target) {
118 if (NULL == ctx || NULL == target) { 113 if (NULL == ctx || NULL == target) {
119 return NULL; 114 return NULL;
120 } 115 }
(...skipping 16 matching lines...) Expand all
137 desc.fConfig = SkBitmapConfig2GrPixelConfig(config); 132 desc.fConfig = SkBitmapConfig2GrPixelConfig(config);
138 desc.fSampleCnt = sampleCount; 133 desc.fSampleCnt = sampleCount;
139 134
140 SkAutoTUnref<GrTexture> tex(ctx->createUncachedTexture(desc, NULL, 0)); 135 SkAutoTUnref<GrTexture> tex(ctx->createUncachedTexture(desc, NULL, 0));
141 if (NULL == tex) { 136 if (NULL == tex) {
142 return NULL; 137 return NULL;
143 } 138 }
144 139
145 return SkNEW_ARGS(SkSurface_Gpu, (ctx, tex->asRenderTarget())); 140 return SkNEW_ARGS(SkSurface_Gpu, (ctx, tex->asRenderTarget()));
146 } 141 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698