| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SampleApp.h" | 8 #include "SampleApp.h" |
| 9 | 9 |
| 10 #include "OverView.h" | 10 #include "OverView.h" |
| 11 #include "Resources.h" | 11 #include "Resources.h" |
| 12 #include "SampleCode.h" | 12 #include "SampleCode.h" |
| 13 #include "SkAnimTimer.h" | 13 #include "SkAnimTimer.h" |
| 14 #include "SkCanvas.h" | 14 #include "SkCanvas.h" |
| 15 #include "SkCommandLineFlags.h" | 15 #include "SkCommandLineFlags.h" |
| 16 #include "SkData.h" | 16 #include "SkData.h" |
| 17 #include "SkDocument.h" | 17 #include "SkDocument.h" |
| 18 #include "SkGammaColorFilter.h" |
| 18 #include "SkGraphics.h" | 19 #include "SkGraphics.h" |
| 19 #include "SkImage_Base.h" | 20 #include "SkImage_Base.h" |
| 20 #include "SkImageEncoder.h" | 21 #include "SkImageEncoder.h" |
| 21 #include "SkOSFile.h" | 22 #include "SkOSFile.h" |
| 22 #include "SkPaint.h" | 23 #include "SkPaint.h" |
| 23 #include "SkPaintFilterCanvas.h" | 24 #include "SkPaintFilterCanvas.h" |
| 24 #include "SkPicture.h" | 25 #include "SkPicture.h" |
| 25 #include "SkPictureRecorder.h" | 26 #include "SkPictureRecorder.h" |
| 26 #include "SkPM4fPriv.h" | 27 #include "SkPM4fPriv.h" |
| 27 #include "SkStream.h" | 28 #include "SkStream.h" |
| 28 #include "SkSurface.h" | 29 #include "SkSurface.h" |
| 29 #include "SkTemplates.h" | 30 #include "SkTemplates.h" |
| 30 #include "SkTSort.h" | 31 #include "SkTSort.h" |
| 31 #include "SkTime.h" | 32 #include "SkTime.h" |
| 32 #include "SkTypeface.h" | 33 #include "SkTypeface.h" |
| 33 #include "SkWindow.h" | 34 #include "SkWindow.h" |
| 34 #include "sk_tool_utils.h" | 35 #include "sk_tool_utils.h" |
| 35 | 36 |
| 36 #if SK_SUPPORT_GPU | 37 #if SK_SUPPORT_GPU |
| 37 # include "gl/GrGLInterface.h" | 38 # include "gl/GrGLInterface.h" |
| 38 # include "gl/GrGLUtil.h" | 39 # include "gl/GrGLUtil.h" |
| 39 # include "GrDrawContext.h" | |
| 40 # include "GrRenderTarget.h" | |
| 41 # include "GrContext.h" | 40 # include "GrContext.h" |
| 42 # include "SkGr.h" | 41 # include "SkGr.h" |
| 43 # if SK_ANGLE | 42 # if SK_ANGLE |
| 44 # include "gl/angle/GLTestContext_angle.h" | 43 # include "gl/angle/GLTestContext_angle.h" |
| 45 # endif | 44 # endif |
| 46 #else | 45 #else |
| 47 class GrContext; | 46 class GrContext; |
| 48 #endif | 47 #endif |
| 49 | 48 |
| 50 const struct { | 49 const struct { |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 fMSAASampleCount, &props); | 306 fMSAASampleCount, &props); |
| 308 } else { | 307 } else { |
| 309 return fGpuSurface; | 308 return fGpuSurface; |
| 310 } | 309 } |
| 311 } | 310 } |
| 312 #endif | 311 #endif |
| 313 return nullptr; | 312 return nullptr; |
| 314 } | 313 } |
| 315 | 314 |
| 316 void publishCanvas(SampleWindow::DeviceType dType, | 315 void publishCanvas(SampleWindow::DeviceType dType, |
| 317 SkCanvas* canvas, SampleWindow* win) override { | 316 SkCanvas* renderingCanvas, SampleWindow* win) override { |
| 318 #if SK_SUPPORT_GPU | 317 #if SK_SUPPORT_GPU |
| 319 if (fCurContext) { | |
| 320 // in case we have queued drawing calls | |
| 321 fCurContext->flush(); | |
| 322 } | |
| 323 | |
| 324 if (!IsGpuDeviceType(dType) || | 318 if (!IsGpuDeviceType(dType) || |
| 325 kRGBA_F16_SkColorType == win->info().colorType() || | 319 kRGBA_F16_SkColorType == win->info().colorType() || |
| 326 fActualColorBits > 24) { | 320 fActualColorBits > 24) { |
| 327 // We made/have an off-screen surface. Get the contents as an SkImag
e: | 321 // We made/have an off-screen surface. Get the contents as an SkImag
e: |
| 328 SkBitmap bm; | 322 SkBitmap bm; |
| 329 bm.allocPixels(win->info()); | 323 bm.allocPixels(win->info()); |
| 330 canvas->readPixels(&bm, 0, 0); | 324 renderingCanvas->readPixels(&bm, 0, 0); |
| 331 SkPixmap pm; | 325 SkPixmap pm; |
| 332 bm.peekPixels(&pm); | 326 bm.peekPixels(&pm); |
| 333 sk_sp<SkImage> image(SkImage::MakeTextureFromPixmap(fCurContext, pm, | 327 sk_sp<SkImage> image(SkImage::MakeTextureFromPixmap(fCurContext, pm, |
| 334 SkBudgeted::kNo)
); | 328 SkBudgeted::kNo)
); |
| 335 | 329 |
| 336 SkCanvas* canvas = fGpuSurface->getCanvas(); | 330 SkCanvas* gpuCanvas = fGpuSurface->getCanvas(); |
| 337 | |
| 338 // Temporary code until applyGamma is replaced | |
| 339 GrDrawContext* dc = canvas->internal_private_accessTopLayerDrawConte
xt(); | |
| 340 GrRenderTarget* rt = dc->accessRenderTarget(); | |
| 341 GrTexture* texture = image->getTexture(); | |
| 342 SkASSERT(texture); | |
| 343 | 331 |
| 344 // With ten-bit output, we need to manually apply the gamma of the o
utput device | 332 // With ten-bit output, we need to manually apply the gamma of the o
utput device |
| 345 // (unless we're in non-gamma correct mode, in which case our data i
s already | 333 // (unless we're in non-gamma correct mode, in which case our data i
s already |
| 346 // fake-sRGB, like we're expected to put in the 10-bit buffer): | 334 // fake-sRGB, like we're expected to put in the 10-bit buffer): |
| 347 bool doGamma = (fActualColorBits == 30) && SkImageInfoIsGammaCorrect
(win->info()); | 335 bool doGamma = (fActualColorBits == 30) && SkImageInfoIsGammaCorrect
(win->info()); |
| 348 fCurContext->applyGamma(rt, texture, doGamma ? 1.0f / 2.2f : 1.0f); | 336 |
| 337 SkPaint gammaPaint; |
| 338 gammaPaint.setXfermodeMode(SkXfermode::kSrc_Mode); |
| 339 if (doGamma) { |
| 340 gammaPaint.setColorFilter(SkGammaColorFilter::Make(1.0f / 2.2f))
; |
| 341 } |
| 342 |
| 343 gpuCanvas->drawImage(image, 0, 0, &gammaPaint); |
| 349 } | 344 } |
| 345 |
| 346 fGpuSurface->prepareForExternalIO(); |
| 350 #endif | 347 #endif |
| 351 | 348 |
| 352 win->present(); | 349 win->present(); |
| 353 } | 350 } |
| 354 | 351 |
| 355 void windowSizeChanged(SampleWindow* win) override { | 352 void windowSizeChanged(SampleWindow* win) override { |
| 356 #if SK_SUPPORT_GPU | 353 #if SK_SUPPORT_GPU |
| 357 if (fCurContext) { | 354 if (fCurContext) { |
| 358 AttachmentInfo attachmentInfo; | 355 AttachmentInfo attachmentInfo; |
| 359 win->attach(fBackend, fMSAASampleCount, fDeepColor, &attachmentInfo)
; | 356 win->attach(fBackend, fMSAASampleCount, fDeepColor, &attachmentInfo)
; |
| (...skipping 1915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2275 #ifdef SK_BUILD_FOR_MAC | 2272 #ifdef SK_BUILD_FOR_MAC |
| 2276 setenv("ANDROID_ROOT", "/android/device/data", 0); | 2273 setenv("ANDROID_ROOT", "/android/device/data", 0); |
| 2277 #endif | 2274 #endif |
| 2278 SkGraphics::Init(); | 2275 SkGraphics::Init(); |
| 2279 SkEvent::Init(); | 2276 SkEvent::Init(); |
| 2280 } | 2277 } |
| 2281 | 2278 |
| 2282 void application_term() { | 2279 void application_term() { |
| 2283 SkEvent::Term(); | 2280 SkEvent::Term(); |
| 2284 } | 2281 } |
| OLD | NEW |