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

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

Issue 13195002: Unit test improvements to fully validate the SkImage contract (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/SkImage_Picture.cpp ('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"
(...skipping 65 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) {
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*>(
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 SkAutoTUnref<SkGpuDevice> aurd(newDevice);
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; 100 SkASSERT(NULL != canvas);
101 101 SkASSERT(canvas->getDevice() == fDevice);
102 SkAutoTUnref<GrTexture> tex(fDevice->context()->createUncachedTexture(de sc, NULL, 0)); 102 canvas->setDevice(newDevice);
103 if (NULL == tex) { 103 SkRefCnt_SafeAssign(fDevice, newDevice);
104 SkTextureImageSetTexture(image, NULL);
105 return;
106 }
107
108 fDevice->context()->copyTexture(rt->asTexture(), tex->asRenderTarget());
109
110 SkTextureImageSetTexture(image, tex);
111 } 104 }
112 } 105 }
113 106
114 /////////////////////////////////////////////////////////////////////////////// 107 ///////////////////////////////////////////////////////////////////////////////
115 108
116 SkSurface* SkSurface::NewRenderTargetDirect(GrContext* ctx, 109 SkSurface* SkSurface::NewRenderTargetDirect(GrContext* ctx,
117 GrRenderTarget* target) { 110 GrRenderTarget* target) {
118 if (NULL == ctx || NULL == target) { 111 if (NULL == ctx || NULL == target) {
119 return NULL; 112 return NULL;
120 } 113 }
(...skipping 16 matching lines...) Expand all
137 desc.fConfig = SkBitmapConfig2GrPixelConfig(config); 130 desc.fConfig = SkBitmapConfig2GrPixelConfig(config);
138 desc.fSampleCnt = sampleCount; 131 desc.fSampleCnt = sampleCount;
139 132
140 SkAutoTUnref<GrTexture> tex(ctx->createUncachedTexture(desc, NULL, 0)); 133 SkAutoTUnref<GrTexture> tex(ctx->createUncachedTexture(desc, NULL, 0));
141 if (NULL == tex) { 134 if (NULL == tex) {
142 return NULL; 135 return NULL;
143 } 136 }
144 137
145 return SkNEW_ARGS(SkSurface_Gpu, (ctx, tex->asRenderTarget())); 138 return SkNEW_ARGS(SkSurface_Gpu, (ctx, tex->asRenderTarget()));
146 } 139 }
OLDNEW
« no previous file with comments | « src/image/SkImage_Picture.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698