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

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

Issue 872543002: Take budgeted param when snapping new image. (Closed) Base URL: https://skia.googlesource.com/skia.git@budgeted
Patch Set: Address comment and rebase Created 5 years, 11 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
« no previous file with comments | « src/image/SkSurface_Gpu.h ('k') | src/image/SkSurface_Raster.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_Gpu.h" 8 #include "SkSurface_Gpu.h"
9 9
10 #include "GrGpuResourceCacheAccess.h" 10 #include "GrGpuResourceCacheAccess.h"
(...skipping 26 matching lines...) Expand all
37 37
38 SkSurface* SkSurface_Gpu::onNewSurface(const SkImageInfo& info) { 38 SkSurface* SkSurface_Gpu::onNewSurface(const SkImageInfo& info) {
39 GrRenderTarget* rt = fDevice->accessRenderTarget(); 39 GrRenderTarget* rt = fDevice->accessRenderTarget();
40 int sampleCount = rt->numSamples(); 40 int sampleCount = rt->numSamples();
41 // TODO: Make caller specify this (change virtual signature of onNewSurface) . 41 // TODO: Make caller specify this (change virtual signature of onNewSurface) .
42 static const Budgeted kBudgeted = kNo_Budgeted; 42 static const Budgeted kBudgeted = kNo_Budgeted;
43 return SkSurface::NewRenderTarget(fDevice->context(), kBudgeted, info, sampl eCount, 43 return SkSurface::NewRenderTarget(fDevice->context(), kBudgeted, info, sampl eCount,
44 &this->props()); 44 &this->props());
45 } 45 }
46 46
47 SkImage* SkSurface_Gpu::onNewImageSnapshot() { 47 SkImage* SkSurface_Gpu::onNewImageSnapshot(Budgeted budgeted) {
48 const int sampleCount = fDevice->accessRenderTarget()->numSamples(); 48 const int sampleCount = fDevice->accessRenderTarget()->numSamples();
49 SkImage* image = SkNewImageFromBitmapTexture(fDevice->accessBitmap(false), s ampleCount); 49 SkImage* image = SkNewImageFromBitmapTexture(fDevice->accessBitmap(false), s ampleCount,
50 budgeted);
50 if (image) { 51 if (image) {
51 as_IB(image)->initWithProps(this->props()); 52 as_IB(image)->initWithProps(this->props());
52 } 53 }
53 return image; 54 return image;
54 } 55 }
55 56
56 void SkSurface_Gpu::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, 57 void SkSurface_Gpu::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y,
57 const SkPaint* paint) { 58 const SkPaint* paint) {
58 canvas->drawBitmap(fDevice->accessBitmap(false), x, y, paint); 59 canvas->drawBitmap(fDevice->accessBitmap(false), x, y, paint);
59 } 60 }
60 61
61 // Create a new SkGpuDevice and, if necessary, copy the contents of the old 62 // Create a new SkGpuDevice and, if necessary, copy the contents of the old
62 // device into it. Note that this flushes the SkGpuDevice but 63 // device into it. Note that this flushes the SkGpuDevice but
63 // doesn't force an OpenGL flush. 64 // doesn't force an OpenGL flush.
64 void SkSurface_Gpu::onCopyOnWrite(ContentChangeMode mode) { 65 void SkSurface_Gpu::onCopyOnWrite(ContentChangeMode mode) {
65 GrRenderTarget* rt = fDevice->accessRenderTarget(); 66 GrRenderTarget* rt = fDevice->accessRenderTarget();
66 // are we sharing our render target with the image? 67 // are we sharing our render target with the image? Note this call should ne ver create a new
67 SkASSERT(this->getCachedImage()); 68 // image because onCopyOnWrite is only called when there is a cached image.
68 if (rt->asTexture() == SkTextureImageGetTexture(this->getCachedImage())) { 69 SkImage* image = this->getCachedImage(kNo_Budgeted);
70 SkASSERT(image);
71 if (rt->asTexture() == SkTextureImageGetTexture(image)) {
69 GrRenderTarget* oldRT = this->fDevice->accessRenderTarget(); 72 GrRenderTarget* oldRT = this->fDevice->accessRenderTarget();
70 SkSurface::Budgeted budgeted = oldRT->cacheAccess().isBudgeted() ? kYes_ Budgeted : 73 SkSurface::Budgeted budgeted = oldRT->cacheAccess().isBudgeted() ? kYes_ Budgeted :
71 kNo_B udgeted; 74 kNo_B udgeted;
72 SkAutoTUnref<SkGpuDevice> newDevice( 75 SkAutoTUnref<SkGpuDevice> newDevice(
73 SkGpuDevice::Create(oldRT->getContext(), budgeted, fDevice->imageInf o(), 76 SkGpuDevice::Create(oldRT->getContext(), budgeted, fDevice->imageInf o(),
74 oldRT->numSamples(), &this->props(), 0)); 77 oldRT->numSamples(), &this->props(), 0));
75 if (kRetain_ContentChangeMode == mode && !oldRT->wasDestroyed() && newDe vice) { 78 if (kRetain_ContentChangeMode == mode && !oldRT->wasDestroyed() && newDe vice) {
76 oldRT->getContext()->copySurface(newDevice->accessRenderTarget(), ol dRT); 79 oldRT->getContext()->copySurface(newDevice->accessRenderTarget(), ol dRT);
77 } 80 }
78 81
79 SkASSERT(this->getCachedCanvas()); 82 SkASSERT(this->getCachedCanvas());
80 SkASSERT(this->getCachedCanvas()->getDevice() == fDevice); 83 SkASSERT(this->getCachedCanvas()->getDevice() == fDevice);
81 84
82 this->getCachedCanvas()->setRootDevice(newDevice); 85 this->getCachedCanvas()->setRootDevice(newDevice);
83 SkRefCnt_SafeAssign(fDevice, newDevice.get()); 86 SkRefCnt_SafeAssign(fDevice, newDevice.get());
84 87
85 // For now we always treat the image snapshots as budgeted. We could mak e newImageSnapshot 88 SkTextureImageApplyBudgetedDecision(image);
86 // take a Budgeted param.
87 oldRT->cacheAccess().makeBudgeted();
88
89 } else if (kDiscard_ContentChangeMode == mode) { 89 } else if (kDiscard_ContentChangeMode == mode) {
90 this->SkSurface_Gpu::onDiscard(); 90 this->SkSurface_Gpu::onDiscard();
91 } 91 }
92 } 92 }
93 93
94 void SkSurface_Gpu::onDiscard() { 94 void SkSurface_Gpu::onDiscard() {
95 fDevice->accessRenderTarget()->discard(); 95 fDevice->accessRenderTarget()->discard();
96 } 96 }
97 97
98 /////////////////////////////////////////////////////////////////////////////// 98 ///////////////////////////////////////////////////////////////////////////////
(...skipping 10 matching lines...) Expand all
109 int sampleCount, const SkSurfaceProps* pro ps) { 109 int sampleCount, const SkSurfaceProps* pro ps) {
110 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(ctx, budgeted, info, sa mpleCount, props, 110 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(ctx, budgeted, info, sa mpleCount, props,
111 SkGpuDevice::kNeedClear _Flag)); 111 SkGpuDevice::kNeedClear _Flag));
112 if (!device) { 112 if (!device) {
113 return NULL; 113 return NULL;
114 } 114 }
115 return SkNEW_ARGS(SkSurface_Gpu, (device)); 115 return SkNEW_ARGS(SkSurface_Gpu, (device));
116 } 116 }
117 117
118 #endif 118 #endif
OLDNEW
« no previous file with comments | « src/image/SkSurface_Gpu.h ('k') | src/image/SkSurface_Raster.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698