OLD | NEW |
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 "SkCanvas.h" | 10 #include "SkCanvas.h" |
11 #include "SkGpuDevice.h" | 11 #include "SkGpuDevice.h" |
12 #include "SkImage_Base.h" | 12 #include "SkImage_Base.h" |
| 13 #include "SkImage_Gpu.h" |
13 #include "SkImagePriv.h" | 14 #include "SkImagePriv.h" |
14 #include "SkSurface_Base.h" | 15 #include "SkSurface_Base.h" |
15 | 16 |
16 #if SK_SUPPORT_GPU | 17 #if SK_SUPPORT_GPU |
17 | 18 |
18 /////////////////////////////////////////////////////////////////////////////// | 19 /////////////////////////////////////////////////////////////////////////////// |
19 | 20 |
20 SkSurface_Gpu::SkSurface_Gpu(SkGpuDevice* device) | 21 SkSurface_Gpu::SkSurface_Gpu(SkGpuDevice* device) |
21 : INHERITED(device->width(), device->height(), &device->surfaceProps()) | 22 : INHERITED(device->width(), device->height(), &device->surfaceProps()) |
22 , fDevice(SkRef(device)) { | 23 , fDevice(SkRef(device)) { |
(...skipping 14 matching lines...) Expand all Loading... |
37 SkSurface* SkSurface_Gpu::onNewSurface(const SkImageInfo& info) { | 38 SkSurface* SkSurface_Gpu::onNewSurface(const SkImageInfo& info) { |
38 GrRenderTarget* rt = fDevice->accessRenderTarget(); | 39 GrRenderTarget* rt = fDevice->accessRenderTarget(); |
39 int sampleCount = rt->numSamples(); | 40 int sampleCount = rt->numSamples(); |
40 // TODO: Make caller specify this (change virtual signature of onNewSurface)
. | 41 // TODO: Make caller specify this (change virtual signature of onNewSurface)
. |
41 static const Budgeted kBudgeted = kNo_Budgeted; | 42 static const Budgeted kBudgeted = kNo_Budgeted; |
42 return SkSurface::NewRenderTarget(fDevice->context(), kBudgeted, info, sampl
eCount, | 43 return SkSurface::NewRenderTarget(fDevice->context(), kBudgeted, info, sampl
eCount, |
43 &this->props()); | 44 &this->props()); |
44 } | 45 } |
45 | 46 |
46 SkImage* SkSurface_Gpu::onNewImageSnapshot(Budgeted budgeted) { | 47 SkImage* SkSurface_Gpu::onNewImageSnapshot(Budgeted budgeted) { |
| 48 const SkImageInfo info = fDevice->imageInfo(); |
47 const int sampleCount = fDevice->accessRenderTarget()->numSamples(); | 49 const int sampleCount = fDevice->accessRenderTarget()->numSamples(); |
48 SkImage* image = SkNewImageFromBitmapTexture(fDevice->accessBitmap(false), s
ampleCount, | 50 SkImage* image = NULL; |
49 budgeted); | 51 GrTexture* tex = fDevice->accessRenderTarget()->asTexture(); |
| 52 if (tex) { |
| 53 image = SkNEW_ARGS(SkImage_Gpu, |
| 54 (info.width(), info.height(), info.alphaType(), |
| 55 tex, sampleCount, budgeted)); |
| 56 } |
50 if (image) { | 57 if (image) { |
51 as_IB(image)->initWithProps(this->props()); | 58 as_IB(image)->initWithProps(this->props()); |
52 } | 59 } |
53 return image; | 60 return image; |
54 } | 61 } |
55 | 62 |
56 void SkSurface_Gpu::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, | 63 void SkSurface_Gpu::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, |
57 const SkPaint* paint) { | 64 const SkPaint* paint) { |
58 canvas->drawBitmap(fDevice->accessBitmap(false), x, y, paint); | 65 canvas->drawBitmap(fDevice->accessBitmap(false), x, y, paint); |
59 } | 66 } |
60 | 67 |
61 // Create a new render target and, if necessary, copy the contents of the old | 68 // Create a new render target and, if necessary, copy the contents of the old |
62 // render target into it. Note that this flushes the SkGpuDevice but | 69 // render target into it. Note that this flushes the SkGpuDevice but |
63 // doesn't force an OpenGL flush. | 70 // doesn't force an OpenGL flush. |
64 void SkSurface_Gpu::onCopyOnWrite(ContentChangeMode mode) { | 71 void SkSurface_Gpu::onCopyOnWrite(ContentChangeMode mode) { |
65 GrRenderTarget* rt = fDevice->accessRenderTarget(); | 72 GrRenderTarget* rt = fDevice->accessRenderTarget(); |
66 // are we sharing our render target with the image? Note this call should ne
ver create a new | 73 // are we sharing our render target with the image? Note this call should ne
ver create a new |
67 // image because onCopyOnWrite is only called when there is a cached image. | 74 // image because onCopyOnWrite is only called when there is a cached image. |
68 SkImage* image = this->getCachedImage(kNo_Budgeted); | 75 SkImage* image = this->getCachedImage(kNo_Budgeted); |
69 SkASSERT(image); | 76 SkASSERT(image); |
70 if (rt->asTexture() == SkTextureImageGetTexture(image)) { | 77 if (rt->asTexture() == image->getTexture()) { |
71 this->fDevice->replaceRenderTarget(SkSurface::kRetain_ContentChangeMode
== mode); | 78 this->fDevice->replaceRenderTarget(SkSurface::kRetain_ContentChangeMode
== mode); |
72 SkTextureImageApplyBudgetedDecision(image); | 79 SkTextureImageApplyBudgetedDecision(image); |
73 } else if (kDiscard_ContentChangeMode == mode) { | 80 } else if (kDiscard_ContentChangeMode == mode) { |
74 this->SkSurface_Gpu::onDiscard(); | 81 this->SkSurface_Gpu::onDiscard(); |
75 } | 82 } |
76 } | 83 } |
77 | 84 |
78 void SkSurface_Gpu::onDiscard() { | 85 void SkSurface_Gpu::onDiscard() { |
79 fDevice->accessRenderTarget()->discard(); | 86 fDevice->accessRenderTarget()->discard(); |
80 } | 87 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 } | 120 } |
114 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(surface->asRenderTarget
(), props, | 121 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(surface->asRenderTarget
(), props, |
115 SkGpuDevice::kNeedClear
_Flag)); | 122 SkGpuDevice::kNeedClear
_Flag)); |
116 if (!device) { | 123 if (!device) { |
117 return NULL; | 124 return NULL; |
118 } | 125 } |
119 return SkNEW_ARGS(SkSurface_Gpu, (device)); | 126 return SkNEW_ARGS(SkSurface_Gpu, (device)); |
120 } | 127 } |
121 | 128 |
122 #endif | 129 #endif |
OLD | NEW |