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

Side by Side Diff: src/core/SkBlitter.cpp

Issue 1720933002: Add ContextRec param to SkShader::contextSize() (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Created 4 years, 10 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
OLDNEW
1 /* 1 /*
2 * Copyright 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
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 "SkBlitter.h" 8 #include "SkBlitter.h"
9 #include "SkAntiRun.h" 9 #include "SkAntiRun.h"
10 #include "SkColor.h" 10 #include "SkColor.h"
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 class Sk3DShader : public SkShader { 585 class Sk3DShader : public SkShader {
586 public: 586 public:
587 Sk3DShader(SkShader* proxy) : fProxy(proxy) { 587 Sk3DShader(SkShader* proxy) : fProxy(proxy) {
588 SkSafeRef(proxy); 588 SkSafeRef(proxy);
589 } 589 }
590 590
591 virtual ~Sk3DShader() { 591 virtual ~Sk3DShader() {
592 SkSafeUnref(fProxy); 592 SkSafeUnref(fProxy);
593 } 593 }
594 594
595 size_t contextSize() const override { 595 size_t contextSize(const ContextRec& rec) const override {
596 size_t size = sizeof(Sk3DShaderContext); 596 size_t size = sizeof(Sk3DShaderContext);
597 if (fProxy) { 597 if (fProxy) {
598 size += fProxy->contextSize(); 598 size += fProxy->contextSize(rec);
599 } 599 }
600 return size; 600 return size;
601 } 601 }
602 602
603 Context* onCreateContext(const ContextRec& rec, void* storage) const overrid e { 603 Context* onCreateContext(const ContextRec& rec, void* storage) const overrid e {
604 SkShader::Context* proxyContext = nullptr; 604 SkShader::Context* proxyContext = nullptr;
605 if (fProxy) { 605 if (fProxy) {
606 char* proxyContextStorage = (char*) storage + sizeof(Sk3DShaderConte xt); 606 char* proxyContextStorage = (char*) storage + sizeof(Sk3DShaderConte xt);
607 proxyContext = fProxy->createContext(rec, proxyContextStorage); 607 proxyContext = fProxy->createContext(rec, proxyContextStorage);
608 if (!proxyContext) { 608 if (!proxyContext) {
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
868 paint.writable()->setShader(shader)->unref(); 868 paint.writable()->setShader(shader)->unref();
869 // blitters should ignore the presence/absence of a filter, since 869 // blitters should ignore the presence/absence of a filter, since
870 // if there is one, the shader will take care of it. 870 // if there is one, the shader will take care of it.
871 } 871 }
872 872
873 /* 873 /*
874 * We create a SkShader::Context object, and store it on the blitter. 874 * We create a SkShader::Context object, and store it on the blitter.
875 */ 875 */
876 SkShader::Context* shaderContext = nullptr; 876 SkShader::Context* shaderContext = nullptr;
877 if (shader) { 877 if (shader) {
878 SkShader::ContextRec rec(*paint, matrix, nullptr); 878 SkShader::ContextRec rec(*paint, matrix, nullptr,
879 size_t contextSize = shader->contextSize(); 879 device.colorType(),
880 device.info().profileType());
881 size_t contextSize = shader->contextSize(rec);
880 if (contextSize) { 882 if (contextSize) {
881 // Try to create the ShaderContext 883 // Try to create the ShaderContext
882 void* storage = allocator->reserveT<SkShader::Context>(contextSize); 884 void* storage = allocator->reserveT<SkShader::Context>(contextSize);
883 shaderContext = shader->createContext(rec, storage); 885 shaderContext = shader->createContext(rec, storage);
884 if (!shaderContext) { 886 if (!shaderContext) {
885 allocator->freeLast(); 887 allocator->freeLast();
886 return allocator->createT<SkNullBlitter>(); 888 return allocator->createT<SkNullBlitter>();
887 } 889 }
888 SkASSERT(shaderContext); 890 SkASSERT(shaderContext);
889 SkASSERT((void*) shaderContext == storage); 891 SkASSERT((void*) shaderContext == storage);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
952 } 954 }
953 return blitter; 955 return blitter;
954 } 956 }
955 957
956 /////////////////////////////////////////////////////////////////////////////// 958 ///////////////////////////////////////////////////////////////////////////////
957 959
958 class SkZeroShaderContext : public SkShader::Context { 960 class SkZeroShaderContext : public SkShader::Context {
959 public: 961 public:
960 SkZeroShaderContext(const SkShader& shader, const SkShader::ContextRec& rec) 962 SkZeroShaderContext(const SkShader& shader, const SkShader::ContextRec& rec)
961 // Override rec with the identity matrix, so it is guaranteed to be inve rtible. 963 // Override rec with the identity matrix, so it is guaranteed to be inve rtible.
962 : INHERITED(shader, SkShader::ContextRec(*rec.fPaint, SkMatrix::I(), nul lptr)) {} 964 : INHERITED(shader, SkShader::ContextRec(*rec.fPaint, SkMatrix::I(), nul lptr,
965 rec.fDeviceColorType, rec.fDevi ceColorProfile)) {}
963 966
964 void shadeSpan(int x, int y, SkPMColor colors[], int count) override { 967 void shadeSpan(int x, int y, SkPMColor colors[], int count) override {
965 sk_bzero(colors, count * sizeof(SkPMColor)); 968 sk_bzero(colors, count * sizeof(SkPMColor));
966 } 969 }
967 970
968 private: 971 private:
969 typedef SkShader::Context INHERITED; 972 typedef SkShader::Context INHERITED;
970 }; 973 };
971 974
972 SkShaderBlitter::SkShaderBlitter(const SkPixmap& device, const SkPaint& paint, 975 SkShaderBlitter::SkShaderBlitter(const SkPixmap& device, const SkPaint& paint,
(...skipping 22 matching lines...) Expand all
995 fShaderContext->~Context(); 998 fShaderContext->~Context();
996 SkShader::Context* ctx = fShader->createContext(rec, (void*)fShaderContext); 999 SkShader::Context* ctx = fShader->createContext(rec, (void*)fShaderContext);
997 if (nullptr == ctx) { 1000 if (nullptr == ctx) {
998 // Need a valid context in fShaderContext's storage, so we can later (or our caller) call 1001 // Need a valid context in fShaderContext's storage, so we can later (or our caller) call
999 // the in-place destructor. 1002 // the in-place destructor.
1000 new (fShaderContext) SkZeroShaderContext(*fShader, rec); 1003 new (fShaderContext) SkZeroShaderContext(*fShader, rec);
1001 return false; 1004 return false;
1002 } 1005 }
1003 return true; 1006 return true;
1004 } 1007 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698